Read replicated safetensors tensors once and broadcast behind an option#3475
Open
mridul-sahu wants to merge 1 commit into
Open
Read replicated safetensors tensors once and broadcast behind an option#3475mridul-sahu wants to merge 1 commit into
mridul-sahu wants to merge 1 commit into
Conversation
mridul-sahu
force-pushed
the
feature/safetensors-broadcast-replicated
branch
from
July 17, 2026 16:34
505fa09 to
c8a4143
Compare
Sharding-driven reads pull replicated tensors from storage once per process, so a checkpoint replicated across N processes costs N x its size in storage egress. SafetensorsOptions.broadcast_replicated removes that: replication in a NamedSharding is exactly the mesh axes its spec does not use, so the loader assigns each unused axis to an evenly divisible tensor dimension and reads under that de-duplicated sharding -- each byte owned once, the read spread across all replicas' hosts. An identity computation with the target out_shardings then broadcasts the shards over the accelerator interconnect, batched under a fixed per-device byte bound so transient device memory stays predictable. Axes that fit no dimension stay unplaced (partial de-duplication); leaves without a NamedSharding, single-process loads, and unshardable tensors fall back to the normal read path unchanged.
mridul-sahu
force-pushed
the
feature/safetensors-broadcast-replicated
branch
from
July 17, 2026 16:39
c8a4143 to
8b4e042
Compare
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.
Description
Follow-up to #3455. The sharding-driven load reads at most the bytes each process needs — except for tensors replicated across processes, which every process re-reads in full. On a large cluster loading from object storage, that is the one case where total egress grows with the number of hosts instead of staying near the checkpoint's size.
This PR adds the opt-in
SafetensorsOptions.broadcast_replicated(defaultFalse). When enabled in a multi-process run, leaves with ajax.sharding.NamedShardingthat are replicated across processes are loaded in two steps:out_shardingsfans the shards out over the accelerator interconnect. Broadcasts are batched so per-device output stays under 1 GiB per call, bounding the transient device memory.This trades accelerator interconnect traffic for storage egress, so it helps when storage bandwidth or egress cost is the bottleneck. Leaves with other shardings, single-process runs, and the default configuration are unaffected.
Type of change
Checklist
CHANGELOG.mdunder the[Unreleased]section (or the relevantcheckpoint//export/changelog).