def pre_process(
        self,
        feature_stack: torch.Tensor,
        max_length: torch.Tensor | None = None,
    ) -> tuple[torch.Tensor, torch.Tensor]:
        """Pre-process feature embeddings before KDE.

        Scales the features according to the specified scaling method.

        Args:
            feature_stack: Features extracted from the model, shape (N, D)
            max_length: Maximum feature length for scaling. If ``None``, computed
                from ``feature_stack``. Defaults to None.

        Returns:
            tuple: (scaled_features, max_length)

        Raises:
            RuntimeError: If unknown scaling method is specified
        """
        if max_length is None:
            max_length = torch.max(torch.linalg.norm(feature_stack, ord=2, dim=1))

        if self.feature_scaling_method == FeatureScalingMethod.NORM:
            feature_stack /= torch.linalg.norm(feature_stack, ord=2, dim=1)[:, None]
        elif self.feature_scaling_method == FeatureScalingMethod.SCALE:
            feature_stack /= max_length
        else:
            msg = "Unknown pre-processing mode. Available modes are: Normalized and Scale."
            raise RuntimeError(msg)
        return feature_stack, max_length
Pre-process feature embeddings before KDE.

        Scales the features according to the specified scaling method.

        Args:
            feature_stack: Features extracted from the model, shape (N, D)
            max_length: Maximum feature length for scaling. If ``None``, computed
                from ``feature_stack``. Defaults to None.

        Returns:
            tuple: (scaled_features, max_length)

        Raises:
            RuntimeError: If unknown scaling method is specified
        
src/anomalib/models/components/classification/kde_classifier.py