Skip to content

feat(opd): TROPD changes - #4357

Merged
yfw merged 8 commits into
mainfrom
kbhardwaj/tropd-trust-region
Oct 2, 2026
Merged

yfw merged 8 commits into
mainfrom
kbhardwaj/tropd-trust-region

Conversation

@kbhardwaj-nvidia

@kbhardwaj-nvidia kbhardwaj-nvidia commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do ?

Adds the TROPD trust-region teacher to OPD/MOPD advantages on main, working on both run_grpo.py and the SingleController path (run_grpo_single_controller.py). Ports the trust-region part of #4011 from super-v3.5-posttraining. The OPD sample/token/top-k diagnostics from #4011 are not included.

New grpo.adv_estimator settings, both off by default:

  • proximal_teacher_alpha (in (0, 1], default 1.0): the advantage targets a mixture of teacher and student, log π_prox = log(α·π_teacher + (1−α)·π_student), so Â_t = sg[log π_prox − log π_student]. Computed in log space; bounded below by log(1−α). α = 1 is exactly MOPD.
  • subtract_global_baseline (default false): subtracts the mean advantage over the valid tokens in the step. Masked tokens don't count; a fully masked batch returns zeros.

Fixes and wiring:

  • _create_advantage_estimator built OPD with a hard-coded {"name": "opd"}, so estimator settings never reached it. It now passes the validated AdvEstimatorConfig. The SingleController uses the same factory.
  • teacher_student_logprob_gap_mean keeps reporting the raw teacher−student gap; adv_mean/adv_std describe the advantage actually trained on.
  • SingleController: _pooled_opd_metrics reported the mean advantage as the gap. The raw gap is now pooled separately, over the same tokens.
  • SingleController computes advantages once per streaming chunk, so subtract_global_baseline=true requires async_rl.min_groups_for_streaming_train == grpo.num_prompts_per_step (one chunk per step). The checked-in SC MOPD recipe already does this. Other values are rejected at setup instead of silently computing a per-chunk baseline.
  • Full-vocabulary MOPD ignores advantages, so both settings are rejected there.

Commits: (1) proximal-teacher advantage + factory wiring + full-vocab check; (2) global baseline + SC one-chunk-per-step check; (3) raw gap in SC OPD metrics; (4) recipe-level SC test; (5) docs.

Issues

Trust-region part of #4011. Independent of #4347; the two merge cleanly.

Usage

grpo:
  adv_estimator:
    name: opd
    proximal_teacher_alpha: 0.2
    subtract_global_baseline: true
async_rl:  # SingleController, only when subtract_global_baseline is true
  min_groups_for_streaming_train: ${grpo.num_prompts_per_step}

Add grpo.adv_estimator.proximal_teacher_alpha (in (0, 1], default 1.0).
With alpha < 1 the OPD advantage targets a proximal teacher that stays
within a trust region of the student,

    log pi_prox = log(alpha * pi_teacher + (1 - alpha) * pi_student)
    A_t         = sg[log pi_prox - log pi_student]

computed in log space with logaddexp. The advantage is bounded below by
log(1 - alpha); alpha = 1.0 takes the old code path and is exactly MOPD.

_create_advantage_estimator now passes the validated AdvEstimatorConfig to
OPDAdvantageEstimator instead of a hard-coded {"name": "opd"} dict, so the
knob reaches both run_grpo.py and the SingleController, which builds its
estimator through the same factory.

on_policy_distillation/teacher_student_logprob_gap_mean keeps reporting
the raw teacher-student gap; adv_mean/adv_std describe the trained signal.
Full-vocabulary MOPD ignores advantages, so alpha < 1 is rejected there
instead of being silently dropped.

Ported from the super-v3.5-posttraining change in #4011.

Signed-off-by: Khushi Bhardwaj <[email protected]>
Add grpo.adv_estimator.subtract_global_baseline (default false). When set,
OPDAdvantageEstimator subtracts the mean advantage over every valid token
of the batch it is given, after the TROPD interpolation. Masked tokens do
not vote, and an all-masked batch stays finite zero.

run_grpo.py computes advantages once per step, so the baseline is the
step mean. The SingleController runs the advantage stage once per
streaming chunk, which would center each chunk on its own mean instead;
validate_single_controller_config therefore requires
async_rl.min_groups_for_streaming_train == grpo.num_prompts_per_step when
the baseline is on (the checked-in SC MOPD recipe already does this).
Full-vocabulary MOPD ignores advantages and rejects the knob.

Ported from the super-v3.5-posttraining change in #4011.

Signed-off-by: Khushi Bhardwaj <[email protected]>
The SingleController pools OPD metrics across streaming chunks from the
advantages the estimator returns, and logged their mean as both adv_mean
and teacher_student_logprob_gap_mean. That was the same number for plain
MOPD, but with proximal_teacher_alpha < 1 or subtract_global_baseline the
advantage is no longer the gap, so the v2 path reported the wrong metric
and disagreed with run_grpo.py.

Pool sum(teacher_logprobs - prev_logprobs) over the same trained tokens
as the advantage statistics and report its mean as the gap metric.
adv_mean/adv_std are unchanged.

Signed-off-by: Khushi Bhardwaj <[email protected]>
Load the checked-in SingleController MOPD recipe with TROPD overrides,
run validate_single_controller_config, and build the estimator through
the SC setup factory, so the knobs are checked end to end from YAML to
the OPDAdvantageEstimator the controller uses.

Signed-off-by: Khushi Bhardwaj <[email protected]>
Describe proximal_teacher_alpha and subtract_global_baseline, what the
OPD gap and advantage metrics report under them, the SingleController
one-chunk-per-step requirement for the global baseline, and the
full-vocabulary MOPD restriction.

Signed-off-by: Khushi Bhardwaj <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Sep 30, 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.

@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Sep 30, 2026
@kbhardwaj-nvidia kbhardwaj-nvidia changed the title Kbhardwaj/tropd trust region feat(opd): TROPD changes Sep 30, 2026
@kbhardwaj-nvidia
kbhardwaj-nvidia marked this pull request as ready for review September 30, 2026 18:07

@yfw yfw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the port. The validated AdvEstimatorConfig now goes through the one shared factory, so a single edit reaches both runtimes. At the default knobs, the checked-in MOPD recipes produce bitwise-identical advantages and metrics.

Verified at 743c651, which merges cleanly into current main:

  • tests/unit/single_controller/ (1053) and tests/unit/algorithms/ pass, with no failures at head or at the merge base.
  • pre-commit and pyrefly are clean.

Optional follow-up, not for this PR: the OPD step metrics are defined twice, in OPDAdvantageEstimator._compute_metrics (legacy) and in _advantage_stage + _pooled_opd_metrics (SC). The two have already drifted twice. The first drift is the gap metric, which this PR fixes. The second is adv_mean/adv_std: SC pools them after message-level penalties, while legacy logs them before. A small shared sums type would give them one definition.

Generated by Claude Code

Comment thread docs/about/algorithms/mopd.md Resolved
assert_trust_region_supported only ran in the shared estimator factory,
which the SingleController calls after it has built the clusters, the
teachers, the trainer and generation. A full-vocab MOPD config with a
TROPD knob therefore passed validate_single_controller_config and was
rejected only once every worker was up. The legacy entry point never
reaches the factory with full-vocab enabled because setup() already
rejects on_policy_distillation.full there.

Run the guard in validate_single_controller_config next to
assert_prev_logprobs_available, and pin the startup rejection with a
test on the shipped full-vocab recipe.

Signed-off-by: Khushi Bhardwaj <[email protected]>
_make_master_config pins min_groups_for_streaming_train to
num_prompts_per_step, so every other test runs a single chunk and nothing
failed if the check dropped its subtract_global_baseline condition and
rejected every streaming SC MOPD run. Validate the same streaming config
with the baseline off.

Signed-off-by: Khushi Bhardwaj <[email protected]>
adv_mean/adv_std are recorded before grpo.advantage_clip_low/high on
both runtimes (and before message-level penalties on run_grpo.py), so
they are not exactly the advantage that is trained on. Describe them as
the advantage after TROPD and the global baseline, before clipping.

Signed-off-by: Khushi Bhardwaj <[email protected]>
@yfw

yfw commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

