fastsafetensors is a Python library designed for high-performance loading of safetensors models, particularly optimized for GPU environments (CUDA, ROCm). It aims to offer faster loading times compared to the standard `safetensors` library for large models. The current version is `0.2.2`, and it maintains an active release cadence with frequent bug fixes and performance improvements.
pip install fastsafetensorsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create a dummy safetensors file using the standard `safetensors` library, then load it with `fastsafetensors.FastSafetensorsFile`. It shows how to inspect the file's metadata and how to lazily load individual tensors by accessing them like dictionary items. Note that `torch` is used here for tensor creation and loading, implying it should be installed for this specific example.
Use `safetensors` for saving models: `from safetensors.torch import save_file; save_file(model_state, 'model.safetensors')`.
Be aware that `fsf.get_tensors()` returns metadata (name, shape, dtype, data_offsets), not the actual tensor data. Access specific tensors by key (e.g., `my_tensor = fsf['my_key']`) to trigger their loading.
Install the necessary framework (e.g., `pip install torch`, `pip install tensorflow`, `pip install paddlepaddle`) if you intend to work with framework-specific tensor objects.
Upgrade to `fastsafetensors` version `0.2.1` or newer to benefit from critical bug fixes related to CUDA stream synchronization and device initialization.