Repository navigation
Conversation
ormandj
requested review from
Fridge003,
JustinTong0323,
Qiaolin-Yu,
Ying1123,
b8zhong,
hnyls2002,
ispobock,
merrymercy,
mmangkad,
sogalin,
wisclmy0611,
xiezhq-hermann and
zijiexia
as code owners
October 7, 2026 05:45
This was referenced Oct 7, 2026
This was referenced Oct 7, 2026
This was referenced Oct 14, 2026
This was referenced Oct 15, 2026
…tream
A model can name the checkpoint tensors it keeps in host memory through
host_resident_weight_patterns. Under --load-format instanttensor, the loader
reads the safetensors headers and streams only files without such tensors to
the GPU. Files that hold them load through the CPU safetensors iterator;
their other tensors are moved to the device, where InstantTensor places
everything else. DeepSeek-V4 and its DSpark draft name the Engram tables
when --engram-config places them on the CPU ("placement": "cpu").
ormandj
force-pushed
the
instanttensor-host-resident
branch
from
October 29, 2026 21:50
91da44c to
99e55fc
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Builds on #40453 (InstantTensor loader by YitaoYuan), which is now on main.
Motivation
--load-format instanttensor(#40453) streams every checkpoint file to the GPU, and each weight loader then copies its part. With--engram-config '{"placement": "cpu"}', DeepSeek-V4.1 keeps its Engram tables in pinned host memory: 188.8 GiB of rows and scales in 2 of the 48 checkpoint files. Under InstantTensor, every rank would first materialize each full table on its GPU. The FP8 rows of one table are about 91.5 GiB. That does not fit on a 96 GB GPU, where the rest of the model already takes about 73 GiB per rank at TP4. So the host table currently has to use the default loader.Modifications
DefaultModelLoader.Source.host_resident_weight_patterns: a model can list substrings of checkpoint tensor names that it keeps in host memory.Source.init_newreads this attribute from the model, likeallow_patterns_overrides.--load-format instanttensor, when the model declares host-resident patterns, the loader reads the safetensors headers and splits the file list. Files with no matching tensor stream through InstantTensor as before. Files that contain a matching tensor load through the existing multi-threaded CPU safetensors iterator. The matching tensors stay on the host. The other tensors in those files are moved to the current device, so every tensor that is not host-resident arrives on the GPU, as with InstantTensor. When nothing matches, InstantTensor gets the full file list, as before. Non-safetensors files are not opened by the split; InstantTensor still reports them. As with the default loader,--weight-loader-disable-mmapcannot read theF8_E8M0scales in the Engram files (safetensors.torch.loadin safetensors 0.8.0 has no such dtype); a follow-up PR avoids that path.DeepseekV4ForCausalLMreturns(".engram.embed.",)when--engram-configplaces the Engram tables on the host ("placement": "cpu") andNoneotherwise. The DSpark draft shares the property because it reads the same checkpoint and drops the Engram tensors. In the DeepSeek-V4.1 checkpoint, the two Engram files contain only Engram tensors.Accuracy Tests
Load-path change only: the same values reach the same weight loaders. New tests in
test/registered/unit/model_loader/test_instanttensor_loader.pyuse a three-file checkpoint with DeepSeek-V4.1 tensor names and an InstantTensor stub. The stub records the files it receives and places tensors on a stand-in device:On this branch (current main plus #40453), the file passes (14 tests) on macOS (CPU) and on Linux aarch64 (CPU, PyTorch 2.14.1). With the production change reverted, 4 of the 5 new tests fail. The rest of
test/registered/unit/model_loader/also passes on macOS (132 passed, 1 skipped in total;test_modelopt_loader.pywas not collected in the local environment becausetvm_ffiis not installed).Earlier, on #40453 at the same head with an older main, a separate check used the real InstantTensor library on one RTX PRO 6000 Blackwell GPU. The dense files and the Engram file's other tensor arrived on
cuda:0, and the Engram tables stayed on the CPU with exact values. The production diff of this PR is unchanged since that check.2026-10-29: rebased onto main
974831643f, where #40453 has merged (the branch now carries only this commit) and #46893 replacedSGLANG_ENABLE_DSV41_ENGRAM_HOST_TABLEwith--engram-config, soDeepseekV4ForCausalLMnow declares the Engram patterns when--engram-configsets"placement": "cpu";test_instanttensor_loader.pypasses on the new head (14 tests, macOS CPU), and the SM120 GPU results in this description are from the previous head and will be re-run.Speed Tests and Profiling
DeepSeek-V4.1-Flash, TP4/EP4, 4x RTX PRO 6000 Blackwell (SM120, PCIe), host Engram table (per-rank layout), checkpoint on local NVMe (ZFS), one server start each, on an older main with the same source otherwise. Times are the
Load weightelapsed time on TP0 for the target model:--load-format instanttensor(#40453) + this changeWithout this change, InstantTensor cannot be used with the host table on this setup (see Motivation), so the default loader is the only comparison. In the InstantTensor run, the 46 device files took about 42 s. The 2 Engram files then took about 68 s through the CPU safetensors path. A follow-up PR replaces that path with positioned reads.
Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ciDeveloped with AI assistance.
CI States
Latest PR Test (Base): ❌ Run #40961104686
Latest PR Test (Extra): ❌ Run #40961104852
Latest PR Test (AMD ROCm 10): ❌ Run #40961104822