```python
Loads a checkpoint file, handling both safetensors and pickle checkpoint formats.

Args:
checkpoint_file (`str` or `os.PathLike`):
Path to the checkpoint file to load. Can be either a safetensors or pickle (`.bin`) checkpoint.
map_location (`str` or `torch.device`, *optional*):
A `torch.device` object, string or a dict specifying how to remap storage locations. It
indicates the location where all tensors should be loaded.
weights_only (`bool`, *optional*, defaults to `False`):
If True, only loads the model weights without optimizer states and other metadata.
Only supported for pickle (`.bin`) checkpoints with PyTorch >= 1.13. Has no effect when
loading safetensors files.
mmap (`bool`, *optional*, defaults to `False`):
Whether to use memory-mapped file loading. Memory mapping can improve loading performance
for large models in PyTorch >= 2.1.0 with zipfile-based checkpoints. Has no effect when
loading safetensors files, as the `safetensors` library uses memory mapping by default.

Returns:
`Union[Dict[str, "torch.Tensor"], Any]`: The loaded checkpoint.
- For safetensors files: always returns a dictionary mapping parameter names to tensors.
- For pickle files: returns any Python object that was pickled (commonly a state dict, but could be
an entire model, optimizer state, or any other Python object).

Raises:
[`FileNotFoundError`](https://docs.python.org/3/library/exceptions.html#FileNotFoundError)
If the checkpoint file does not exist.
[`ImportError`](https://docs.python.org/3/library/exceptions.html#ImportError)
If safetensors or torch is not installed when trying to load a .safetensors file or a PyTorch checkpoint respectively.
[`OSError`](https://docs.python.org/3/library/exceptions.html#OSError)
If the checkpoint file format is invalid or if git-lfs files are not properly downloaded.
[`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
If the checkpoint file path is empty or invalid.

Example:
```python
>>> from huggingface_hub import load_state_dict_from_file