GRPO: Tool continuation traces are discarded
Author: ingambeCreated Sep 26, 2026Updated Sep 27, 2026
Reproduction
Basically, num_generations > 1 makes complete sense for single shot User -> Assistant message.
But if we already have a tool call in the group, taking the first and num_generation == N is not working as the prefix is different.
ordered_set_of_prompt_ids = all_prompts[::num_generations]Works great on first call, but then, we only keep the head of each generation. So if we have: [history_A, history_B] due to tool calls, then we only keep A.
And then we are doing:
sampling_params = {
"n": num_generations,
}
self.vllm_client.generate(
prompts=ordered_set_of_prompt_ids, features=features, **sampling_params
)Which only provides the A prefix.
num_generations > 1 needs to be guarded by a group check to ensure we have no different prefix in the group. If no, put num_generations = 1
As requested, test to reproduce it (CPU only, but should not matter):
from types import SimpleNamespace
from trl.generation.vllm_generation import VLLMGeneration
def mock_server_generate(prompts, n, **kwargs):
# Echo the calculator result from the submitted history.
return {
"prompt_ids": prompts,
"completion_ids": [[prompt[-1]] for prompt in prompts for _ in range(n)],
"logprobs": None,
}
# Fields required by the real generation method; no model or server initialization.
generation = SimpleNamespace(
mode="server",
accelerator=SimpleNamespace(is_main_process=True, process_index=0),
vllm_client=SimpleNamespace(generate=mock_server_generate),
temperature=1.0,
top_p=1.0,
top_k=-1,
min_p=None,
repetition_penalty=1.0,
max_completion_length=1,
logprobs=0,
structured_outputs_regex=None,
generation_kwargs={},
)
# Same initial prompt, different tool calls and calculator results.
histories = [[1, 10, 30], [1, 20, 35]]
_, completions, _, _ = VLLMGeneration.generate(
generation, histories, images=None, num_generations=2
)
print("Calculator results:", [history[-1] for history in histories])
print("Results used for continuations:", [answer[0] for answer in completions])
assert completions == [[30], [35]], "B's continuation was generated from A's history."Current output:
Calculator results: [30, 35]
Results used for continuations: [30, 30]
AssertionError: B's continuation was generated from A's history.After fix:
Calculator results: [30, 35]
Results used for continuations: [30, 35]System Info
- Platform: macOS-26.6.2-arm64-arm-64bit
- Python version: 3.12.11
- TRL version: source checkout at commit 88e12d5ed13b2eaf15309a83e43157738b246051 (ingambe/trl)
- PyTorch version: 2.14.0
- accelerator(s): cpu
- Transformers version: 5.17.0
- Accelerate version: 1.15.0
- Accelerate config: not found
- Datasets version: 5.0.1
- HF Hub version: 1.33.0
- bitsandbytes version: not installed
- DeepSpeed version: not installed
- Liger-Kernel version: not installed
- PEFT version: not installed
- vLLM version: not installed
Checklist
- I have checked that my issue isn't already filed (see open issues)
- I have included my system information
- Any code provided is minimal, complete, and reproducible (more on MREs)
- Any code provided is properly formatted in code blocks, (no screenshot, more on code blocks)
- Any traceback provided is complete
Source: huggingface/trl