[PR #1859] [CLOSED] weights: add an opt-in read-only safetensors source (no engine changes) #3723

Closed
opened 2026-11-07 15:30:18 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/1859
Author: @spideytznn
Created: 10/10/2026
Status: ❌ Closed

Base: main ← Head: contribute/safetensors-reader


📝 Commits (1)

  • 4b87951 weights: add a standalone read-only safetensors source with adversarial tests

📊 Changes

12 files changed (+26435 additions, -0 deletions)

View changed files

➕ docs/SAFETENSORS_SOURCE.md (+74 -0)
➕ include/strata/weights/safetensors.hpp (+76 -0)
➕ native_safetensors/CMakeLists.txt (+39 -0)
➕ src/weights/json_checked.hpp (+66 -0)
➕ src/weights/safetensors.cpp (+286 -0)
➕ src/weights/source_inspect.cpp (+69 -0)
➕ src/weights/source_test.cpp (+81 -0)
➕ third_party/nlohmann/.gitattributes (+3 -0)
➕ third_party/nlohmann/LICENSE.MIT (+21 -0)
➕ third_party/nlohmann/README.md (+20 -0)
➕ third_party/nlohmann/json.hpp (+25526 -0)
➕ tools/test_safetensors_reader.py (+174 -0)

📄 Description

Original NVIDIA ModelOpt NVFP4 checkpoints cannot currently be consumed as safetensors by Strata's weight-source interface. This first patch provides a read-only source and standalone inspector, ahead of model/layout and runtime integration. It is related to #1858; the complete experimental implementation and its measured limits are linked there.

The source validates the index and all shard headers, retains physical shapes and absolute byte ranges, performs bounded coalesced reads into caller-owned spans, accounts for bytes by family, and can seal expert/MTP reads or close all resident startup handles. It rejects malformed descriptors, duplicate JSON keys, unsafe paths, index mismatches and out-of-bounds reads. nlohmann/json 3.12.0 is vendored with its MIT license and hash; configuration downloads nothing.

This is explicitly opt-in through cmake -S native_safetensors .... All 12 changed paths are additions. The root CMake file, every existing engine/backend/setup file, CLI and runtime default are unchanged byte-for-byte against the tested upstream baseline fb58e0dbc8399662c0e47c76578c6e878b14f6cf. No complete inference or speed improvement is claimed by this patch; NVFP4 layout binding, CUDA execution, scheduling and server integration are separate follow-ups.

Validation on Windows, MSVC 19.44.35228 / Python 3.13.15:

  • Standalone Release and Debug builds pass with /W4 /WX; CTest passes 2/2 in each configuration.
  • The C++ fixture verifies scatter/coalescing, family counters, descriptor ownership, validation-before-I/O, sealing and reuse of owned sample bytes.
  • Python runs 12 adversarial/container tests: 11 pass and the symlink-escape fixture is skipped because the account lacks Windows symlink privileges. The sparse >4 GiB seek test passes.
  • The Release inspector parses the original checkpoint's 11 shards / 299,545 tensors, reading 40,402,984 header bytes with every payload-family counter zero.

No CUDA, HIP or SYCL backend files are touched or built. Linux execution has not been validated. Build commands, behavior and limitations are documented in docs/SAFETENSORS_SOURCE.md.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/1859 **Author:** [@spideytznn](https://github.com/spideytznn) **Created:** 10/10/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `contribute/safetensors-reader` --- ### 📝 Commits (1) - [`4b87951`](https://github.com/Niko1221/Strata/commit/4b879513b9ac08c6149786cb3e99a7ae1749a558) weights: add a standalone read-only safetensors source with adversarial tests ### 📊 Changes **12 files changed** (+26435 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `docs/SAFETENSORS_SOURCE.md` (+74 -0) ➕ `include/strata/weights/safetensors.hpp` (+76 -0) ➕ `native_safetensors/CMakeLists.txt` (+39 -0) ➕ `src/weights/json_checked.hpp` (+66 -0) ➕ `src/weights/safetensors.cpp` (+286 -0) ➕ `src/weights/source_inspect.cpp` (+69 -0) ➕ `src/weights/source_test.cpp` (+81 -0) ➕ `third_party/nlohmann/.gitattributes` (+3 -0) ➕ `third_party/nlohmann/LICENSE.MIT` (+21 -0) ➕ `third_party/nlohmann/README.md` (+20 -0) ➕ `third_party/nlohmann/json.hpp` (+25526 -0) ➕ `tools/test_safetensors_reader.py` (+174 -0) </details> ### 📄 Description Original NVIDIA ModelOpt NVFP4 checkpoints cannot currently be consumed as safetensors by Strata's weight-source interface. This first patch provides a read-only source and standalone inspector, ahead of model/layout and runtime integration. It is related to #1858; the complete experimental implementation and its measured limits are linked there. The source validates the index and all shard headers, retains physical shapes and absolute byte ranges, performs bounded coalesced reads into caller-owned spans, accounts for bytes by family, and can seal expert/MTP reads or close all resident startup handles. It rejects malformed descriptors, duplicate JSON keys, unsafe paths, index mismatches and out-of-bounds reads. nlohmann/json 3.12.0 is vendored with its MIT license and hash; configuration downloads nothing. This is explicitly opt-in through `cmake -S native_safetensors ...`. All 12 changed paths are additions. The root CMake file, every existing engine/backend/setup file, CLI and runtime default are unchanged byte-for-byte against the tested upstream baseline `fb58e0dbc8399662c0e47c76578c6e878b14f6cf`. No complete inference or speed improvement is claimed by this patch; NVFP4 layout binding, CUDA execution, scheduling and server integration are separate follow-ups. Validation on Windows, MSVC 19.44.35228 / Python 3.13.15: - Standalone Release and Debug builds pass with `/W4 /WX`; CTest passes 2/2 in each configuration. - The C++ fixture verifies scatter/coalescing, family counters, descriptor ownership, validation-before-I/O, sealing and reuse of owned sample bytes. - Python runs 12 adversarial/container tests: 11 pass and the symlink-escape fixture is skipped because the account lacks Windows symlink privileges. The sparse >4 GiB seek test passes. - The Release inspector parses the original checkpoint's 11 shards / 299,545 tensors, reading 40,402,984 header bytes with every payload-family counter zero. No CUDA, HIP or SYCL backend files are touched or built. Linux execution has not been validated. Build commands, behavior and limitations are documented in `docs/SAFETENSORS_SOURCE.md`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:30:18 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#3723
No description provided.