Skip to content

test(sc): add the distillation recipe and functional test for SingleController - #3849

Closed
tianyi-zhang-02 wants to merge 21 commits into
NVIDIA-NeMo:mainfrom
tianyi-zhang-02:feat-sc-distillation-recipe
Closed

tianyi-zhang-02 wants to merge 21 commits into
NVIDIA-NeMo:mainfrom
tianyi-zhang-02:feat-sc-distillation-recipe

Conversation

@tianyi-zhang-02

@tianyi-zhang-02 tianyi-zhang-02 commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds the native SingleController distillation recipe and its checkpoint/restore functional test. Relative to #3846, this PR is test-only:

  • one 2-GPU Megatron + vLLM recipe;
  • one functional script that trains steps 1–2, checks policy/metadata/TransferQueue checkpoints, restores, and finishes steps 3–4;
  • config and recipe tests that fail before model loading if the shell overrides or SC constraints drift;
  • L1 suite registration.

This is the top of #3843 → #3846 → #3849. GitHub compares it to main, but its unique delta from #3846 is exactly five test/recipe files (408 added lines).

Ownership

The lower stack's teacher top-k primitive overlaps #2580. The duplicate is disclosed on both sides; #2580 remains open and conflicting, with no author response since August 27. This PR adds coverage only and does not extend the overlapping production surface.

Validation

  • Head: 50ca2117216b1c9bb689d8638354f192b13f6529
  • Parent feat(sc): run the distillation teacher in the SingleController train pump #3846: 80966321d71eb204c42d3b51a322640c2f1964a6
  • Merged main: e831622435180c88d6adcc9fce46bfd88a85f3e5
  • Current head, Linux x86_64, Python 3.13.14, CUDA disabled: both functional shell scripts pass bash -n; 21 passed across functional-config, teacher-stage, field-schema, validation, and shipped-recipe tests.
  • Ruff check and format: clean.

The full functional script previously passed on a Runpod 4×H100 80 GB host using 2 GPUs at pre-refresh head 90760604:

  • run 1 trained steps 1–2 and wrote metadata, data-plane, and policy checkpoints;
  • run 2 restored step 2 and completed steps 3–4;
  • losses: 0.387430, 0.479430, 0.405156, 0.432410;
  • both metric files passed the loss-count, finite/non-negative, < 20, and teacher-timing gates.

That H100 result is historical evidence for the unchanged functional path; it has not been rerun after the current main refresh.

@tianyi-zhang-02
tianyi-zhang-02 requested review from a team as code owners August 26, 2026 16:55
@copy-pr-bot

copy-pr-bot Bot commented Aug 26, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@tianyi-zhang-02

tianyi-zhang-02 commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Update: the 2-GPU functional test has now run successfully on the current stack.

  • live head: 907606048aa8c950027dbc199bff1495035e862c
  • host: Runpod 4×H100 80 GB; test used 2 GPUs
  • run 1 trained steps 1–2 and wrote metadata, data-plane, and policy checkpoints
  • run 2 restored step 2 and completed steps 3–4
  • losses: 0.387430, 0.479430, 0.405156, 0.432410
  • unit/config sweep: 765 passed, 6 GPU-only skips

The exact configuration, metric gates, and ownership hold are in the updated PR body.

@tianyi-zhang-02
tianyi-zhang-02 force-pushed the feat-sc-distillation-recipe branch from 924331d to ef76ccb Compare August 26, 2026 18:16
…troller

Distillation is the last algorithm with a rollout loop that SingleController
cannot run. Its teacher is a Policy, not a separate model class, so the
SingleController side needs no new driver -- only the missing top-k
entrypoint on the two layers every other forward already has:

  - TQWorkerMixin.get_topk_logits_presharded: per-rank fetch -> forward ->
    write-back. Unlike its siblings it writes back two tensors, and both
    carry a third axis ([B, S, k]); the write-back validates only the batch
    dimension, so that axis passes through unchanged.
  - TQPolicy.get_topk_logits_from_meta: the 1-hop dispatch, reusing
    LP_SEED_FIELDS because a teacher forward needs exactly what a logprob
    forward needs.

Nothing calls these yet -- wiring the teacher into the train pump is a
follow-up. Splitting it out keeps this piece independently testable.

Signed-off-by: Tianyi Zhang <[email protected]>
Signed-off-by: Tianyi Zhang <[email protected]>
…pump

Builds on the teacher top-k forward and makes SingleController able to run
a distillation step end to end.

Distillation turns out to fit the existing shape almost exactly. Its
teacher is a Policy, so it is a second TQPolicy rather than a class of its
own, built and parked exactly the way the PPO critic is -- serially, with
the trainer offloaded, because both worker groups sit on the training GPUs.

