Skip to content

Stop ignoring the min_p and stop settings the GRPO notebooks pass to vLLM - #11595

Merged
danielhanchen merged 6 commits into
unslothai:mainfrom
NilayYadav:grpo-vllm-scalar-sampling-params
Sep 23, 2026
Merged

danielhanchen merged 6 commits into
unslothai:mainfrom
NilayYadav:grpo-vllm-scalar-sampling-params

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

The GRPO notebooks pass vllm_sampling_params with min_p=0.1 and include_stop_str_in_output=True. On main only list settings like stop are applied. Everything else is dropped without any warning, so vLLM samples with min_p 0.0 and the user never knows.

This adds a local copy of the helper that builds the sampling settings. It now applies every setting the user changed, except seed, n, temperature, max_tokens and logprobs. Those stay under GRPOConfig: a fixed seed would make every generation the same, and a different temperature would break training.

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed that grpo_update_SamplingParams in unsloth_zoo/rl_replacements.py only copies non-empty list values, so min_p and include_stop_str_in_output are silently dropped. Could you make this fix in the unsloth-zoo helper itself instead of adding a separate copy in unsloth/models/rl_replacements.py, so there is only one version to maintain?

@danielhanchen danielhanchen self-assigned this Sep 23, 2026
danielhanchen added a commit to Imagineer99/unsloth that referenced this pull request Sep 23, 2026
…amplingParams

TRL 0.28 moved the colocate SamplingParams(**generation_kwargs) call out of
grpo_trainer.py into trl/generation/vllm_generation.py, so the source
replacement in rl.py never matches there and the user's vllm_sampling_params
were ignored entirely on TRL 0.28 through 1.13.

The trainer now hands args.vllm_sampling_params to self.vllm_generation, and
the existing scoped VLLMGeneration.generate wrapper routes that one
SamplingParams build through grpo_update_SamplingParams for the duration of
the call. Nothing changes when vllm_sampling_params is unset or in server mode.
@shimmyshimmer

Copy link
Copy Markdown
Member

Review record for #11595, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#72.

Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found.

Round 1 — reviewed mirror 99c5573e8 (this PR's cd9c99dd4)

chatgpt-codex-connector[bot] on unsloth/models/rl_replacements.py (on the mirror)

@@ -3586,9 +3621,28 @@ def unsloth_collective_rpc(method, *args, **kwargs):
             override("generate", wrap_generation_call)
             override("chat", wrap_generation_call)
             override("collective_rpc", wrap_collective_rpc)
+            # TRL >= 0.28 builds `SamplingParams(**generation_kwargs)` inside this call, the one site the older-TRL source replacement in rl.py targets; route it through the same helper for this call only.
+            user_sampling_params = getattr(self, "_unsloth_vllm_sampling_params", None)
+            original_sampling_params = vllm_generation.__dict__.get("SamplingParams", None)
+            if user_sampling_params is not None and original_sampling_params is not None:
+
+                def unsloth_sampling_params(*sp_args, **sp_kwargs):
+                    if sp_args:
+                        return original_sampling_params(*sp_args, **sp_kwargs)
+                    return original_sampling_params(
+                        **grpo_update_SamplingParams(
+                            original_sampling_params, sp_kwargs, user_sampling_params
+                        )
+                    )
+
+                vllm_generation.SamplingParams = unsloth_sampling_params

P2 Badge Avoid swapping the module-global SamplingParams

When two VLLMGeneration.generate calls overlap in the same process, the second call captures the first call's wrapper as original_sampling_params, so its signature is reduced to (*sp_args, **sp_kwargs) and it can apply the first trainer's sampling settings instead of its own. Depending on completion order, the finally blocks can also restore that wrapper permanently rather than the real class, affecting later generations. Keep the override instance-local or serialize/contextualize access to this module global.

Useful? React with 👍 / 👎.

Rejected on the mirror

Reply from danielhanchen:

Not reachable: VLLMGeneration.generate runs once at a time per process in GRPO, and vLLM's offline LLM engine does not support overlapping generate calls (vllm-project/vllm#1285). The adjacent llm.generate/chat/collective_rpc overrides already rely on the same one-call-at-a-time contract.

Round 2 — reviewed mirror 99c5573e86 (this PR's cd9c99dd4)

chatgpt-codex-connector[bot] (on the mirror)

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 99c5573e86

No triage reaction was recorded on the mirror

Verdict

The round converged at mirror 99c5573e86 (this PR's cd9c99dd4).

This is the review as it stood at that commit. Anything pushed to this PR afterwards was not part of it.

@danielhanchen
danielhanchen merged commit f5109b5 into unslothai:main Sep 23, 2026
30 of 31 checks passed
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…vLLM (unslothai#11595)

* Stop ignoring the min_p and stop settings the GRPO notebooks pass to vLLM

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add license header to GRPO sampling params test

* Check the GRPO helper signature with ast so formatting cannot break the test

* Apply vllm_sampling_params on TRL 0.28+ where VLLMGeneration builds SamplingParams

TRL 0.28 moved the colocate SamplingParams(**generation_kwargs) call out of
grpo_trainer.py into trl/generation/vllm_generation.py, so the source
replacement in rl.py never matches there and the user's vllm_sampling_params
were ignored entirely on TRL 0.28 through 1.13.

The trainer now hands args.vllm_sampling_params to self.vllm_generation, and
the existing scoped VLLMGeneration.generate wrapper routes that one
SamplingParams build through grpo_update_SamplingParams for the duration of
the call. Nothing changes when vllm_sampling_params is unset or in server mode.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Daniel Han <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants