Refactor vLLM generation [2/N]: Decouple rollout_func and vLLM functionalities#4712
Draft
albertvillanova wants to merge 2 commits intohuggingface:mainfrom
Draft
Refactor vLLM generation [2/N]: Decouple rollout_func and vLLM functionalities#4712albertvillanova wants to merge 2 commits intohuggingface:mainfrom
albertvillanova wants to merge 2 commits intohuggingface:mainfrom
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
|
Hi @albertvillanova! I'm working on GRPO training with custom rollout functions using UnslothGRPOTrainer and OpenEnv and currently blocked by the vllm coupling issue that your PR addresses. I'd love to help move this forward if useful! |
This was referenced Feb 18, 2026
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.
Refactor vLLM generation [2/N]: Decouple rollout_func and vLLM functionalities.
This PR refactors the
_generate_single_turnmethod inGRPOTrainerto separaterollout_funcandvllmfunctionalities into independent, top-level concerns. This makes the code more modular and easier to extract the vLLM functionality into a separate module. See:Motivation
Previously, the
rollout_funclogic was nested within theuse_vllmconditional blocks, creating unnecessary coupling between two orthogonal features:rollout_func: A general hook for custom generation logic (can work with or without vLLM)vllm: An inference acceleration backend (can work with or withoutrollout_func)This coupling makes the code harder to understand and makes it difficult to extract either feature into separate modules.
Changes
Restructured
_generate_single_turninto two clear phases:Phase 1: vLLM Preparation
use_vllm=True, regardless of whetherrollout_funcis providedPhase 2: Generation Dispatch
Independent top-level conditionals for each generation path:
if rollout_func is not None:→ Custom rollout (may use vLLM internally)elif use_vllm:→ Trainer-managed vLLM generationelif use_transformers_paged:→ Paged transformers generationelse:→ Regular transformers generationBenefits
rollout_func