Skip to content

feat: add opd/tropd metrics for super v3.5 - #4011

Merged
yfw merged 6 commits into
super-v3.5-posttrainingfrom
kbhardwaj/super-mopd
Sep 9, 2026
Merged

yfw merged 6 commits into
super-v3.5-posttrainingfrom
kbhardwaj/super-mopd

Conversation

@kbhardwaj-nvidia

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds proximal on-policy distillation (TROPD), comprehensive OPD diagnostics, and Super 3.5 HSG run support to GRPO.

The TROPD advantage is computed as:
log(α · π_teacher + (1 - α) · π_student) - log(π_student)

This PR:

  • Adds typed and validated on_policy_distillation configuration.
  • Preserves legacy OPD behavior when proximal_teacher_alpha: 1.0.
  • Supports masked global-baseline subtraction.
  • Adds sample-level and token-level diagnostic artifacts.
  • Adds online and deferred top-k policy diagnostics, including full-vocabulary logsumexp capture.
  • Adds a deterministic proxy-data builder, Super 3.5 configuration, and HSG launcher.

Usage

Configure TROPD through the top-level on_policy_distillation block:

on_policy_distillation:
  enabled: true
  use_orm_advantage: false
  proximal_teacher_alpha: 0.2
  subtract_global_baseline: true

  log_sample_stats: true
  sample_stats_log_period: 1
  log_sample_responses: false

  log_token_stats: true
  token_stats_log_period: 1

  log_topk_stats: false
  topk_stats_log_period: 5
  topk_stats_mode: student_online_teacher_deferred
  topk_stats_k: 16

  teacher_model_by_agent_name:
    example_agent: /path/to/teacher/model

Additional Information

Validation completed:

  • 23 focused TROPD and diagnostics tests passed on the target branch.
  • Ruff lint and format checks passed.
  • Shell syntax and git diff --check passed.
  • An 8-node, one-step HSG smoke completed training, refit, checkpointing, and diagnostic emission.
  • A 100-step Super v24-to-Oracle TROPD run completed successfully with exit code 0:0.
  • The final step-100 checkpoint was committed successfully.
  • The step-100 sample artifact contains 512 valid JSONL records.
  • The step-100 token artifact loads successfully with the expected diagnostic schema.

@copy-pr-bot

copy-pr-bot Bot commented Sep 5, 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 5, 2026
@kbhardwaj-nvidia
kbhardwaj-nvidia marked this pull request as ready for review September 5, 2026 01:25
@kbhardwaj-nvidia
kbhardwaj-nvidia requested review from a team as code owners September 5, 2026 01:25
@kbhardwaj-nvidia
kbhardwaj-nvidia marked this pull request as draft September 5, 2026 01:26
@kbhardwaj-nvidia
kbhardwaj-nvidia changed the base branch from main to super-v3.5-posttraining September 5, 2026 01:42
@kbhardwaj-nvidia kbhardwaj-nvidia changed the title [feat] Add OPD/TROPD metrics for Super v3.5 feat: add opd/tropd metrics for super v3.5 Sep 5, 2026
@copy-pr-bot

copy-pr-bot Bot commented Sep 8, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@kbhardwaj-nvidia
kbhardwaj-nvidia marked this pull request as ready for review September 8, 2026 20:53
@copy-pr-bot

copy-pr-bot Bot commented Sep 8, 2026

Copy link
Copy Markdown

Auto-sync is disabled for ready for review pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

Comment thread nemo_rl/algorithms/grpo.py Resolved

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

Reviewed against base super-v3.5-posttraining (95d3cc3) at head 4dbc04c, with the merge criteria "flag-off behavior identical to base" and "new implementation correct".

Flag-off: every changed line on the default-flags path was traced and matches base — the alpha == 1.0 estimator branch (metrics get the same raw-gap tensor), _opd_seq_error_logging_fields vs the legacy masking formula (exact parity incl. the [:, 1:] slices), lm_policy.get_topk_logits torch.cat → from_batches (equal for equal-length shards; the removed "flattens" comment was already stale at base), the Megatron get_logprobs restructuring, TeacherWorkerGroup.get_topk_logits vs its sibling, and the async loop wiring. The one exception is the unconditional _opd_seq_error_logging_fields call (inline comment at grpo.py:5428), which is also what turns 15 async test_grpo.py tests red.

Correctness of the new code: TROPD math checked numerically (logaddexp form == closed form for α ∈ {1, 0.5, 0.2, 1e-3}), masked baseline finite on an all-masked batch, next-token→input-position alignment consistent with the repo's logprob convention, distributed_vocab_logsumexp matches torch.logsumexp on CPU (TP>1 path is the PR's GPU test). Remaining items are inline.

Lint: pre-commit run --all-files fails on two PR files: pyrefly at opd.py:73 (inline) and ruff-format/isort in opd_diagnostics.py:26-28 (a blank line after import torch — running pre-commit fixes it).

Smaller notes, no inline comment:

  • use_orm_advantage / orm_advantage_weight (opd.py:71-72) have no readers anywhere in nemo_rl/; the only YAML setting them predates this PR and loads fine via extra="allow". Consider dropping them, or a validator rejecting non-default values, so use_orm_advantage: true cannot silently do nothing.
  • The online top-k payload stores raw logits in bf16 and later subtracts the fp32 V_logsumexp, while its description calls the resulting probabilities "exact". With the shipped defer_fp32_logits: true the logits are already bf16 so nothing is lost there; for fp32-logit configs consider storing logits - lse (as the fused path does) or softening the wording.
  • topk_stats_max_tokens subsamples after the full [B, S, k] top-k transfer to the driver, so it bounds the saved payload but not host memory.

Not verified here: no CUDA/Megatron/vLLM in the review environment, so the CP+packing V_logsumexp gather, the fused Megatron top-k path, and test_distributed_vocab_logsumexp were read-verified only; test_grpo.py numbers come from a scratch copy that only neutralizes the Ray-actor autouse fixture.

Generated by Claude Code

Comment thread nemo_rl/algorithms/grpo.py Resolved
Comment thread nemo_rl/algorithms/opd.py Resolved
Comment thread nemo_rl/algorithms/opd.py Resolved
Comment thread nemo_rl/algorithms/grpo.py Resolved
yfw and others added 2 commits September 8, 2026 19:05
compute_teacher_topk built the teacher batch from input_ids/input_lengths only, so a VLM teacher either failed on media placeholder tokens or scored a different input than the student. Mirror _compute_teacher_logprobs: thread multimodal_data through the call, track row_indices through DP padding, and select the media rows per teacher. The row-selection logic is shared via _attach_multimodal_rows so the two teacher paths cannot drift. Adds two tests mirroring the existing multimodal logprob tests.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
Signed-off-by: Khushi Bhardwaj <[email protected]>
@yfw
yfw merged commit 7251b00 into super-v3.5-posttraining Sep 9, 2026
10 checks passed
@yfw
yfw deleted the kbhardwaj/super-mopd branch September 9, 2026 07:42
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]>
potatowarriors added a commit to potatowarriors/RL that referenced this pull request Nov 25, 2026
…(decision 79) - SWE agent loop passes end to end with a scripted model

Gym source: upstream 7bfccecc1 (normalize response tools for replay, NVIDIA-NeMo#3190) as a patch file under gym_patches/,
applied to the submodule and the measurement checkout by tools/apply_gym_patches.sh (idempotent, 'check' mode).
Plugin: alpha_vllm_model also drops the tool-result 'name' and 'provider_specific_fields' before validation
(same targets as upstream NVIDIA-NeMo#4011/NVIDIA-NeMo#4483); its server venv gets nemo-gym from the package index, so a source
patch would not reach it.
Raising the Gym pin was rejected: every Gym containing the fixes pins vllm 0.29, and uv lock fails in a
scratch copy (torchvision 0.28 vs 0.26, then transformers >=5.10.4 vs <5.9; Ray 2.58 vs 2.56.1).
Verified: plugin tests 9 (2 negative controls), Gym test_openai_utils 180, R3 tallies unchanged, scripted-model
loop on the installed configuration 4/4 reward 1 (student_stub7).

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JjdZctFTn2wkcheCmz3xKN
Signed-off-by: potatowarriors <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants