def _load_checkpoint(self, path: str | Path) -> dict:
        """Load the model checkpoint.

        Args:
            path (str | Path): Path to the PyTorch checkpoint file.

        Returns:
            dict: Dictionary containing the model and metadata.

        Raises:
            ValueError: If the model file has an unknown extension.
            ValueError: If TRUST_REMOTE_CODE environment variable is not set.

        Example:
            >>> model = TorchInferencer(path="path/to/model.pt")
            >>> checkpoint = model._load_checkpoint("path/to/model.pt")
            >>> isinstance(checkpoint, dict)
            True
        """
        if isinstance(path, str):
            path = Path(path)

        if path.suffix not in {".pt", ".pth"}:
            msg = f"Unknown PyTorch checkpoint format {path.suffix}. Make sure you save the PyTorch model."
            raise ValueError(msg)

        trust_remote_code_enabled = os.environ.get("TRUST_REMOTE_CODE", "0").lower() in {"1", "true"}

        if not trust_remote_code_enabled:
            msg = (
                "Loading this model checkpoint requires executing arbitrary code via Python's pickle module, "
                "which is disabled by default for security reasons. This can be exploited by malicious model files. "
                "If you trust the source of this model and understand the risks, "
                "set the environment variable `TRUST_REMOTE_CODE=1` to allow loading."
            )
            raise ValueError(msg)

        logger.warning(
            "TRUST_REMOTE_CODE is set to True. Loading model using pickle module, "
            "which is inherently insecure and can lead to arbitrary code execution. "
            "Only set this to True if you TRUST the source of the checkpoint.",
        )
        # See mitigation details in https://github.com/open-edge-platform/anomalib/pull/2729
        # nosemgrep: trailofbits.python.pickles-in-pytorch.pickles-in-pytorch
        return torch.load(path, map_location=self.device, weights_only=False)  # nosec B614
Load the model checkpoint.

        Args:
            path (str | Path): Path to the PyTorch checkpoint file.

        Returns:
            dict: Dictionary containing the model and metadata.

        Raises:
            ValueError: If the model file has an unknown extension.
            ValueError: If TRUST_REMOTE_CODE environment variable is not set.

        Example:
            >>> model = TorchInferencer(path="path/to/model.pt")
            >>> checkpoint = model._load_checkpoint("path/to/model.pt")
            >>> isinstance(checkpoint, dict)
            True
        
src/anomalib/deploy/inferencers/torch_inferencer.py