/ok to test 06fa41d

@yfw yfw added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Oct 1, 2026
@yfw
yfw enabled auto-merge (squash) October 1, 2026 22:42
@yfw
yfw merged commit f80683e into main Oct 2, 2026
163 of 165 checks passed
@yfw
yfw deleted the kbhardwaj/tropd-trust-region branch October 2, 2026 17:00
arendu added a commit that referenced this pull request Oct 7, 2026
…k capture

Port of super-v3.5-posttraining 7251b00 (#4011), restricted to what main
lacks. TROPD (proximal_teacher_alpha, subtract_global_baseline) is already
on main via #4357 and is NOT re-added; the TROPD hunks of the original were
resolved to main's versions.

Ported:
- nemo_rl/algorithms/opd_diagnostics.py: per-sample, per-token and top-k
  OPD diagnostics (teacher/student gap, agreement, entropy, KL proxies),
  gated by on_policy_distillation.log_sample_stats / log_token_stats /
  log_topk_stats with per-metric log periods; payloads are written next to
  the step's train_data jsonl (opd_*_stats_step*.{jsonl,pt}).
- OnPolicyDistillationConfig gains the log_* knobs, topk_stats_mode
  ("student_online_teacher_deferred" | "online"), topk_stats_k and
  topk_stats_max_tokens; assert_topk_stats_supported rejects combinations
  that cannot run (DTensor backend, fused linear logprobs, online mode
  without non-colocated teachers).
- Megatron backend: LogprobsPostProcessor(topk=...) captures student top-k
  logprobs in the same forward as prev_logprobs; TopkLogitsPostProcessor
  (return_logsumexp=True) returns the full-vocabulary logsumexp
  (distributed_vocab_logsumexp, TP-sharded, CP/packed aware) so top-k logits
  can be normalised on the driver. Policy.get_logprobs(topk=) and
  get_topk_logits(return_logsumexp=) are threaded through lm_policy,
  TeacherWorkerGroup.get_topk_logits and the DTensor workers (which raise
  NotImplementedError for the new options).
- AsyncTrajectoryCollector.compute_teacher_topk: per-teacher-group top-k
  for a driver-selected batch, reusing the per-agent routing of
  _compute_teacher_logprobs; multimodal rows are attached through the
  shared _attach_multimodal_rows helper.
- async_grpo_train wiring and pyrefly include.

Differences from the original: main trims logprobs/top-k outputs to the
pre-dense-padding original_seq_length and uses CPU int tuples for packed
offsets -- both kept; the fused top-k result is attached next to main's
pinned-memory logprobs copy; TeacherWorkerGroup.get_topk_logits copies
sequence_packing_args like main's get_logprobs instead of mutating them;
fetch_returned_only (not in main's worker-group API) is dropped; the
example yaml, reference config and launcher changes of the original are
not included (already on main / out of scope). The deleted legacy
dtensor_policy_worker.py hunk is dropped.

(cherry picked from commit 7251b00)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
(cherry picked from commit dadd267)
arendu added a commit that referenced this pull request Oct 7, 2026
…k capture

Port of super-v3.5-posttraining 7251b00 (#4011), restricted to what main
lacks. TROPD (proximal_teacher_alpha, subtract_global_baseline) is already
on main via #4357 and is NOT re-added; the TROPD hunks of the original were
resolved to main's versions.

Ported:
- nemo_rl/algorithms/opd_diagnostics.py: per-sample, per-token and top-k
  OPD diagnostics (teacher/student gap, agreement, entropy, KL proxies),
  gated by on_policy_distillation.log_sample_stats / log_token_stats /
  log_topk_stats with per-metric log periods; payloads are written next to
  the step's train_data jsonl (opd_*_stats_step*.{jsonl,pt}).
- OnPolicyDistillationConfig gains the log_* knobs, topk_stats_mode
  ("student_online_teacher_deferred" | "online"), topk_stats_k and
  topk_stats_max_tokens; assert_topk_stats_supported rejects combinations
  that cannot run (DTensor backend, fused linear logprobs, online mode
  without non-colocated teachers).
- Megatron backend: LogprobsPostProcessor(topk=...) captures student top-k
  logprobs in the same forward as prev_logprobs; TopkLogitsPostProcessor
  (return_logsumexp=True) returns the full-vocabulary logsumexp
  (distributed_vocab_logsumexp, TP-sharded, CP/packed aware) so top-k logits
  can be normalised on the driver. Policy.get_logprobs(topk=) and
  get_topk_logits(return_logsumexp=) are threaded through lm_policy,
  TeacherWorkerGroup.get_topk_logits and the DTensor workers (which raise
  NotImplementedError for the new options).
- AsyncTrajectoryCollector.compute_teacher_topk: per-teacher-group top-k
  for a driver-selected batch, reusing the per-agent routing of
  _compute_teacher_logprobs; multimodal rows are attached through the
  shared _attach_multimodal_rows helper.
- async_grpo_train wiring and pyrefly include.

Differences from the original: main trims logprobs/top-k outputs to the
pre-dense-padding original_seq_length and uses CPU int tuples for packed
offsets -- both kept; the fused top-k result is attached next to main's
pinned-memory logprobs copy; TeacherWorkerGroup.get_topk_logits copies
sequence_packing_args like main's get_logprobs instead of mutating them;
fetch_returned_only (not in main's worker-group API) is dropped; the
example yaml, reference config and launcher changes of the original are
not included (already on main / out of scope). The deleted legacy
dtensor_policy_worker.py hunk is dropped.

(cherry picked from commit 7251b00)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
(cherry picked from commit dadd267)
Signed-off-by: adithyare <[email protected]>
arendu added a commit that referenced this pull request Oct 7, 2026
…k capture

Port of super-v3.5-posttraining 7251b00 (#4011), restricted to what main
lacks. TROPD (proximal_teacher_alpha, subtract_global_baseline) is already
on main via #4357 and is NOT re-added; the TROPD hunks of the original were
resolved to main's versions.

Ported:
- nemo_rl/algorithms/opd_diagnostics.py: per-sample, per-token and top-k
  OPD diagnostics (teacher/student gap, agreement, entropy, KL proxies),
  gated by on_policy_distillation.log_sample_stats / log_token_stats /
  log_topk_stats with per-metric log periods; payloads are written next to
  the step's train_data jsonl (opd_*_stats_step*.{jsonl,pt}).
- OnPolicyDistillationConfig gains the log_* knobs, topk_stats_mode
  ("student_online_teacher_deferred" | "online"), topk_stats_k and
  topk_stats_max_tokens; assert_topk_stats_supported rejects combinations
  that cannot run (DTensor backend, fused linear logprobs, online mode
  without non-colocated teachers).
- Megatron backend: LogprobsPostProcessor(topk=...) captures student top-k
  logprobs in the same forward as prev_logprobs; TopkLogitsPostProcessor
  (return_logsumexp=True) returns the full-vocabulary logsumexp
  (distributed_vocab_logsumexp, TP-sharded, CP/packed aware) so top-k logits
  can be normalised on the driver. Policy.get_logprobs(topk=) and
  get_topk_logits(return_logsumexp=) are threaded through lm_policy,
  TeacherWorkerGroup.get_topk_logits and the DTensor workers (which raise
  NotImplementedError for the new options).
- AsyncTrajectoryCollector.compute_teacher_topk: per-teacher-group top-k
  for a driver-selected batch, reusing the per-agent routing of
  _compute_teacher_logprobs; multimodal rows are attached through the
  shared _attach_multimodal_rows helper.
- async_grpo_train wiring and pyrefly include.

Differences from the original: main trims logprobs/top-k outputs to the
pre-dense-padding original_seq_length and uses CPU int tuples for packed
offsets -- both kept; the fused top-k result is attached next to main's
pinned-memory logprobs copy; TeacherWorkerGroup.get_topk_logits copies
sequence_packing_args like main's get_logprobs instead of mutating them;
fetch_returned_only (not in main's worker-group API) is dropped; the
example yaml, reference config and launcher changes of the original are
not included (already on main / out of scope). The deleted legacy
dtensor_policy_worker.py hunk is dropped.

(cherry picked from commit 7251b00)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
(cherry picked from commit dadd267)
Signed-off-by: adithyare <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) Documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants