advanced25 min studyLesson 585 in Engineering

Sharded checkpoint resharding

Reconstruct destination tensor regions from logical identities and source intersections rather than reassigning rank filenames.

On this page

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.

Rij=Si∩Dj,Dj=⋃iRijR_{ij}=S_i\cap D_j,\qquad D_j=\bigcup_iR_{ij}
S_i is a saved logical tensor region and D_j the required destination region. Under complete nonoverlapping source coverage, their intersections reconstruct D_j exactly. These are index sets, not byte offsets until the encoding and datatype mapping are applied.↔ Scroll wide equations horizontally.

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.

ℓij=max⁡ ⁣(0,min⁡(bi,dj)−max⁡(ai,cj))\ell_{ij}=\max\!\left(0,\min(b_i,d_j)-\max(a_i,c_j)\right)
Saved interval S_i=[a_i,b_i) and destination interval D_j=[c_j,d_j) use integer element indices. The overlap length ell_ij is elements; multiply by bytes/element only for a compatible contiguous uncompressed encoding.↔ Scroll wide equations horizontally.

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.

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.

  1. 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.

  2. 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.

  3. 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.

The result

Resharding follows intersections in logical tensor coordinates. File ownership and destination rank ownership need not coincide.

Explore the model

Interactive lab

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.

Preserve index meaning across traversal ordersAddition 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. Current readings: Residue r0: 0; Orbit period · m/gcd(m,a): 12; Distinct residues visited: 1 of 12. All parameters are adjustable with the labeled controls below.Repeated addition modulo 12: the current residue is 0, and the orbit period is 12.01234567891011+ 5mod 12An additive orbitn = 0rₙ = 0Period = 12Cycle starts at 0:0 → 5 → 10 → 3 →8 → 1 → 6 → 11 →4 → 9 → 2 → 7 → 0Exact residues · two additions per second
Additive orbitCurrent residue / next edge
Residue r0
0
Orbit period · m/gcd(m,a)
12
Distinct residues visited
1 of 12
t = 0 s

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.

Check your understanding

Why should a resharding loader use logical tensor names, shapes, and saved-region metadata?

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.

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.