Sharded checkpoint resharding
Reconstruct destination tensor regions from logical identities and source intersections rather than reassigning rank filenames.
On this page
The question for today
What you’ll understand
- Map saved global tensor regions into a new supported partition.
- Compute intersection lengths with half-open index ranges.
- Explain compatibility limits for optimizer state, objects, padding, and transformed tensors.
A checkpoint shard is a storage representation of part of a logical state. It need not be the part a new rank should own. Resharding makes that distinction explicit: identify a tensor globally, determine the destination’s required indices, and read the intersecting source regions. Renaming an old rank file or dividing its bytes evenly is not a substitute for that mapping.
Use logical tensor identity as the stable coordinate system
Give every logical tensor a stable name and semantic shape. Record how stored fragments map to its global indices, including dimension order, datatype, padding rules, and any split or merge transform. Parameter aliases and tied weights need an explicit policy so multiple names do not become divergent independent values. Optimizer moments must use the same logical parameter identity even when internal flattening or parameter object IDs change. A successfully opened file says nothing about whether its contents belong to the intended layer or moment.
The destination creates its supported model and optimizer layout, then asks for its required logical regions. PyTorch 2.14 DCP operates in place and uses destination state together with checkpoint metadata for supported load-time resharding. Megatron’s sharded mappings include global shape and offsets. Those capabilities are format- and state-specific: arbitrary Python objects, unsupported optimizer encodings, or architecture changes do not become transformable just because tensor resharding works. Check compatibility for every state category and software version before committing to a new allocation.
Plan reads from intersections and representation rules
For a contiguous one-dimensional illustration, an overlap length is the positive part of the smaller end minus the larger start. Half-open intervals make adjacent regions unambiguous: their shared boundary is not a duplicated element. In multidimensional or strided layouts, a planner must preserve shape and stride meaning rather than assume an overlap is one contiguous byte range. A flattened optimizer format may need a supported conversion to logical tensors before the same intersection reasoning applies. Do not infer that conversion from an incidental filename suffix.
Output buffers may include alignment padding that is not part of the logical tensor. A converter must avoid treating padded values as real parameters or shifting the next tensor’s offset. Compression and quantization introduce their own decoding rules and may alter numerical equivalence; exact lossless reshaping is a different operation from changing precision. Validate source and destination coverage, dtype, names, and values. Compare selected reconstructed slices or small full tensors to a trusted logical reference before allowing the resumed optimizer to consume them.
Test mapping separately from training equivalence
A resharding test can fill each logical tensor with an index-derived pattern, save it under one partition, and restore it under another. The oracle checks every global index, tied-weight relation, and optimizer-state association. This catches gaps, duplicates, and axis transposes that a scalar loss can miss. Then test an actual next training update under stated numerical tolerances. Correct tensor reconstruction is necessary, but changed reductions, input allocation, or optimizer settings can still change the subsequent trajectory.
The modular lab illustrates complete index coverage with different visit orders. Reset, set both m=12 and a=1, predict period twelve, then Play or Step. Separately Reset, set both m=12 and a=5, predict period twelve with a different order, then Play or Step. Each additive orbit visits all residues exactly once per cycle. The model does not read shards or implement a tensor planner. Its limited lesson is that position labels must retain their meaning when traversal order changes; equal counts alone cannot identify the intended values.
Work it through
Restore a differently partitioned tensor slice
A tensor of twelve four-byte elements was stored as three intervals [0,4), [4,8), and [8,12). A new two-way layout asks one destination for [0,6) and the other for [6,12). Assume an unchanged contiguous lossless representation.
The first destination takes four elements from [0,4) and two from [4,8), namely [4,6). It receives six elements, or twenty-four payload bytes.
The second destination takes [6,8), two elements from the middle source, and [8,12), four from the final source. Its six elements also occupy twenty-four bytes.
Total reconstructed payload is twelve elements or forty-eight bytes with no gap or duplication. The middle source contributes to both destinations, demonstrating why assigning each old file to only one new rank would be insufficient.
Resharding follows intersections in logical tensor coordinates. File ownership and destination rank ownership need not coincide.
The living notebook
Explore the model
Interactive lab · modular
Preserve index meaning across traversal orders
Reset, set both m=12 and a=1, predict period twelve, then Play or Step. Separately Reset, set both m=12 and a=5, predict period twelve in a different order, then Play or Step. This additive index orbit does not perform checkpoint I/O, tensor resharding, or multidimensional layout conversion.
- Residue r0
- 0
- Orbit period · m/gcd(m,a)
- 12
- Distinct residues visited
- 1 of 12
Addition modulo m starts at zero: rₙ = na mod m. Playback advances two additions per second. The orbit has period m/gcd(m,a), including period one for a = 0. This is not a cryptographic security test or a primality algorithm. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forComplete counts need logical identities and mappings before they establish correct reconstruction.
Pause & reason
Check your understanding
Your turn
Try it yourself
A saved source interval is [100,180) and a destination needs [150,210). How many shared elements can that source provide, and how many destination elements still need other sources?
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Use the maximum starting index and minimum ending index.
Compare with the solution
Their intersection is [150,180), containing thirty elements. The destination needs sixty elements overall, so [180,210), another thirty, must come from other valid sources. Copying the entire eighty-element source or merely matching a destination byte count would not respect the required logical indices.
Keep the idea
Take it with you
- Reshard by logical tensor identity and index intersections.
- Optimizer mappings, padding, aliases, and encoding rules are part of compatibility.
- Validate reconstruction separately from next-update numerical behavior.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.