trl icon indicating copy to clipboard operation
trl copied to clipboard

GRPOTrainer: allow evaluation-only sampling settings (e.g. greedy, 1 completion per prompt)

Open SardaKartik opened this issue 1 week ago • 2 comments

Feature request

GRPOTrainer cannot evaluate with greedy decoding, or with sampling settings different from training. As a result, evaluation also generates num_generations completions per prompt even when one would be enough.

Current behavior

  • GRPOConfig has temperature, top_p, top_k and min_p, but training and evaluation share them.
  • The only evaluation-specific generation setting is num_generations_eval. It defaults to num_generations, so by default evaluation generates the same number of completions per prompt as training (e.g. 8).
  • generation_kwargs can override the sampling settings, but it is global, so it also changes training. Making it greedy there would break GRPO: identical completions in a group get identical rewards, so there is no learning signal.

In the code (v1.19.0, and unchanged on current main):

  • trl/trainer/grpo_trainer.py: the transformers path builds generation_kwargs once with "do_sample": True and "temperature": self.temperature. There is no branch for evaluation.
  • trl/generation/vllm_generation.py: generate() uses temperature = self.temperature and passes it to SamplingParams. There is no branch for evaluation either.
  • The trainer already knows the mode (mode = "train" if self.model.training else "eval" is used in several places), but it is not used to pick the sampling settings.

Proposal

Add an evaluation-only temperature to GRPOConfig, e.g. eval_temperature, where 0 means greedy (do_sample=False on the transformers path). In eval mode the trainer would use it instead of temperature, in both the transformers and vLLM paths. When it is not set, behavior stays exactly as today.

With greedy decoding, one completion per prompt is enough, since all completions would be identical. This can already be expressed with num_generations_eval=1, so no extra option is needed for that. It would be worth documenting.

I kept the proposal to one option on purpose, to stay simple. If maintainers prefer something more general, such as an eval_generation_kwargs dict covering top_p, top_k and so on, I'm happy to do that instead.

One detail to settle: temperature is also used when computing log-probabilities in training. I would only change the generation temperature in eval mode, and avoid dividing by zero when it is 0.

Environment

  • TRL: 1.19.0 (trl[vllm]==1.19.0); also read the code on current main
  • vLLM: 0.34.0
  • Transformers: 5.22.2
  • PEFT: 0.22.0
  • Datasets: 5.2.0

Motivation

I train GRPO on Qwen2.5-0.5B-Instruct with num_generations=8 and vLLM generation. I want to check accuracy on a validation set every few steps, so I plan to use eval_strategy="steps" with an eval_dataset.

I'm frustrated by two things:

  1. The validation score is not comparable. It is sampled at the training temperature (1.0). A small model makes more slips when sampled, so the number reads lower and noisier than a normal greedy evaluation. It cannot be compared with benchmark numbers, which are measured greedily.
  2. Evaluation wastes time and GPU memory. By default, every validation question gets 8 sampled completions, as in training. For a plain accuracy check that is 8 times the generation work, and more completions held in memory, for a number that is still noisy. A greedy evaluation needs 1 completion per question and gives a deterministic result.

Today the only workaround is to run a separate greedy evaluation script outside the trainer, so the in-training validation curve is only a rough trend and costs more than it should.

I have not written a standalone reproduction script, and I have not measured the exact time or memory cost. This comes from reading the code paths above and from my training setup.

Your contribution

I'd like to work on this and can open a PR if you agree with the direction. I have read CONTRIBUTING.md. Should the same option also be added to RLOOTrainer for consistency?

SardaKartik avatar Nov 28 '26 17:11 SardaKartik

Hi, I would like to work on this issue. My proposed scope is an optional eval_temperature on GRPOConfig (None preserves current behavior; 0 enables greedy decoding), applied only during evaluation in both Transformers and vLLM generation so training and its log-probability temperature remain unchanged. I will add train/eval regression coverage and document pairing greedy evaluation with num_generations_eval=1.

I plan to keep the change to GRPOTrainer unless maintainers prefer adding the same option to RLOOTrainer. As a first-time TRL contributor, I will wait for assignment before opening a PR. I will use AI assistance and personally verify the implementation and tests.

PRINCE2-AI avatar Nov 30 '26 07:11 PRINCE2-AI

Hi @qgallouedec, I opened this issue and I'm ready to implement it. Could you assign it to me?

Proposed scope:

  • Add an optional eval_temperature to GRPOConfig. None keeps today's behavior, and 0 enables greedy decoding.
  • Apply it only in eval mode, in both the transformers and vLLM generation paths. Training and the log-probability temperature stay unchanged.
  • Add a test that checks train and eval use their own temperature, and a docs note about pairing greedy evaluation with the existing num_generations_eval=1, so evaluation generates one completion per prompt.

I'll keep the change to GRPOTrainer unless you'd like RLOOTrainer covered too, since the two share this logic. I'm also happy to change the design first if you prefer something different, for example an eval_generation_kwargs dict.

I will wait for assignment before opening a PR.

SardaKartik avatar Dec 05 '26 07:12 SardaKartik