def forward(
        self,
        batch: torch.Tensor,
        batch_imagenet: torch.Tensor | None = None,
        normalize: bool = True,
    ) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor] | InferenceBatch:
        """Forward pass through the model.

        Args:
            batch (torch.Tensor): Input batch of images.
            batch_imagenet (torch.Tensor | None): Optional batch of ImageNet
                images for training. Defaults to ``None``.
            normalize (bool): Whether to normalize anomaly maps.
                Defaults to ``True``.

        Returns:
            tuple[torch.Tensor, torch.Tensor, torch.Tensor] | InferenceBatch:
                If training:
                    - Loss components (student-teacher, autoencoder,
                      student-autoencoder)
                If inference:
                    - Batch containing anomaly maps and scores
        """
        student_output, distance_st = self.compute_student_teacher_distance(batch)
        if self.training:
            return self.compute_losses(batch, batch_imagenet, distance_st)

        map_st, map_stae = self.compute_maps(batch, student_output, distance_st, normalize)
        anomaly_map = 0.5 * map_st + 0.5 * map_stae
        pred_score = torch.amax(anomaly_map, dim=(-2, -1))
        return InferenceBatch(pred_score=pred_score, anomaly_map=anomaly_map)
Forward pass through the model.

        Args:
            batch (torch.Tensor): Input batch of images.
            batch_imagenet (torch.Tensor | None): Optional batch of ImageNet
                images for training. Defaults to ``None``.
            normalize (bool): Whether to normalize anomaly maps.
                Defaults to ``True``.

        Returns:
            tuple[torch.Tensor, torch.Tensor, torch.Tensor] | InferenceBatch:
                If training:
                    - Loss components (student-teacher, autoencoder,
                      student-autoencoder)
                If inference:
                    - Batch containing anomaly maps and scores
        
src/anomalib/models/image/efficient_ad/torch_model.py