Unit 7 of 11 · about 4 hours · implement

Restoring onto a different world size or mesh

Jobs rarely restart on identical hardware. Resharding turns a checkpoint from a same-mesh snapshot into portable state.

You'll be able to

  • Load a sharded checkpoint onto a different world size and prove full-parameter equality.
  • Explain which state reshards cleanly (parameters, aligned optimizer moments) and which does not (RNG streams, topology-bound shards).

Covers

World-size and mesh resharding on restore
1

Read

In this order, only the parts listed

0 of 4 done

  1. Reshard across topologies at loadPyTorch Distributed Checkpoint Recipes

    How DCP works: save on any number of ranks, then re-shard across differing cluster topologies at load time; Loading: same or different world size with the pre-allocated destination plan; Formats for the single-file export path (page read 2026-10-14)

  2. Seed checkpoints and reshardingTorchTitan - Checkpointing

    Creating a seed checkpoint: every parallelism degree set to 1 on one device, then loaded anywhere via DCP resharding

  3. Why resharding is hardNanotron - Distributed Serialization

    Distributed serialization mechanism: checkpoints are NOT topology agnostic because of random_states and sharded tensors, with the checkpoint_reshape plan; optimizer states aligned with parameters as the reshardable part

  4. The no-reshard baselinePicotron - Checkpoint State

    load_checkpoint: Assume the topology is the same, with per-TP and PP-rank .pth names, so resume never remaps across degrees; adjust_tensor_size belongs to the separate Hugging Face initialization path, where it slices embedding, output-projection and MLP weights by TP rank but takes the leading rows of q, k and v on every rank

2

Focus on

  • DCP resharding is a load-time plan from saved shards to live objects: same files, new layout, decided from the destination model's sharding. Nothing in the checkpoint changes.
  • Parameters and their aligned optimizer moments remap; RNG streams do not. Two streams at have no equivalent, so a resharded resume reseeds or replays RNG explicitly.
  • A seed checkpoint is the extreme case: build once at degree 1, reshard everywhere. It separates initialization randomness from layout.
  • Picotron resumes only onto the saving layout. Its slicer serves initialization from full Hugging Face weights, and even there its q, k and v slices ignore the TP rank. Shrinking from onto needs concatenation across files, which only a planner (DCP) or an explicit reshape provides.
Common mistakes · 3
  • Assuming shard files map to ranks. Planner-assigned ranges follow the destination layout; a new rank's slice may come from any old file.
  • Resharding the model but skipping the moments check. Moments follow parameters only while the parameter-to-state alignment holds, so verify moments per parameter after the move.
  • Expecting the sampler position to survive a world-size change. Per-rank data ownership changes with the new degree, so recompute the shard assignment and resume from a global step, not a rank offset.
3

Try it yourself

Closed-book, before checking anything

Save a fully_shard toy model plus Adam state at world size 2 on CPU, load it at world size 1 over differently seeded initialization, and show the full parameter tensors equal the world-size-2 reference exactly.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.A 4-rank checkpoint loads onto 2 ranks. Where does the second rank's new slice come from?Answer

    Wherever the load plan puts it: DCP reads all saved shards and writes each destination rank its new slice. Files are not rank-addressed.

  2. 2.After a restore from to , loss matches but later dropout draws differ from the same-mesh resume. Is the restore broken?Answer

    No. Parameters and optimizer state reshard, but RNG streams have no cross-topology equivalent, so dropout draws legitimately differ. Statistical match is the right bar for that stream.

  3. 3.Why can a seed checkpoint initialize any mesh while a training checkpoint cannot resume on any mesh without extra work?Answer

    The seed holds only initial weights, which slice cleanly. A training checkpoint also holds optimizer moments, scheduler position, RNG streams and data position, each with its own layout dependence.

  4. 4.Picotron's adjust_tensor_size pads a narrowed slice with torch.empty rows when the target is wider. What must happen before training on those rows?Answer

    They must be re-initialized: torch.empty allocates without drawing values, so the padded rows are garbage until reset. That path is Hugging Face initialization, not resume.

5

Practice

  • DCP recipe Loading example across world sizes

    Loading: rebuild the model at the new world size, then dcp.load the old checkpoint_id; assert full-parameter equality with a full_state_dict=True comparison

    Proven pattern on CPU gloo: save at 2 processes, load at 1, all 4 parameter tensors bit-exact. Check optimizer moments the same way when the optimizer configuration is unchanged.

You're done when

A 2-to-1 CPU restore matches the reference bit-exactly on parameters, and you can state for each state class (parameters, moments, RNG, sampler) whether it reshards, reseeds or recomputes.

Only when you can do this without notes.

Leads to

Notes

Resources · 4 for this unit, 9 more in the section
  • PyTorch Distributed Checkpoint RecipesPyTorch · required

    Complete the distributed checkpoint recipe with a tiny sharded model on CPU, then dcp.async_save from the 2.14 reference at https://docs.pytorch.org/docs/2.14/distributed.checkpoint.html. The recipe saves model and optimizer only: add scheduler, scaler, RNG and dataloader state yourself, then inject partial directories, missing shards and a changed world-size restore.

  • Picotron - Checkpoint StateHugging Face · support

    Inspect picotron/checkpoint.py and every call site in train.py. List which state is saved, how ranks participate and which DT-1 reproducibility requirements need to be added in your project.

  • Nanotron - Distributed SerializationHugging Face · support

    Read the serialization section of docs/docs.md (metadata, per-rank optimizer and RNG shards) and its statement that checkpoints are not topology agnostic, then the reasons in src/nanotron/serialize/. Use it as the worked example of why resharding is hard.

  • TorchTitan - CheckpointingPyTorch · support

    Read docs/checkpoint.md and the checkpointer component at a pinned commit: intervals, model-only and export saves, asynchronous modes and keys excluded from loading.

Also in this section

  • Machine Learning Systems Volume II - Chapter 7 Fault ToleranceML Systems Textbook · primary

    Read Failure Analysis at Scale, Hardware Fault Taxonomy, Check-and-Verify, Fault Injection Tools and Frameworks, Checkpointing, Failure Detection and Recovery, Elastic Recovery and Distributed Debugging and Observability. Turn them into a failure matrix before implementing the PyTorch DCP lab.

  • TorchFeather - Distributed Checkpoint ManagerTorchFeather · required

    Trace components/checkpoint.py through state wrappers, DCP save and load, asynchronous mode, retention and cleanup. Write a failure table for every barrier, future, temporary artifact and deletion boundary.

  • Machine Learning Engineering Open Book - Checkpoints, Storage and Fault ToleranceStas Bekman · required

    Read training/fault-tolerance/README.md (frequent checkpoints, kill and save switches, watchdogs, preemption) and the "Don't forget the checksums" and benchmark sections of storage/README.md. Turn them into an operational save, verify, publish, retain and recover runbook.

  • Distributed Training Guide - Sharded Checkpoints, Determinism and Elastic TrainingLambda Labs · required

    Run related-topics/elastic-training/toy.py with two CPU processes (hide any GPU so it uses Gloo) to see a crash-and-restart loop, then read the determinism related topic and the Chapter 4 sharded save and load. Prove the same next batches and updates after one interrupted run.

  • PyTorch Elastic Run DocumentationPyTorch · support

    Use failure modes and membership changes to understand agent, worker group, rendezvous and restart semantics. Implement only bounded local restart tests; elasticity is not a substitute for checkpoint correctness.

  • torchftPyTorch · support

    Read the README and train_ddp.py: per-step quorum through the lighthouse, fault-tolerant DDP and HSDP, and live peer recovery. Compare per-step healing with restart-from-checkpoint.

  • The Llama 3 Herd of Models - Reliability and Operational ChallengesLlama Team, Meta (2024) · support

    Read the reliability section and its interruption table (root causes of unexpected interruptions over a 54-day snapshot) and use it to set failure rates in your checkpoint-interval model.

  • Bumblebee - DCP and Checkpoint Smoke TestsBumblebee · depth

    Only as a possible capstone target: read primitive/ckpt/dcp.py and the checkpoint smoke tests in a clean checkout. Its own roadmap lists reshardable optimizer state as a gap.

  • OLMo-core CheckpointerAi2 · support

    Read src/olmo_core/train/checkpoint.py (_temporary_wd, _get_tmp_dir, _teardown_tmp_dir, _save_metadata) for temp-directory atomic publish with barrier discipline, and src/test/train/checkpoint_test.py (run_checkpointer) for the save, find and reload assertions.