feat: add 3FS copier support#59
Conversation
8f5fc82 to
f468751
Compare
|
@ABNER-1 |
|
|
||
| # Import ThreeFSFileReader from the independent fastsafetensor_3fs_reader package | ||
| from fastsafetensor_3fs_reader import ( | ||
| ThreeFSFileReader, |
There was a problem hiding this comment.
I expected that 3fs exposes generic, low-level python interfaces, but this seems specific to fastsafetensors. Does 3fs have plans to expose such interfaces? If so, this repository should contain ThreeFSFileReader.
There was a problem hiding this comment.
The 3fs reader repo is here: https://github.com/ABNER-1/fastsafetensor_3fs_reader.
It mainly uses pyusrbio for the implementation and includes tools to find optimal 3fs download/loading parameters.
I'm not sure if these files belong in fastsafetensors—let's discuss.
The repo is currently under my personal account; we can also consider moving it to a more appropriate org later.
|
Some files were modified by pre-commit hooks. I'll revert them manually. |
192b535 to
9e49187
Compare
Add support for DeepSeek 3FS USRBIO as a new copier backend for high-performance safetensors file loading. - Add fastsafetensors/copier/threefs.py: ThreeFSFileCopier implementation - Add fastsafetensors/threefs_loader.py: ThreeFSLoader and ParallelThreeFSLoader - Add conditional import in copier/__init__.py for optional 3FS dependency - Add **kwargs to gds/nogds copier constructors for forward compatibility - Add threefs optional dependency group in pyproject.toml - Minor logging improvements in parallel_loader.py Signed-off-by: yuanyuxing.yyx <yuanyuxing.yyx@alibaba-inc.com>
b8844ac to
e3b3556
Compare
- Add tests/threefs/test_threefs.py: unit tests for ThreeFSFileCopier, ThreeFSLoader, and ParallelThreeFSLoader (6 tests) - Add tests/threefs/test_parallel_threefs.py: integration tests for ParallelThreeFSLoader covering single/multi-file iteration, tensor data correctness (shape/dtype/values), resource cleanup, and close-without-iterate edge case (5 tests) - Add tests/threefs/conftest.py: shared fixtures for 3FS tests Signed-off-by: yuanyuxing.yyx <yuanyuxing.yyx@alibaba-inc.com>
|
@ABNER-1 Let me spend some more time to learn fastsafetensors_3fs_reader. Then, I will propose how to deal with this issue. |
feat: add 3FS copier support
Summary
Add support for DeepSeek 3FS USRBIO as a new copier backend for high-performance safetensors file loading. This enables fastsafetensors to leverage 3FS's zero-copy I/O and asynchronous read capabilities when loading model weights from 3FS-mounted filesystems.
resolve #55
Motivation
3FS (Fire-Flyer File System) is a high-performance distributed filesystem designed for AI/ML workloads. By integrating 3FS USRBIO as a copier backend, fastsafetensors can achieve significantly higher I/O throughput when model weights are stored on 3FS-mounted paths, complementing the existing GDS and NoGDS copier backends.
Changes
New Files
fastsafetensors/copier/threefs.py: Core 3FS copier implementationThreeFSFileCopier: ImplementsCopierInterfaceusing 3FS USRBIO for file readsnew_threefs_file_copier(): Factory function registered as"3fs"copier type via the copier registryfastsafetensor-3fs-readerpackage for the actual 3FS I/O operationsfastsafetensors/threefs_loader.py: High-level loader APIs for 3FSThreeFSLoader: Single-file loader extendingBaseSafeTensorsFileLoaderParallelThreeFSLoader: Pipeline-parallel loader extendingPipelineParallelfor batch loading multiple safetensors filesModified Files
fastsafetensors/copier/gds.py&fastsafetensors/copier/nogds.py: Added**kwargstonew_gds_file_copier()andnew_nogds_file_copier()for forward-compatible copier constructor signaturesfastsafetensors/copier/__init__.py: ExportThreeFSFileCopierfastsafetensors/parallel_loader.py: Minor logging improvements (addednum_keysto batch summary)pyproject.toml: Addedthreefsoptional dependency group (fastsafetensor-3fs-reader>=0.1.0)Usage
Dependencies
This feature depends on the
fastsafetensor-3fs-readerpackage, which is declared as an optional dependency:If the 3FS reader package is not installed, the 3FS copier will not be available but all other functionality remains unaffected.
Testing
Tests are provided under
tests/threefs/, automatically skipped whenfastsafetensor_3fs_readeris not available. To run locally with mock backend:FASTSAFETENSORS_BACKEND=mock TEST_FASTSAFETENSORS_FRAMEWORK=pytorch \ pytest tests/threefs/ -vTests also run in real 3FS environments without any special environment variable -- the skip condition checks whether
fastsafetensor_3fs_readeris importable.tests/threefs/test_threefs.py-- Unit tests for core 3FS components (uses gpt2 model data)test_threefs_copier_registered: VerifiesThreeFSFileCopieris registered in the copier registrytest_ThreeFSFileCopier: Tests the copiersubmit_io+wait_iowith tensor data verificationtest_ThreeFSLoader: Tests single-file loading viaThreeFSLoadertest_ThreeFSLoader_multiple_files: Tests multi-file loading with full tensor correctnesstests/threefs/test_parallel_threefs.py-- Integration tests forParallelThreeFSLoader(uses example safetensors files)test_parallel_single_file: Single-file iteration with tensor data correctness verificationtest_parallel_multiple_files: Multi-file iteration with shape, dtype, and value verificationtest_parallel_close_and_memory_release: Resource cleanup and bounce buffer release after full iterationtest_parallel_close_without_iterate: Graceful cleanup when closing without iteratingAll 8 tests pass (~1.7s).