[fsdp] FSDP2 weight export gathers per-parameter; batching via FSDPModule.unshard() could cut the export cost further
Context
get_per_tensor_param exports FSDP2 weights with a per-parameter .to(device).full_tensor() — one independent all-gather per parameter (~340 for a 7B model), plus one pageable H2D per parameter when the model is CPU-offloaded.
With the staging round trip in place this cost is invisible (the shards are already GPU-resident; we profiled the whole per-param gather loop at 0.1–0.25 s). After #7005 skips the staging for FSDP2, the lazy path pays ~2.4–2.7 s per sync in the export generator on a 2-node disaggregated Qwen2.5-7B run (8-GPU FSDP2 trainer, param+optimizer offload) — now the largest remaining chunk of the full-weight sync (~3.4 s total).
Proposal
Batch the export instead of going parameter-by-parameter. Two candidate shapes:
FSDPModule.unshard()per fully_shard unit (usually one transformer layer): the same fused foreach all-gather the forward pre-hooks use — ~30 large collectives instead of ~340 small ones, with bounded memory (one layer materialized at a time) and FSDP-managed staging for offloaded params. Requires walking the fully_shard units, reconstructing FQNs, and managing the unshard→read→reshard lifecycle.- Manual batching: concatenate the local shards of K same-layout parameters (FSDP2 params share the mesh and
Shard(0)placement), oneall_gather_into_tensor, slice per parameter afterwards.
One caveat worth profiling first: in the offloaded no-staging regime, part of the ~2.5 s is per-parameter pageable H2D (driver-staged, blocking) rather than all-gather latency. Option 1 addresses both (fused transfer + gather); option 2 addresses the collective count only, so the H2D side would additionally want pinned/bulk staging.
Reference data
| configuration (7B, 2×8 GPUs, offload, same node pair) | per-step weight sync |
|---|---|
| nccl, staging (current) | 6.8–7.0 s |
| nccl, staging skipped (#7005) | 3.4–4.1 s |
| — of which export generator pull | 2.4–2.7 s |
Happy to share the profiling harness/methodology from #6974 (per-phase decomposition of export/gather/pack/broadcast on both sender and receiver).
Hi, are you already working on this? @ChangyiYang
I'd like to work on the first candidate and open my first PR to verl with profiling data, if you are not working on it.
@BeatSeat I made a pure vibed demo but never formally work on it. Feel free to give it a try
Hi @ChangyiYang @BeatSeat — it’s been a while since the last update here. I’m preparing a clean two-node Qwen2.5-7B FSDP2/SGLang reproduction on 8×H200 per node, starting with current-main profiling of export versus transport.
Before going further, may I ask whether either of you is actively working on candidate 1? I don’t want to duplicate anyone’s effort. If there is an existing branch or preferred direction, I’d be grateful for a pointer. Otherwise, I’d be happy to contribute reproduction, profiling, or correctness coverage first. Thanks!