fix(grpo,rloo): apply generation_config override in use_transformers_paged path#5888
Open
Sumu004 wants to merge 1 commit into
Open
fix(grpo,rloo): apply generation_config override in use_transformers_paged path#5888Sumu004 wants to merge 1 commit into
Sumu004 wants to merge 1 commit into
Conversation
…paged path The regular generation path already passes generation_kwargs to unwrap_model_for_generation (which calls _override_model_generation_config) to work around transformers#42762, where model-specific generation_config values (e.g. Qwen2.5's temperature=0.7) silently override training kwargs such as temperature=1.0 during model.generate(). The use_transformers_paged path was missing this same fix: it called unwrap_model_for_generation without generation_kwargs, leaving the model's generation_config unoverridden before generate_batch(). This caused near-greedy sampling in the paged path under transformers < 5.0, silently collapsing GRPO/RLOO rollout diversity and making the advantage signal degenerate (std(R) ≈ 0) without any error. Fix: pass generation_kwargs=self.generation_kwargs in the use_transformers_paged branch of both GRPOTrainer and RLOOTrainer, consistent with the regular generation path. Also adds unit tests for _override_model_generation_config covering: - config override during context (transformers < 5) - original config restored after context - no-op when generation_kwargs=None - no-op on transformers >= 5 (upstream fix) Fixes: huggingface#5783
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.
What does this PR do?
The
use_transformers_pagedgeneration path in bothGRPOTrainerandRLOOTrainerwas missing thegeneration_kwargsoverride that the regular path already applies via_override_model_generation_config.On transformers < 5.0, model-specific
generation_configvalues (e.g. Qwen2.5 ships withtemperature=0.7) are silently merged on top of training kwargs duringmodel.generate()— see transformers#42762. The regular generation path was already fixed (after the v0.24.0 tag) by passinggeneration_kwargs=self.generation_kwargstounwrap_model_for_generation. Theuse_transformers_pagedbranch calledunwrap_model_for_generationwithoutgeneration_kwargs, leaving the same silent bug active: rollouts collapse to near-duplicates, advantage variance → 0, and GRPO/RLOO training silently fails with no error or warning.Fix: pass
generation_kwargs=self.generation_kwargsin theuse_transformers_pagedbranch of both trainers, matching the comment and pattern already on the regular path. Also adds unit tests for_override_model_generation_config(none existed before).Fixes #5783
Before submitting
AI writing disclosure
We welcome the use of AI tools to help with contributions. For transparency and to help us improve our review process, please indicate the level of AI involvement in this PR.
Who can review?
@lewtun @kashif — this touches the GRPO and RLOO generation paths. Happy to make any adjustments.
Note
Low Risk
Small, targeted parity fix in rollout generation plus tests; aligns paged path with an already-used pattern on the regular path.
Overview
The
use_transformers_pagedrollout path inGRPOTrainerandRLOOTrainernow passesgeneration_kwargs=self.generation_kwargsintounwrap_model_for_generation, matching the non-paged generation path. That applies the existing_override_model_generation_configworkaround for transformers#42762 (on transformers < 5.0, bundled modelgeneration_configcan override training sampling settings duringgenerate/generate_batch).tests/test_model_utils.pyaddsTestOverrideModelGenerationConfigcovering override during the context, restore afterward, no-op when kwargs areNone, and no-op on transformers ≥ 5.0.Reviewed by Cursor Bugbot for commit f63a893. Bugbot is set up for automated code reviews on this repo. Configure here.