You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(profiler): reject FSDP profiler configs that crash on swap-based CPU offload
The FSDP2 manual CPU-offload path moves models with model.to("cpu") ->
nn.Module._apply -> torch.utils.swap_tensors, which raises
"RuntimeError: _apply(): Couldn't swap <param>" while torch.profiler holds
weakrefs to those params during an active window (reproduced on CPU with
torch 2.12). That offload only fires mid-loop under colocation.
Map of the crash precondition (all required):
- strategy == "fsdp" (Megatron offloads via flat-buffer/.data reassignment,
never swap_tensors -> immune)
- fsdp_config.cpu_offload == False (the default "manual" path; cpu_offload=True
uses FSDP2-native offload, no manual swap)
- colocate_all OR colocate_policy_ref (otherwise no in-loop offload happens)
SFT is single-model and hardcodes colocate_all=False -> never at risk.
Enforce via TorchProfilerConfig.validate(): the RL validator (validate_cfg) now
passes strategy/colocation/cpu_offload context so an incompatible config fails
fast at startup with an actionable message (set cpu_offload=true, disable
colocation, or use Megatron). SFT calls validate() with no context so the
cross-field check is skipped. Added unit + end-to-end tests and documented the
restriction in config.mdx.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: docs/content/docs/configuration/config.mdx
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -306,6 +306,8 @@ policy:
306
306
307
307
**Scope:** the profiler captures **only the policy model's training step** (forward/backward + optimizer). In an RL run it does **not** profile the critic or reference models, and it does **not** profile generation/inference — only policy training compute on the configured `ranks`.
308
308
309
+
**FSDP + colocation restriction:** on the FSDP backend, the default CPU-offload path moves models to CPU with `torch.utils.swap_tensors`, which crashes mid-run (`RuntimeError: _apply(): Couldn't swap <param>`) when the profiler holds references to those parameters. That offload only happens under colocation, so `validate_cfg`**rejects at startup** the combination of `enable: true` + `trainer.strategy=fsdp` + `policy.fsdp_config.cpu_offload: false` (default) + colocation (`placement.colocate_all: true`*or*`placement.colocate_policy_ref: true`). To profile FSDP, either set `policy.fsdp_config.cpu_offload: true` (FSDP2-native offload, no swap) or disable colocation. The **Megatron** backend offloads via a different mechanism and is unaffected.
310
+
309
311
Which steps are recorded is controlled entirely by [`torch.profiler.schedule`](https://docs.pytorch.org/docs/stable/profiler.html#torch.profiler.schedule): the profiler skips the first `skip_first` steps, then repeats a cycle of `wait` (idle) + `warmup` (tracing discarded) + `active` (tracing recorded) steps `repeat` times (`repeat: 0` profiles every cycle for the whole run). This is how you profile multiple steps, at an interval, repeating.
310
312
311
313
-`policy.torch_profiler_config.enable`: Master switch. When `false` (default), no profiler RPCs are dispatched and there is zero overhead.
0 commit comments