What is different is the batch. DistillationLossFn reads only the sequence
columns and the teacher's top-k: no importance ratio, no reference KL, no
advantages. So the train pump skips both logprob forwards and the whole
advantage stage, and the fetched column set is narrowed accordingly --
DP_TRAIN_FIELDS names advantages and the logprob columns, and fetching a
column nobody wrote errors out rather than reading zeros. That narrowing
needs train_microbatches_from_meta to take the train_fields argument
train_from_meta already had.

MasterConfig now admits a third algorithm block, still exactly one at a
time, and a `teacher` block is required by distillation and rejected on
every other path -- a teacher nobody reads is the same silent no-op this
path already rejects unsupported algorithm knobs for.

The recipe and the functional test are a follow-up.

Signed-off-by: Tianyi Zhang <[email protected]>
Signed-off-by: Tianyi Zhang <[email protected]>
Two things a distillation run hits before any model loads.

The legacy-async check read `config.grpo.async_grpo` on everything that was
not PPO. `grpo` is None on a distillation run, so the launcher died with an
AttributeError. DistillationConfig has no legacy async block at all --
distillation never had a v1 async path -- so there is nothing to reject.

And the teacher's vocabulary is now checked against the student's. The
teacher writes top-k *indices*, which the loss reads back as student
vocabulary ids: a teacher on a different vocabulary produces indices that
are silently wrong rather than an error. distillation.py already runs this
check; SC skipped it. Same helper, same NRL_SKIP_DISTILLATION_TOKENIZER_CHECK
opt-out, and it runs before the first model load so a mismatch costs
seconds instead of a full spin-up.

Signed-off-by: Tianyi Zhang <[email protected]>
Signed-off-by: Tianyi Zhang <[email protected]>
@tianyi-zhang-02

Copy link
Copy Markdown
Contributor Author

Heads-up on merge order, with the resolution written out.

Four of my open PRs edit the same twelve-line block — the unsupported knob list in _validate_algo_settings:

I checked every pair by actually merging them. #3786 × #3787 is clean now — they only ever conflicted on the comment wording and on both adding a test before the same anchor, and both are fixed. The remaining four pairs are a genuine textual conflict on that block, and no restructuring avoids it: extracting or reordering the list conflicts just as hard.

So rather than force a stack, here is the resolution. Whichever order they land in, this is the merged form:

    # An enabled one here describes shaping this run does not do. An entry
    # leaves this list when the SC path starts implementing it -- rejecting a
    # knob is only right while nobody honours it.
    #
    # DistillationConfig defines none of them: there is no reward to shape or
    # filter on, so the list cannot even be evaluated on that path.
    unsupported = (
        []
        if is_distillation_run(master_config)
        else [
            name
            for name, enabled in (
                ("use_dynamic_sampling", algo_cfg.use_dynamic_sampling),
                ("reward_scaling", algo_cfg.reward_scaling.enabled),
                ("reward_shaping", algo_cfg.reward_shaping.enabled),
            )
            if enabled
        ]
    )

I built that merge locally and ran the SC and config suites against it — 1084 passed. Happy to rebase whichever ones are left once the first lands; just say which order you want.

The guard used to wrap that list in a conditional, which put this PR on the
same twelve lines as NVIDIA-NeMo#3786 and NVIDIA-NeMo#3787 -- each of those removes an entry from
it. Four pairwise conflicts on nothing but placement.

Returns early instead. DistillationConfig defines none of the knobs the list
names, so the check does not apply and the comprehension could not be
evaluated anyway; everything after it is PPO-specific and returns early on
this path already. The colocated requirement is the one thing that does
apply, so it moves into a helper and the guard calls it directly rather than
falling through.

The list itself is now untouched by this PR, so all four conflicts go away
and none of the three needs to land before the others.

Signed-off-by: Tianyi Zhang <[email protected]>
Signed-off-by: Tianyi Zhang <[email protected]>
@tianyi-zhang-02
tianyi-zhang-02 force-pushed the feat-sc-distillation-recipe branch from d5a76c8 to 364f5c4 Compare August 26, 2026 22:43
…ontroller

Gives the SC distillation path something to run.

The recipe is the SingleController variant of distillation_math_megatron.yaml,
in the same shape as the GRPO and PPO SC exemplars. Three things had to be
spelled out rather than inherited: validation off, since SC has no validation
loop; a data_plane block, since distillation has only ever run on the legacy
path and its parent has none; and a single-GPU teacher shape, since the parent
shards the teacher across eight.

The functional test mirrors distillation_megatron.sh on the same model pair,
run through run_grpo_single_controller.py, with checkpoint/restore across two
runs like the SC PPO test. It asserts on "Teacher init:" and on the absence
of "Value init:" -- the teacher and the critic are mutually exclusive, and
asserting only the presence of one would not catch building both.

Also sets teacher_init_time_s, which setup was measuring and dropping.

