Skip to content

Add FGDS (an alternative solution of GDS) copier - #111

Merged
takeshi-yoshimura merged 1 commit into
foundation-model-stack:mainfrom
kk47:main
Sep 24, 2026
Merged

takeshi-yoshimura merged 1 commit into
foundation-model-stack:mainfrom
kk47:main

Conversation

@kk47

@kk47 kk47 commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Add a new 'fgds' copier for direct GPU storage access, The FGDS provides a high-performance, easy-to-use alternative to existing GDS implementations.

FGDS micro benchmark shows that FGDS outperforms GDS by 11%~109%, and POSIX by 40%~143%. When loading the Qwen-32B model in the H100+NVME SSD environment, fgds copier shows 2.6x improvement than nogds copier.

Key changes:

  • Add fastsafetensors/cpp/fgds_ext.cpp: C++ pybind11 extension wrapping libfgds
  • Add fastsafetensors/cpp/fgds_ext.pyi: Type stubs for the extension
  • Add fastsafetensors/copier/fgds.py: Python FgdsFileCopier implementation
  • Register 'fgds' copier in fastsafetensors/copier/init.py
  • Add fgds_ext build target in setup.py
  • Add use_fgds parameter to SafeTensorsFileLoader and fastsafe_open

The FGDS copier follows the same pattern as the existing GDS copier:

  • Supports O_DIRECT file access
  • Uses async multi-threaded read submission
  • Registers GPU memory for direct I/O
  • Falls back to nogds copier when libfgds is unavailable
  • Properly deregisters memory and cleans up resources

Usage:
loader = SafeTensorsFileLoader(pg, device='cuda:0', use_fgds=True)
# or
with fastsafe_open(files, device='cuda:0', use_fgds=True) as f:
...

@kk47

kk47 commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

The old PR is #101 and closed for conflict resons.

@takeshi-yoshimura

Copy link
Copy Markdown
Collaborator

@kk47
Thanks for adding FGDS support. I think the current implementation, however, differs significantly from the existing C++ extension design in fastsafetensors, and I believe a substantial rework is needed before this can be merged.

At minimum, I would like the implementation to follow these requirements:

  • Please do not introduce separate fgds_ext.cpp / fgds_ext.pyi modules. FGDS support should be integrated into the existing ext.cpp / cpp.pyi, in the same way that the existing optional CUDA/HIP/GDS functionality is handled. This should also eliminate the need for a separate fgds_ext build target and the Windows stub extension.

  • Please remove FgdsWrapper and do not tie dlopen() / dlclose() to the lifetime of individual wrapper/file objects. FGDS functions should be resolved as part of the existing load_library_functions() mechanism (or using the same design), with function pointers and an availability flag kept in the existing extension.

  • Please make the lifetime of fgds_open() / fgds_close() explicit and consistent with the existing GDS initialization model. fgds_open() should not be performed for every FgdsFileCopier instance without a corresponding, well-defined close operation.

  • Please avoid passing a raw FgdsWrapper * to worker threads. Once the FGDS functions are loaded into the existing extension, the reader implementation should be able to invoke them directly without introducing an additional object-lifetime dependency.

These are structural issues rather than individual bugs, so I would prefer to address the overall design first before reviewing smaller implementation details.

@kk47

kk47 commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

@takeshi-yoshimura Thank you for the structural feedback. I have reworked the FGDS copier accordingly and would appreciate it if you could take another look.

Comment thread fastsafetensors/cpp/ext.cpp Resolved
Comment thread fastsafetensors/copier/fgds.py Resolved
Comment thread fastsafetensors/copier/fgds.py Resolved
Comment thread fastsafetensors/cpp/ext.cpp Resolved
Comment thread fastsafetensors/copier/fgds.py Resolved
Comment thread fastsafetensors/loader.py Resolved
@kk47
kk47 force-pushed the main branch 3 times, most recently from 6bf6d04 to 8accd9a Compare September 21, 2026 09:34
@kk47

kk47 commented Sep 22, 2026

Copy link
Copy Markdown
Contributor Author

@takeshi-yoshimura Sorry for taking so long to resolve the unittest failure. The issue was that torch.cuda.caching_allocator_alloc in framework.alloc_tensor_memory returns an offset within a GPU memory segment, whereas fgds_regmem requires a base pointer obtained directly from cudaMalloc. Setting the minimum allocation size to 2 MB resolved the page alignment problem.

@takeshi-yoshimura takeshi-yoshimura left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kk47
Thanks for reworking the implementation around the existing extension and library-loading design. I added one more request to make sure minimizing changes for current users who do not enable FGDS.

Comment thread fastsafetensors/cpp/ext.cpp Outdated
// GPU is available, so we only attempt the load when gpu_found is set.
fgds_found = false;
#ifndef _MSC_VER
if (gpu_found) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make loading libfgds.so strictly opt-in. Currently, this block runs whenever the shared load_library_functions() detects a GPU, even when use_fgds=False and another copier (gds, nogds, unified, or dstorage) is selected.

Add a new 'fgds' copier for direct GPU storage access,
The FGDS provides a high-performance, easy-to-use alternative to existing
GDS implementations.

FGDS micro benchmark shows that FGDS outperforms GDS by 11%~109%, and POSIX by
40%~143%. When loading the Qwen-32B model in the H100+NVME SSD environment,
fgds copier shows 2.6x improvement than nogds copier.

Key changes:
- Add fastsafetensors/copier/fgds.py: Python FgdsFileCopier implementation
- Register 'fgds' copier in fastsafetensors/copier/__init__.py
- Add use_fgds parameter to SafeTensorsFileLoader and fastsafe_open

The FGDS copier follows the same pattern as the existing GDS copier:
- Supports O_DIRECT file access
- Uses async multi-threaded read submission
- Registers GPU memory for direct I/O
- Falls back to nogds copier when libfgds is unavailable
- Properly deregisters memory and cleans up resources

Usage:
    loader = SafeTensorsFileLoader(pg, device='cuda:0', use_fgds=True)
    # or
    with fastsafe_open(files, device='cuda:0', use_fgds=True) as f:
        ...

Signed-off-by: Kai Kuang <[email protected]>
@takeshi-yoshimura
takeshi-yoshimura merged commit 1d19926 into foundation-model-stack:main Sep 24, 2026
13 checks passed
@takeshi-yoshimura

Copy link
Copy Markdown
Collaborator

@kk47 Merged. Thanks!

kk47 added a commit to kk47/fgds that referenced this pull request Oct 28, 2026
The FGDS copier for fastsafetensors has been merged upstream
(foundation-model-stack/fastsafetensors#111), so the manual patch is
no longer needed. Update README.md and docs/fgds-fastsafetensor.md
accordingly, and remove the obsolete patch file.

Signed-off-by: Kai Kuang <[email protected]>
pengkunlunHIT pushed a commit to Storage-and-OS-for-AI/fgds that referenced this pull request Oct 30, 2026
The FGDS copier for fastsafetensors has been merged upstream
(foundation-model-stack/fastsafetensors#111), so the manual patch is
no longer needed. Update README.md and docs/fgds-fastsafetensor.md
accordingly, and remove the obsolete patch file.

Signed-off-by: Kai Kuang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants