Stream safetensors checkpoints into models - #411
Conversation
Signed-off-by: Gangzheng Tong <gtong@nvidia.com>
Greptile SummaryThe PR adds file-backed and direct-to-model safetensors loading to reduce peak checkpoint memory, then enables it for LingBot presets.
Confidence Score: 4/5The PR is not yet safe to merge because supported safetensors installations can still fail during streamed model initialization. The streaming paths pass Files Needing Attention: flashdreams/flashdreams/core/checkpoint/load.py; flashdreams/pyproject.toml Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[LingBot or WAN transformer config] --> B[Materialize model on init_device]
B --> C{stream_checkpoint enabled?}
C -- No --> D[Load complete state dict]
C -- Yes --> E{Checkpoint format}
E -- Single safetensors --> F[Resolve local or cached file]
E -- Sharded index --> G[Resolve index and shards]
F --> H[Validate keys and shapes]
G --> H
H --> I[Copy one tensor at a time]
I --> J[Initialized model]
Reviews (4): Last reviewed commit: "Merge branch 'main' into dev/gtong/strea..." | Re-trigger Greptile |
|
/ok to test b0c0d2f |
ArielG-NV
left a comment
There was a problem hiding this comment.
1 suggestion
1 question
Benchmarked on GB300, lingbot checkpoints streaming is 3.13 s / 15.3% slower on cached startup |
|
/ok to test 2aaeb74 |
Is this because we are issuing 1 big copy ( Is this something we can potentially improve upon in your opinion? |
Summary
Resource savings
LingBot’s 16 transformer shards total approximately 69 GiB. Previously, non-streaming loads also created a merged safetensors cache, requiring an additional ~70 GiB of disk space.
Streaming avoids this duplicate cache and avoids retaining a complete checkpoint state dict during loading. This reduces peak host-memory pressure and prevents out-of-memory failures on RAM-constrained systems.
Loading-time delta
Benchmarked on an NVIDIA GB300 with cached LingBot checkpoints, streaming adds 3.13 s (15.3%) to startup time. This ~3-second cost is an acceptable tradeoff for the 14B model’s reduced disk usage and host-memory pressure.
stream_checkpointis enabled by default for LingBot and remains disabled by default for other models until their checkpoint layouts and transform requirements are validated.