I cannot run this test: it needs two GPUs and I have one. What I did verify
is that the config resolves, that MasterConfig accepts it, that
validate_single_controller_config passes it, and that it survives the
repo-wide config sweep in tests/unit/test_config_validation.py. Someone with
the hardware should run the functional test before this merges.

Signed-off-by: Tianyi Zhang <[email protected]>
Signed-off-by: Tianyi Zhang <[email protected]>
Found by trying to launch the recipe rather than only validating it.
MasterConfig accepted the config, but three keys the distillation chain has
never carried are read with [] rather than .get() further down -- and each is
NotRequired on its config type, so pydantic passes it and the run dies later:

  - policy.draft.enabled, read by the launcher before generation is configured
  - data.use_multiple_dataloader and data.num_workers, read by SC's setup
    while building the dataloader; the legacy distillation loop builds its own
    without either, which is why the base config never needed them

Three tests pin the recipe against exactly this: it passes
validate_single_controller_config, it carries those keys, and its loss block
resolves to DistillationLossConfig rather than the other arm of the union.

Signed-off-by: Tianyi Zhang <[email protected]>
Signed-off-by: Tianyi Zhang <[email protected]>
NVIDIA-NeMo#3768 added on_policy_distillation validation that reads
algo_cfg.adv_estimator. DistillationConfig has no such field -- its teacher
signal is the loss, not an advantage -- so a distillation config now dies with
an AttributeError inside the validator.

Reads it defensively and rejects the on_policy_distillation + distillation
pairing explicitly, the same way the PPO pairing is already rejected. The two
are different algorithms that both happen to use a teacher: MOPD routes
per-agent teachers on their own nodes and turns their logprobs into an
advantage, this path colocates one teacher with the trainer and feeds
DistillationLossFn.

Signed-off-by: Tianyi Zhang <[email protected]>
max_buffered_rollouts=6 sits below the in_order sampler's required capacity --
num_prompts_per_step * (max_lookahead_versions + 1) = 4 * 2 = 8 --  so
validate_sampler_buffer_capacity rejects the config and the run dies at setup.

The test needs two GPUs, so nobody would have found that until a two-GPU
runner picked it up. Adds a CPU test that resolves the script's own overrides
through hydra, MasterConfig and validate_single_controller_config, reading them
out of the shell script rather than restating them so the two cannot drift.

Mutation-tested: restoring the 6, enabling colocated generation, and setting a
val: metric_name each turn it red.

Signed-off-by: Tianyi Zhang <[email protected]>
Signed-off-by: Tianyi Zhang <[email protected]>
@tianyi-zhang-02
tianyi-zhang-02 force-pushed the feat-sc-distillation-recipe branch from b4095a5 to c6b9aef Compare August 28, 2026 15:41
run2 resumes at step 2 into its own log dir, so its TensorBoard run holds
the two steps it actually executed. The assertion expected four and would
have failed at the very end, after two complete runs. The sibling
ppo_async_single_controller.sh:104 has the same run1/run2 shape and
already asserts two.

Signed-off-by: Tianyi Zhang <[email protected]>
# Conflicts:
#	nemo_rl/algorithms/single_controller.py
#	nemo_rl/algorithms/single_controller_utils/setup.py
# Conflicts:
#	tests/functional/L1_Functional_Tests_SingleController.sh
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label Aug 29, 2026
tianyi-zhang-02 and others added 10 commits August 28, 2026 21:03
validate_single_controller_config routed distillation around
_validate_algo_settings entirely, to dodge one check inside it -- the
reward shaping and filtering knobs, which DistillationConfig does not
declare, so reading them raises AttributeError.

That dropped three checks that are not about GRPO at all and whose own
comments say so: the max_num_epochs<=0 guard (the rollout pump gates on
it whatever the algorithm), the warmup_lookahead_versions capacity guard
('Capacity is sized from the peak window whatever the algorithm'), and
the value-without-ppo guard. A distillation config setting any of them
was silently accepted where GRPO raises -- the same silently-accepted
no-op this file's shaping check exists to prevent.

Read the four shaping knobs defensively instead, so distillation stays
on the one code path and only the check that cannot apply is skipped.

Signed-off-by: Tianyi Zhang <[email protected]>
Signed-off-by: Tianyi Zhang <[email protected]>

# Conflicts:
#	nemo_rl/algorithms/single_controller.py
Refresh the test-only recipe layer onto the current distillation implementation and main.

Signed-off-by: Tianyi Zhang <[email protected]>
@tianyi-zhang-02

Copy link
Copy Markdown
Contributor Author

Closing this dependent stack item together with #3843/#3846. The active distillation work now has separate ownership and direction in #2580 and the newer distillation series, so I do not want to maintain a competing functional-test layer.

@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-maintainers Waiting on maintainers to respond label Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants