Skip to content

[Feature Request]On-policy distillation support #910

Closed

Description

@sharonyu-115

Open this issue to track the enhancement of adding on-policy knowledge distillation in NeMo RL, a distillation variation used by Qwen3, which follows the following procedure:

"On-policy Distillation: In this phase, the student model generates on-policy sequences for fine-tuning. Specifically, prompts are sampled, and the student model produces responses in either /think or /no think mode. The student model is then fine-tuned by aligning its logits with those of a teacher model (Qwen3-32B or Qwen3-235B-A22B) to minimize the KL divergence."

Training and program flow:

Image Image

Core methodology (high level)

  • Student generates on-policy rollouts for sampled prompts.
  • Teacher(s) provide token-level targets (logits or probabilities) on the student’s generated trajectories.
  • Optimize student with a distillation loss on those trajectories.

Implementation design - changes on core components

  • New Distillation Algorithm Class (OnPolicyDistillation)
    • Similar structure to GRPO algorithm in nemo_rl/algorithms/grpo.py
    • Manages the overall training loop and orchestrates student-teacher interaction
    • Leverages existing GRPO infrastructure for distributed training
  • Distillation Loss Function (DistillationLossFn)
    • Implements KL divergence loss between student and teacher logits
    • Similar to ClippedPGLossFn in nemo_rl/algorithms/loss_functions.py
    • Supports token-level masking to exclude prompt tokens from loss calculation
  • Dual Policy Management
    • Student Policy: Trainable, inherits from existing Policy class
    • Teacher Policy: Fixed/frozen, separate instance or shared infrastructure
    • Both can use the same underlying worker architecture (DTensor/Megatron)

https://nvidia.slack.com/archives/C0271E234TB/p1751960108820759

Activity

  1. changed the title [-]On-policy distillation support[/-] [+][Feature Request]On-policy distillation support[/+] on Aug 13, 2025
  2. euronymous-aithal commented on Aug 13, 2025

    @euronymous-aithal
    Contributor
  3. terrykong commented on Aug 14, 2025

    @terrykong
    Collaborator

    Hi @sharonyu-115 . Thanks for sharing your design, and I think this is definitely a use-case you can easily enable with nemo-rl.

    One thing you may need to consider is how to allocate resources. AFAICT, it's probably easiest if teacher and student aren't enforced to be colocated since that enforces things like divisibility of world size. So it's probably easiest to only allow colocation on the student and treat the teacher as a separate policy.

  4. terrykong commented on Aug 14, 2025

    @terrykong
    Collaborator

    @YUki-666 i feel like as long as they aren't using async engine they probably don't need #895 , but i think SPREAD will probably pose issues since the bundles will be spread out for student leaving an inefficient scheduling for both the student and teacher. wdyt?

  5. sharathts commented on Aug 14, 2025

    @sharathts
    Contributor

    Thanks @sharonyu-115 for sharing the plan, looks great. Two minor comments:

    1. During distillation, we run the teacher in eval mode. Let's make this a configurable option.
    2. Re : "Supports token-level masking to exclude prompt tokens from loss calculation" - Let's make this configurable as well, as we have observed promising results when not masking the prompt during KD.
  6. yuki-97 commented on Aug 15, 2025

    @yuki-97
    Contributor

    @yuki-666 i feel like as long as they aren't using async engine they probably don't need #895 , but i think SPREAD will probably pose issues since the bundles will be spread out for student leaving an inefficient scheduling for both the student and teacher. wdyt?

    yup, it's better to use PACK in this case.

    add some infos:

    • we set default SPREAD for now at here because of #895.
    • when implement this case, we can set placement_group_strategy="PACK" when init RayVirtualCluster.
  7. linked a pull request that will close this issuefeat: add on policy distillation algorithm #1006on Aug 28, 2025
  8. self-assigned this
    on Sep 22, 2025
  9. added
    qa_rcca_done
    on May 5, 2026
  10. qiaochuz-nv commented on May 5, 2026

    @qiaochuz-nv
    Contributor

    QA RCCA Analysis

    RCCA Status: Done
    RCCA Category: covered
    Test Action: none

    Fix PR: #1006
    Root Cause: fix PR includes upstream test coverage.
    Trigger Config: [Feature Request]On-policy distillation support

    Coverage Assessment:

    Area Result
    Existing Test Upstream fix PR test coverage
    Coverage Status COVERED
    Gap N/A
    Corrective Action No nmfw_tests addition required; fix PR includes upstream test coverage or equivalent regression coverage.

    Conclusion: RCCA classification completed for this closed NeMo-RL GitHub issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

algorithmexternalqa_rcca_donex-ss

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions