Skip to content

[DMD2 8/10] perf(ray): sleep each trainer group right after its train - #342

Merged
Rockdu merged 1 commit into
mainfrom
dmd2/05b-sleep-after-train
Nov 11, 2026
Merged

Rockdu merged 1 commit into
mainfrom
dmd2/05b-sleep-after-train

Conversation

@zhihengy

@zhihengy zhihengy commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

Eighth of the DMD2 stacked series, on top of #334. With --offload-train, the sync driver now puts each trainer group to sleep right after its train, before the next group wakes, instead of keeping every group on the GPUs until all of them have trained. A DMD2 critic group no longer holds the critic, its optimizer and the teacher on the GPUs while the actor trains.

What

  • train_diffusion.py: per rollout, each group trains, saves (on save rollouts) and then sleeps (--offload-train) or clears its memory, in declared order. The save and offload_train helpers stay, now taking the group; the rollout manager's save runs once after the loop, as before.
  • A group's train outputs are Ray objects by the time it sleeps, so later groups still receive them as external_data.
  • With one trainer group the order is unchanged: train, save, sleep, then weight sync.

Why

  • Peak trainer memory under DMD2. The critic group (trainable critic + its optimizer + frozen teacher, 16 + 4 bytes per parameter with fp32 master weights and Adam) stayed awake through the actor's train (16 bytes per parameter), so the actor step peaked at 36 bytes per parameter. Sleeping the critic first brings the peak to 20. For a 33B DiT (MiniMax H3) on 16 GPUs that is ~74.5 GB per GPU of model and optimizer state down to ~41 GB, before activations.
  • Host-device traffic per rollout is unchanged: every group already slept and woke once per rollout, only the critic's sleep moves earlier.
  • Upstream precedent: miles' train.py offloads the critic right after critic_model.train(...) and before actor_model.train(..., external_data=values), under --offload-train. Upstream saves after both trains and wakes each model to save it (save_training_model: onload, save, offload). Here each group saves before it sleeps instead, which avoids that extra wake on save rollouts and keeps the single-group order as it was.

Tests

Checklist

  • pre-commit hooks (black, isort, ruff at the pinned versions) pass on the changed files
  • Added/updated tests for new behaviour (per-group save and sleep order, single group unchanged)
  • pytest tests/fast: 562 passed, 7 skipped; 4 tests fail in this environment and fail the same way on [DMD2 7/10] feat(dmd2): train the student with the distribution matching gradient from the critic group's scores #334 (test_hybrid_shard_mesh::test_mesh_axes and test_metric_buffer_dist::test_metric_buffer_reduction, whose torchrun children import another checkout, and two test_sft_h3_ref2va_encoder cases)
  • If launch flags changed, python3 train_diffusion.py --help still parses (no flags changed)
  • If a public flag was added, it appears in the CLI reference docs (no flags added)
  • If an example was added, it has a real walkthrough (no examples added)

Stack

DMD2: distill a flow-matching teacher into a few-step student with distribution matching. Merge in order:

  1. [DMD2 1/10] [DMD2 1/10] refactor(ray): build each trainer's args from a trainer config list #335: per-trainer args from a trainer config list
  2. [DMD2 2/10] [DMD2 2/10] feat(ray): train several colocated trainer groups in the sync driver #329: several colocated trainer groups in the sync driver
  3. [DMD2 3/10] [DMD2 3/10] feat(ray): hand earlier trainer groups' outputs to later groups as external_data #330: hand earlier trainer groups' outputs to later groups as external_data
  4. [DMD2 4/10] [DMD2 4/10] feat(fsdp): add a train-input hook that preprocesses train pairs before micro-batching #338: a train-input hook that preprocesses a trainer group's train pairs before micro-batching
  5. [DMD2 5/10] [DMD2 5/10] feat(rollout): stop the rollout at a random step for DMD2 backward simulation #331: few-step rollout and the DMD2 step strategy (needs [Feat] diffusion-rl: stop a rollout at a requested step sgl-project/sglang#45230)
  6. [DMD2 6/10] [DMD2 6/10] feat(dmd2): train a fake-score critic group from the teacher and score the student's samples #333: DMD2 critic group: critic training and teacher/critic scoring of its last step
  7. [DMD2 7/10] [DMD2 7/10] feat(dmd2): train the student with the distribution matching gradient from the critic group's scores #334: --loss-type dmd2 on the actor
  8. [DMD2 8/10] this PR: sleep each trainer group right after its train
  9. [DMD2 9/10] [DMD2 9/10] feat(dmd2): add the MiniMax H3 4-step DMD2 recipe with eval media and DMD2 metrics #343: MiniMax H3 4-step DMD2 recipe, eval media and DMD2 metrics

A GAN head and other follow-ups come after this series.

@zhihengy zhihengy changed the title [DMD2 8/9] perf(ray): sleep each trainer group right after its train [DMD2 8/10] perf(ray): sleep each trainer group right after its train Nov 2, 2026
@zhihengy
zhihengy added this pull request to stack #339 November 2, 2026 10:06
@Rockdu
Rockdu force-pushed the dmd2/05b-sleep-after-train branch from f5aa744 to cfd5368 Compare November 4, 2026 19:41
@zhihengy
zhihengy force-pushed the dmd2/05b-sleep-after-train branch 2 times, most recently from e804eea to 41b4957 Compare November 10, 2026 03:59
@zhihengy
zhihengy force-pushed the dmd2/05b-sleep-after-train branch from 41b4957 to 2d35bc1 Compare November 10, 2026 11:44
@zhihengy
zhihengy marked this pull request as ready for review November 10, 2026 13:19

@Rockdu Rockdu 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

@zhihengy
zhihengy requested a review from guapisolo as a code owner November 11, 2026 08:18
@zhihengy
zhihengy force-pushed the dmd2/05b-sleep-after-train branch from 2d35bc1 to 55a681e Compare November 11, 2026 08:18
@Rockdu
Rockdu force-pushed the dmd2/05b-sleep-after-train branch 4 times, most recently from 26ceca3 to c4769e2 Compare November 11, 2026 15:44
Base automatically changed from dmd2/05-dmd2-loss to main November 11, 2026 15:44
@Rockdu
Rockdu force-pushed the dmd2/05b-sleep-after-train branch from c4769e2 to 9470b60 Compare November 11, 2026 15:44
@Rockdu
Rockdu merged commit 8a96fee into main Nov 11, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants