in bindings/python/py_src/safetensors/numpy.py [0:0]
def load_file(filename: Union[str, os.PathLike]) -> Dict[str, np.ndarray]:
"""
Loads a safetensors file into numpy format.
Args:
filename (`str`, or `os.PathLike`)):
The name of the file which contains the tensors
Returns:
`Dict[str, np.ndarray]`: dictionary that contains name as key, value as `np.ndarray`
Example:
```python
from safetensors.numpy import load_file
file_path = "./my_folder/bert.safetensors"
loaded = load_file(file_path)
```
"""
result = {}
with safe_open(filename, framework="np") as f:
for k in f.offset_keys():
result[k] = f.get_tensor(k)
return result