Skip to content

refactor(fsdp): sleep/wake module, CPU-offloaded models stay put, frozen models reuse host copies - #267

Merged
Rockdu merged 3 commits into
fsdp-followups/2-nft-alignmentfrom
fsdp-followups/3-offload-perf
Oct 4, 2026
Merged

Rockdu merged 3 commits into
fsdp-followups/2-nft-alignmentfrom
fsdp-followups/3-offload-perf

Conversation

@Rockdu

@Rockdu Rockdu commented Sep 27, 2026 •

Copy link
Copy Markdown
Collaborator

Stack 3/9 of follow-ups to #263: main ← #265 ← #266 ← this ← #268 ← #269 ← #271 ← #272 ← #273 ← #274.

What

  • refactor(fsdp): leave natively CPU-offloaded models out of sleep and wake: as in miles, a model under FSDP's CPUOffloadPolicy never sleeps; its parameter shards stay on the host and its buffers on the GPU. This drops the keep_parameters_on_cpu special case.
  • refactor(fsdp): replace offload_model and onload_model with move_model in sleep_wake.py: one move_model(model, device) next to move_optimizer, in a module named after the trainer's sleep/wake phases (offload/onload stays the rollout's vocabulary). Rename only.
  • perf(fsdp): reuse frozen models' pinned host copies ...: frozen reference and teacher models get wake_up_frozen_model / sleep_frozen_model. Waking keeps each parameter's pinned host copy, and sleeping points the parameters back at it instead of copying unchanged weights device-to-host again. Buffers are still copied, since a forward may update them.

Why

Reference and teacher weights never change after load, so the per-sleep device-to-host copy is pure overhead. Pinned host memory should not grow, because the caching host allocator already kept those blocks between phases (not measured).

Validation

OCR GRPO benchmark (SD3.5-M LoRA, KL 0.04 via lora_base, 2×H200, 6 rollouts, steady-state means excluding the first step), main vs #263:

main #263
actor_train 70.20 s 70.34 s
sleep 2.77 s 1.55 s
wake_up 0.94 s 0.22 s
sglang release (steady state) 0.53 s 0.53 s

The per-microbatch lora_base reshard costs ~0.14 s per step and sglang release is unchanged, so neither is changed here. That recipe has no independent reference or teacher; this PR's path is covered by the GPU offload worker, which checks that a frozen model's second sleep keeps the same host storage.

Files

  • miles/backends/fsdp_utils/sleep_wake.py (was offload.py): move_model, move_optimizer; wake_up_frozen_model / sleep_frozen_model in their own section.
  • miles/backends/fsdp_utils/actor.py, model_loader.py: which models sleep; frozen models sleep and wake through the frozen functions, each with its own frozen_parameter_host_copies.
  • tests/fast-gpu/backends/fsdp_utils/{test_sleep_wake,_sleep_wake_worker}.py (were test_offload / _offload_worker): natively CPU-offloaded models only move their optimizer and EMA; a frozen model's sleep keeps each evenly sharded parameter's host storage.
  • docs/fsdp_model_roles.md: sleep/wake wording and test paths.

Checklist

  • pre-commit run --all-files passes — not run locally
  • Added/updated tests for new behaviour
  • pytest -x is green — GPU worker runs in CI only
  • If launch flags changed, python3 train.py --help still parses — n/a
  • If a public flag was added, it appears in the CLI reference docs — n/a
  • If an example was added, it has a real walkthrough — n/a

@Rockdu Rockdu added the run-ci-basic Authorize and run only basic unlabeled CI tests label Sep 27, 2026
@Rockdu
Rockdu force-pushed the fsdp-followups/3-offload-perf branch from 3329630 to b9e4531 Compare September 27, 2026 11:07
@Rockdu
Rockdu force-pushed the fsdp-followups/3-offload-perf branch 2 times, most recently from 83d1cf3 to 6ecf518 Compare September 27, 2026 11:26
@Rockdu
Rockdu force-pushed the fsdp-followups/3-offload-perf branch from 6ecf518 to ebae691 Compare September 27, 2026 13:06
@Rockdu
Rockdu added this pull request to stack #270 September 27, 2026 17:59
@Rockdu
Rockdu force-pushed the fsdp-followups/3-offload-perf branch 3 times, most recently from 0b206a9 to a05d4e6 Compare September 27, 2026 18:29
@Rockdu Rockdu changed the title perf(offload): reuse frozen models' pinned host copies across sleeps perf(offload): release frozen models onto their pinned host copies Sep 27, 2026
@Rockdu
Rockdu force-pushed the fsdp-followups/3-offload-perf branch from a05d4e6 to 9db1f3d Compare September 27, 2026 19:09
@Rockdu Rockdu changed the title perf(offload): release frozen models onto their pinned host copies perf(offload): move_model plus sleep and wake for frozen models Sep 27, 2026
@Rockdu
Rockdu force-pushed the fsdp-followups/3-offload-perf branch from 9db1f3d to 7f6bf43 Compare September 27, 2026 19:39
@Rockdu Rockdu changed the title perf(offload): move_model plus sleep and wake for frozen models refactor(fsdp): sleep/wake module, CPU-offloaded models stay put, frozen models reuse host copies Sep 27, 2026
@Rockdu Rockdu mentioned this pull request Sep 28, 2026
1 of 6 tasks

@zhihengy zhihengy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Rockdu
Rockdu merged commit a02a704 into main Oct 4, 2026
34 of 36 checks passed
OnePunchMonk pushed a commit to OnePunchMonk/miles_diffusion that referenced this pull request Oct 5, 2026
…zen models reuse host copies (radixark#267)

* refactor(fsdp): leave natively CPU-offloaded models out of sleep and wake

* refactor(fsdp): replace offload_model and onload_model with move_model in sleep_wake.py

* perf(fsdp): reuse frozen models' pinned host copies instead of copying them back on every sleep
OnePunchMonk pushed a commit to OnePunchMonk/miles_diffusion that referenced this pull request Oct 5, 2026
OnePunchMonk pushed a commit to OnePunchMonk/miles_diffusion that referenced this pull request Oct 5, 2026
…zen models reuse host copies (radixark#267)

* refactor(fsdp): leave natively CPU-offloaded models out of sleep and wake

* refactor(fsdp): replace offload_model and onload_model with move_model in sleep_wake.py

* perf(fsdp): reuse frozen models' pinned host copies instead of copying them back on every sleep
@Rockdu Rockdu mentioned this pull request Oct 5, 2026
4 of 6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-ci-basic Authorize and run only basic unlabeled CI tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants