Unit 11 of 12 · about 3 hours · implement
Checkpoint consolidation and resharding to a new world size
A checkpoint should describe the logical model, not depend on yesterday's rank numbers. World-size changes test whether that contract covers both weights and optimizer history.
You'll be able to
- Consolidate a small sharded checkpoint into full logical tensors while accounting for the host-memory requirement.
- Restore parameter and optimizer shards onto a different world size and prove the next global-batch update.
- Explain which metadata makes repartitioning possible and which semantic changes resharding cannot repair.
Covers
Read
In this order, only the parts listed
0 of 2 done
- DCP load-time resharding and format conversionPyTorch FSDP2 Tutorial (fully_shard)
How DCP works; Loading, including different world size; Formats (page read 2026-10-14)
Use the matching
AppStatestructure for save and load. The later unwrapped example uses a top-levelmodelkey while the preceding save usedapp.model; preserve the saved nesting instead of copying that example unchanged. - Destination layouts and state-dict optionsPyTorch FSDP2 Tutorial (fully_shard)
state_dict_loader.load;state_dict.StateDictOptions, especiallyfull_state_dict,cpu_offloadandbroadcast_from_rank0
Focus on
- Load into an allocated destination model whose DTensor mesh and placements describe the new partition. The loader reads old chunks intersecting each new local slice; old rank IDs are not new owners.
- Consolidation is representation conversion, not training resume. Full tensors can require enough host memory for the whole model and optimizer state plus temporary copies. Avoid it for routine resharding when DCP can load directly.
- World-size changes must preserve names, global shapes, precision policy, optimizer mapping and the fixed global batch used by your oracle. Resharding does not fix a changed vocabulary or an incompatible optimizer.
- A changed rank count can alter reduction rounding, data partitioning and RNG streams. Check numerical update equivalence with explicit tolerances; bitwise-identical continuation requires a stronger execution contract.
Common mistakes · 3
- Renaming shard files by new rank and ignoring tensor offsets. New shards can span several old shards.
- Loading weights successfully but dropping or reassigning optimizer moments after repartitioning.
- Keeping the local batch fixed when world size changes, then attributing the resulting different global update to checkpoint corruption.
Try it yourself
Closed-book, before checking anything
dcp_to_torch_save on the tiny checkpoint and confirm that the consolidated model and optimizer entries represent the same logical state; do not use consolidation as the reshard mechanism.Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.What lets a loader restore four saved shards into two destination shards?Answer
Global tensor names and shapes, old chunk offsets and sizes, and the destination layout. It computes the required intersections rather than assuming rank-to-rank file identity.
2.Must all old shards be loaded in full on every new rank?Answer
No. A layout-aware loader can read the parts needed for each destination shard. Full consolidation is a separate, memory-heavier operation.
3.Does loading onto fewer ranks guarantee bitwise-identical future training?Answer
No. Collective reduction order and data/RNG assignment may change. First prove the same logical state and a fixed-batch update within stated tolerances.
You're done when
Both the direct changed-world-size restore and tiny consolidated export reconstruct the same logical state, and the restored optimizer's next update matches the oracle.
Only when you can do this without notes.
Leads to
Notes
Resources · 1 for this unit, 10 more in the section
- PyTorch FSDP2 Tutorial (fully_shard)PyTorch · required
Work through
fully_shardper block then root,MixedPrecisionPolicy,reshard_after_forward, explicit prefetch and DTensor state dicts, and check each against the 2.14 API reference. FSDP1 (FullyShardedDataParallel) is the legacy API; record the PyTorch version beside every result.
Also in this section
- CS336 Assignment 2 (Spring 2026) - Sections 6, 7 and 8.3Stanford University · primary
Complete
optimizer_state_shardingandoptimizer_state_sharding_accounting(Section 6),fsdpandfsdp_accounting(Section 7) andfsdp_calcs(Section 8.3) with your own code.tests/test_sharded_optimizer.pyandtests/test_fsdp.pyrun on CPU with Gloo. For each variant, predict per-rank state, peak live tensors and collective bytes before testing tiny cases. - Ultra-Scale Playbook - Zero Redundancy Optimizer (ZeRO)Hugging Face · required
Read the ZeRO-1, ZeRO-2 and ZeRO-3 progression. Reproduce the memory diagrams for one transformer layer and annotate every all-gather, reduce-scatter and reshard boundary. Its "two times faster" line holds for bytes moved at equal payload in the bandwidth-bound regime.
- ZeRO: Memory Optimizations Toward Training Trillion Parameter ModelsRajbhandari et al. (SC 2020) · required
Read the memory analysis (model states with optimizer bytes per parameter) and the stage-by-stage savings and communication analysis. Reproduce its per-device memory for one model and degree.
- PyTorch FSDP: Experiences on Scaling Fully Sharded Data ParallelZhao et al. (VLDB 2023) · support
Read the design sections on wrapping granularity, prefetching, rate limiting and hybrid sharding. Its flat parameter describes FSDP1; FSDP2 shards each parameter as a DTensor.
- TorchTitan - FSDP2 NotesPyTorch · support
Read
docs/fsdp.mdfor the FSDP1 to FSDP2 changes, dim-0 DTensor shards,reshard_after_forwardvalues and hybrid sharding on a 2D mesh, thentorchtitan/distributed/fsdp.py. Pin the commit you read. - DeepSpeed ZeRO TutorialDeepSpeed · support
Use the stage definitions and the
zero_optimizationconfiguration as the original vocabulary for the three stages and offload. Running it needs CUDA GPUs. - Distributed Training Guide - Chapter 4 FSDPLambda Labs · support
Read model initialization on the meta device, sharding, reshard policy, CPU offload and sharded checkpoint code in
04-fully-sharded-data-parallelas a practitioner second view. Its scripts need CUDA. - TorchFeather - FSDP and Activation CheckpointingTorchFeather · support
Watch the video segment at 10:49:41 on meshes, DDP and FSDP, then read
distributed/activation_checkpoint.pyand the FSDP calls inmodel/parallelize.py. Trace how parallel dimensions select the mesh, FSDP policy, precision and reshard behavior; do not adopt the full framework. - How to Scale Your Model - Chapter 5 TrainingGoogle DeepMind · support
Work the FSDP, model-state sharding, rematerialization and offload calculations in Chapter 5. Translate each JAX-oriented layout into equivalent parameter, activation and collective ownership without implementing JAX.
- TensorTonic - Account for ZeRO Memory by StageTensorTonic · support
Solve Account for ZeRO Memory by Stage before the CS336 accounting problems.