Repository navigation
feat(opd): explicit fp32 LM head for MOPD teachers - #4518
Open
pjin-nvidia wants to merge 1 commit into
Open
pjin-nvidia wants to merge 1 commit into
pjin-nvidia wants to merge 1 commit into
Conversation
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]>
4 tasks done
4 tasks done
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.