Unit 7 of 12 · about 5 hours · measure
Activation checkpointing under FSDP and CPU and storage offload
Build on Activation checkpointing and recomputation. At distributed depth, recompute can cross gather boundaries, while offload moves pressure onto another memory tier rather than removing it.
You'll be able to
- Measure recomputation and collective events when activation checkpointing is composed with FSDP groups.
- Account for host memory, transfer traffic and CPU optimizer work under model-state offload.
- Compare selective checkpointing, wrap boundaries and selective offload under a stated memory budget.
Covers
Read
In this order, only the parts listed
0 of 3 done
- Activation-checkpoint placement and selective policiesTorchFeather - FSDP and Activation Checkpointing
_apply_full_ac,_apply_layer_sac,_apply_op_sacandapply_ac; thenparallelize_deepseekv3intorchfeather/model/parallelize.pyat the same commitRead the policy functions and checkpoint-before-FSDP call order only. Do not adopt the private compiler controls or the full framework. Open the second file at https://github.com/hkproj/torchfeather/blob/c416ab1ad0fd3567a0a6c8ad0da570c8fd6e55aa/torchfeather/model/parallelize.py.
- CPU offload in PyTorch 2.14PyTorch FSDP2 Tutorial (fully_shard)
CPUOffloadPolicy, includingpin_memory;fully_shardparameteroffload_policy - CPU versus storage offload vocabularyDeepSpeed ZeRO Tutorial
Offloading to CPU and NVMe with ZeRO-Infinity (page read 2026-10-14)
Read the tier and state-category distinction. Do not run the large-model scripts or port DeepSpeed's configuration keys into FSDP2.
Focus on
- Checkpoint placement relative to the FSDP group decides whether recomputation re-enters gather hooks. Count actual all-gathers rather than assuming every checkpoint adds one or that recomputation is communication-free.
- TorchFeather's checkpoint policies use
preserve_rng_state=False. For a stochastic block, use preserved RNG state in your baseline and test the recomputed gradient; the source's choice is not safe for arbitrary dropout. - FSDP2 CPU offload keeps parameter and gradient shards and optimizer state on CPU. Copy shards to the training device before gathering, copy reduced gradients back, and run the optimizer on CPU. The gathered weights of the active group and its activations must still fit on the training device.
- NVMe adds a storage-to-host tier and staging buffers;
CPUOffloadPolicydoes not implement it. Use a deterministic tiered-transfer model on CPU first. With two or more GPUs, measure checkpoint and per-group CPU-offload variants with host traffic, memory peaks and fixed-workload step times.
Common mistakes · 3
- Assuming offload removes the full-layer working set. It can lower total device peak while leaving that gathered-layer requirement unchanged.
- Treating pinned host memory as free. It is a constrained resource shared with input loading and checkpoint staging.
- Selecting every group for offload without comparing recomputation or narrower wrap boundaries. Added transfers and CPU optimizer work can dominate.
Try it yourself
Closed-book, before checking anything
Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.Does activation checkpointing reduce persistent Adam moments?Answer
No. It changes saved activations and recomputation. Sharding or offload changes optimizer-state ownership or placement.
2.Can CPU offload lower peak GPU memory even though the largest full layer is unchanged?Answer
Yes. Removing resident model-state shards leaves more room for that layer and activations. It does not make an individually oversized compute group fit by itself.
3.Why can a checkpointed stochastic block give the wrong gradient?Answer
If recomputation uses different random draws, it differentiates a different realization. Preserve the needed RNG state or implement a tested equivalent RNG contract.
4.What extra costs appear with storage offload compared with CPU offload?Answer
Storage reads and writes, storage latency, host staging capacity and another transfer dependency. Their cost depends on the actual access and reuse schedule.
You're done when
Your comparison preserves gradient correctness, explains the observed recompute and gather counts, and includes both memory saved and traffic added for each offloaded tier.
Only when you can do this without notes.
Leads to
Notes
Resources · 3 for this unit, 8 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. - 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. - 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.
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. - 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. - 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.