```python
Load a checkpoint into a model, handling both sharded and non-sharded checkpoints.

Args:
model (`torch.nn.Module`):
The model in which to load the checkpoint.
checkpoint_path (`str` or `os.PathLike`):
Path to either the checkpoint file or directory containing the checkpoint(s).
strict (`bool`, *optional*, defaults to `False`):
Whether to strictly enforce that the keys in the model state dict match the keys in the checkpoint.
safe (`bool`, *optional*, defaults to `True`):
If `safe` is True, the safetensors files will be loaded. If `safe` is False, the function
will first attempt to load safetensors files if they are available, otherwise it will fall back to loading
pickle files. `filename_pattern` parameter takes precedence over `safe` parameter.
weights_only (`bool`, *optional*, defaults to `False`):
If True, only loads the model weights without optimizer states and other metadata.
Only supported in PyTorch >= 1.13.
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.
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.
filename_pattern (`str`, *optional*):
The pattern to look for the index file. Pattern must be a string that
can be formatted with `filename_pattern.format(suffix=...)` and must contain the keyword `suffix`
Defaults to `"model{suffix}.safetensors"`.
Returns:
`NamedTuple`: A named tuple with `missing_keys` and `unexpected_keys` fields.
- `missing_keys` is a list of str containing the missing keys, i.e. keys that are in the model but not in the checkpoint.
- `unexpected_keys` is a list of str containing the unexpected keys, i.e. keys that are in the checkpoint but not in the model.

Raises:
[`FileNotFoundError`](https://docs.python.org/3/library/exceptions.html#FileNotFoundError)
If the checkpoint file or directory 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.
[`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
If the checkpoint path is invalid or if the checkpoint format cannot be determined.

Example:
```python
>>> from huggingface_hub import load_torch_model
>>> model = ... # A PyTorch model
>>> load_torch_model(model, "path/to/checkpoint")
```
```