Skip to content

[trainer,algo] feat: Support On-Policy Distillation in main_ppo_sync#5997

Draft
0oshowero0 wants to merge 1 commit intoverl-project:mainfrom
0oshowero0:tq_main_opd
Draft

[trainer,algo] feat: Support On-Policy Distillation in main_ppo_sync#5997
0oshowero0 wants to merge 1 commit intoverl-project:mainfrom
0oshowero0:tq_main_opd

Conversation

@0oshowero0
Copy link
Copy Markdown
Collaborator

What does this PR do?

Support #5041 in main_ppo_sync.py

Checklist Before Starting

  • Search for similar PRs. Paste at least one query link here: ...
  • Format the PR title as [{modules}] {type}: {description} (This will be checked by the CI)
    • {modules} include fsdp, megatron, veomni, sglang, vllm, rollout, trainer, ci, training_utils, recipe, hardware, deployment, ray, worker, single_controller, misc, perf, model, algo, env, tool, ckpt, doc, data, cfg, reward, fully_async, one_step_off
    • If this PR involves multiple modules, separate them with , like [megatron, fsdp, doc]
    • {type} is in feat, fix, refactor, chore, test
    • If this PR breaks any API (CLI arguments, config, function signature, etc.), add [BREAKING] to the beginning of the title.
    • Example: [BREAKING][fsdp, megatron] feat: dynamic batching

Test

For changes that can not be tested by CI (e.g., algorithm implementation, new model support), validate by experiment(s) and show results like training curve plots, evaluation results, etc.

API and Usage Example

Demonstrate how the API changes if any, and provide usage example(s) if possible.

# Add code snippet or script demonstrating how to use this

Design & Code Changes

Demonstrate the high-level design if this PR is complex, and list the specific changes.

Checklist Before Submitting

Important

Please check all the following items before requesting a review, otherwise the reviewer might deprioritize this PR for review.

Signed-off-by: 0oshowero0 <[email protected]>

update

Signed-off-by: 0oshowero0 <[email protected]>

update

Signed-off-by: 0oshowero0 <[email protected]>

fix

Signed-off-by: 0oshowero0 <[email protected]>
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements teacher model distillation support in the PPO synchronization loop, including the addition of a TeacherModelManager and updates to the agent loop and transfer queue utilities to handle teacher logprobs and KVBatchMeta. Review feedback highlights a potential KeyError in agent_loop.py when extra_fields is missing and a crash in main_ppo_sync.py when processing multiple agent loop outputs.

Comment on lines +233 to +236
teacher_ids, teacher_logprobs = (
output["extra_fields"].pop("teacher_ids", None),
output["extra_fields"].pop("teacher_logprobs", None),
)
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.

high

The code assumes extra_fields is always present in the output dictionary. However, since output is created using self.model_dump(exclude_unset=True) at line 212, if extra_fields was not explicitly set (it has a default empty dict), it will be excluded from the resulting dictionary. This will cause a KeyError when attempting to access output["extra_fields"]. It is safer to use .get() or ensure the key exists before popping.

        extra_fields = output.get("extra_fields", {})
        teacher_ids, teacher_logprobs = (
            extra_fields.pop("teacher_ids", None),
            extra_fields.pop("teacher_logprobs", None),
        )

Comment on lines +377 to +382
await self._compute_teacher_logprobs(
output,
prompt_ids=output.prompt_ids,
response_ids=output.response_ids,
validate=validate,
)
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.

high

The code at lines 377-382 will crash if output is a list of AgentLoopOutput objects, as it attempts to access .prompt_ids and .response_ids directly on the output variable. While there is a TODO comment at line 376, the current implementation is broken for the multi-output case which is explicitly handled earlier in the function (line 350). You should iterate over the outputs list to compute teacher logprobs for each item.

Suggested change
await self._compute_teacher_logprobs(
output,
prompt_ids=output.prompt_ids,
response_ids=output.response_ids,
validate=validate,
)
# TODO: Support output:list[AgentLoopOutput]
for out in outputs:
await self._compute_teacher_logprobs(
out,
prompt_ids=out.prompt_ids,
response_ids=out.response_ids,
validate=validate,
)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant