def validate_pred_score(
        pred_score: torch.Tensor | None,
        anomaly_map: torch.Tensor | None = None,
    ) -> torch.Tensor | None:
        """Validate the prediction scores for a batch.

        Validates that the input prediction scores have the correct format. If no scores
        are provided but an anomaly map is given, computes scores from the map.

        Args:
            pred_score (torch.Tensor | None): Input prediction scores. Should be a 1D
                tensor of float values.
            anomaly_map (torch.Tensor | None, optional): Input anomaly map used to compute
                scores if ``pred_score`` is None.

        Returns:
            torch.Tensor | None: Validated prediction scores as float32 tensor.

        Raises:
            ValueError: If prediction scores have invalid shape or cannot be converted to
                tensor.

        Examples:
            >>> import torch
            >>> from anomalib.data.validators import VideoBatchValidator
            >>> pred_scores = torch.tensor([0.1, 0.9, 0.3, 0.7])
            >>> validated_scores = VideoBatchValidator.validate_pred_score(pred_scores)
            >>> print(validated_scores)
            tensor([0.1000, 0.9000, 0.3000, 0.7000])
        """
        if pred_score is None:
            return torch.amax(anomaly_map, dim=(-3, -2, -1)) if anomaly_map is not None else None

        if not isinstance(pred_score, torch.Tensor):
            try:
                pred_score = torch.tensor(pred_score)
            except Exception as e:
                msg = "Failed to convert pred_score to a torch.Tensor."
                raise ValueError(msg) from e
        if pred_score.ndim != 1:
            msg = f"Predicted scores must be a 1D tensor, got shape {pred_score.shape}."
            raise ValueError(msg)

        return pred_score.to(torch.float32)
Validate the prediction scores for a batch.

        Validates that the input prediction scores have the correct format. If no scores
        are provided but an anomaly map is given, computes scores from the map.

        Args:
            pred_score (torch.Tensor | None): Input prediction scores. Should be a 1D
                tensor of float values.
            anomaly_map (torch.Tensor | None, optional): Input anomaly map used to compute
                scores if ``pred_score`` is None.

        Returns:
            torch.Tensor | None: Validated prediction scores as float32 tensor.

        Raises:
            ValueError: If prediction scores have invalid shape or cannot be converted to
                tensor.

        Examples:
            >>> import torch
            >>> from anomalib.data.validators import VideoBatchValidator
            >>> pred_scores = torch.tensor([0.1, 0.9, 0.3, 0.7])
            >>> validated_scores = VideoBatchValidator.validate_pred_score(pred_scores)
            >>> print(validated_scores)
            tensor([0.1000, 0.9000, 0.3000, 0.7000])
        
src/anomalib/data/validators/torch/video.py