Skip to content

feat(opd): explicit fp32 LM head for MOPD teachers - #4518

Open
pjin-nvidia wants to merge 1 commit into
mainfrom
pjin/mopd-teacher-fp32-lm-head-20261005
Open

pjin-nvidia wants to merge 1 commit into
mainfrom
pjin/mopd-teacher-fp32-lm-head-20261005

Conversation

@pjin-nvidia

Copy link
Copy Markdown
Contributor

MOPD teachers inherited policy.megatron_cfg.fp32_lm_head through the deep-copied student config, with no validation on that path.

Full-vocabulary MOPD also dropped the teacher side's fp32 precision even with the fp32 head on everywhere. The student rebuilt teacher logits from the hidden-state payload with a bf16-output GEMM, and the logits payload was cast to payload_dtype (bfloat16 by default). The divergence kernel then upcast these bf16-rounded teacher logits to fp32, so both sides of the reverse KL were fp32 tensors while only the student's carried fp32 precision. Under self-distillation on Qwen3-1.7B this left a precision-only reverse-KL floor of ~3e-4 nats per token; with this change it is exactly 0.

  • Teacher config: port the teacher_overrides merge fix from the super v3.5 MOPD PR (feat: super v3.5 posttraining joint mopd #3830). Through the parsed MasterConfig, a teacher_overrides entry reset every default_teacher_cfg field it did not set (e.g. tensor_model_parallel_size 4 -> 1) for that teacher. Here _opd_cfg dumps each override with exclude_unset=True instead of feat: super v3.5 posttraining joint mopd #3830's None-default TeacherResourceOverrides model.
  • Accept "tf32" as an alias of true for fp32_lm_head (trainer, vLLM, and teachers) via nemo_rl.utils.fp32_lm_head; other non-bool values are rejected. The Megatron head always runs Transformer Engine's GEMM on the bf16 operands with fp32 output.
  • Add an explicit per-teacher fp32_lm_head (default false) to TeacherResourceConfig. TeacherWorkerGroup no longer inherits the student's value, and setting it inside megatron_cfg_overrides is rejected.
  • Validate at setup, before reserving resources: every teacher must match the student; with the fp32 head on, the full-vocab logits payload needs payload_dtype=float32 so the teacher's fp32 logits are not rounded to bf16 in transport; fused linear logprobs are rejected on the top-k path, where they bypass the teacher's output_layer.
  • Full-vocabulary MOPD: carry the resolved setting in the on_policy_distillation_full transport. With the fp32 head on, the student rebuilds teacher logits with an fp32-output GEMM (torch.mm(out_dtype=float32) on CUDA, bit-identical to Megatron's fp32 head on GB200) instead of a bf16 GEMM upcast afterwards. With it off, the rebuild stays the bf16 GEMM it was.
  • Document the setting in docs/about/algorithms/mopd.md.

MOPD teachers inherited policy.megatron_cfg.fp32_lm_head through the
deep-copied student config, with no validation on that path.

Full-vocabulary MOPD also dropped the teacher side's fp32 precision even
with the fp32 head on everywhere. The student rebuilt teacher logits
from the hidden-state payload with a bf16-output GEMM, and the logits
payload was cast to payload_dtype (bfloat16 by default). The divergence
kernel then upcast these bf16-rounded teacher logits to fp32, so both
sides of the reverse KL were fp32 tensors while only the student's
carried fp32 precision. Under self-distillation on Qwen3-1.7B this left
a precision-only reverse-KL floor of ~3e-4 nats per token; with this
change it is exactly 0.

- Teacher config: port the teacher_overrides merge fix from the super
  v3.5 MOPD PR (#3830). Through
  the parsed MasterConfig, a teacher_overrides entry reset every
  default_teacher_cfg field it did not set (e.g.
  tensor_model_parallel_size 4 -> 1) for that teacher. Here _opd_cfg
  dumps each override with exclude_unset=True instead of #3830's
  None-default TeacherResourceOverrides model.
- Accept "tf32" as an alias of true for fp32_lm_head (trainer, vLLM,
  and teachers) via nemo_rl.utils.fp32_lm_head; other non-bool values
  are rejected. The Megatron head always runs Transformer Engine's GEMM
  on the bf16 operands with fp32 output.
- Add an explicit per-teacher fp32_lm_head (default false) to
  TeacherResourceConfig. TeacherWorkerGroup no longer inherits the
  student's value, and setting it inside megatron_cfg_overrides is
  rejected.
- Validate at setup, before reserving resources: every teacher must
  match the student; with the fp32 head on, the full-vocab logits
  payload needs payload_dtype=float32 so the teacher's fp32 logits are
  not rounded to bf16 in transport; fused linear logprobs are rejected
  on the top-k path, where they bypass the teacher's output_layer.
- Full-vocabulary MOPD: carry the resolved setting in the
  on_policy_distillation_full transport. With the fp32 head on, the
  student rebuilds teacher logits with an fp32-output GEMM
  (torch.mm(out_dtype=float32) on CUDA, bit-identical to Megatron's
  fp32 head on GB200) instead of a bf16 GEMM upcast afterwards. With it
  off, the rebuild stays the bf16 GEMM it was.
- Document the setting in docs/about/algorithms/mopd.md.

Signed-off-by: Peter Jin <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Oct 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 Oct 5, 2026
@terrykong terrykong added CI:L1 Run doctests, unit tests, and functional tests CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) and removed CI:L1 Run doctests, unit tests, and functional tests labels Nov 5, 2026
@terrykong terrykong removed the Documentation Improvements or additions to documentation label Nov 28, 2026

This branch has not been deployed

No deployments
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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants