Skip to content

GRPO: rollout importance sampling and off-policy sequence mask read top_p / top_k / repetition_penalty as training-inference mismatch #10649

Backlog

Description

@XiaoyuanWang111

Checklist / 检查清单

  • I have searched existing issues, and this is a new bug report. / 我已经搜索过现有的 issues,确认这是一个新的 bug report。

Bug Description / Bug 描述

With use_vllm, GRPO stores vLLM's processed log-probs as the rollout log-probs (logprobs_mode='processed_logprobs' in rollout_mixin.py, swift rollout, the Megatron rollout mixin and the Ray rollout engine). vLLM takes these after repetition_penalty, temperature, min_p, top_k/top_p and structured outputs. The trainer recomputes the old log-probs over the full vocabulary with only the temperature applied (grpo_trainer.py, logits.div_(self.temperature) then selective_log_softmax).

rollout_importance_sampling_mode and off_policy_sequence_mask_delta both consume old - rollout. With top_p < 1, top_k > 0, min_p > 0 or structured_outputs_regex, that difference is the log of the kept probability mass at every token (never positive), and with repetition_penalty != 1 it moves in both directions. So the corrections reweight or mask tokens even when the rollout and training models agree exactly, and the rollout_correction/ metrics report that term as mismatch. No argument check covers the combination; for example --top_p 0.9 --top_k 50 --rollout_importance_sampling_mode token_truncate is accepted silently. TRL refuses the corresponding combinations in GRPOConfig.__post_init__, which ms-swift's GRPOConfig skips. 15 of the 58 GRPO example scripts use top_p and/or top_k.

How to Reproduce / 如何复现

ms-swift main at e7119a6, vLLM 0.11.0 (CPU build), torch 2.8.0, transformers 4.57.6, Qwen2.5-0.5B-Instruct in fp32 on CPU, so the real training-inference mismatch is close to zero. Rollouts through GRPOVllmEngine with processed log-probs, 32 sequences per setting (8 GSM8K-style prompts times 4), temperature 1.0. The old log-probs are recomputed with transformers and selective_log_softmax, then fed to the trainer's own _get_rollout_is_correction, _compute_rollout_offpolicy_metrics and _compute_off_policy_sequence_mask (threshold 2.0, all advantages negative).

Setting tokens with abs(old - rollout) > 1e-3 token IS weights rollout_correction/kl off-policy mask, sequences masked
no truncation, no penalty 0 / 5031 1.000 to 1.000 8.2e-7 0/32 at every delta from 0.001 to 0.1
top_p 0.9 2367 / 5009 0.900 to 1.000 (1460 tokens below 0.99) 0.0148 delta 0.005: 32/32, 0.01: 30/32, 0.02: 2/32
top_p 0.9, top_k 50 2349 / 4915 0.839 to 1.000 (1441 below 0.99) 0.0151 delta 0.01: 32/32, 0.02: 3/32
top_k 80 137 / 5004 0.980 to 1.000 (8 below 0.99) 1.4e-4 0/32 at every delta
repetition_penalty 1.1 3093 / 5045 0.035 to 8.29 (89 tokens clipped at 2.0) 0.0888 delta 0.05: 23/32, 0.1: 11/32

Replaying vLLM's sampler on the trainer logits matches the stored rollout log-probs to within 3.5e-5, so the differences above are the sampling transform alone. With the penalty, tokens already in the prompt or output get a mean ratio of 1.113 and the others 0.805, so the correction puts more weight on the tokens the penalty was meant to discourage.

Additional Information / 补充信息

Proposed fix, which I can open as a PR: raise a ValueError in RLHFArguments._check_grpo (when use_vllm) and in the Megatron _init_grpo when an IS mode or off_policy_sequence_mask_delta is combined with one of these settings, log a warning when only log_rollout_offpolicy_metrics is on, and add a short "Sampling Parameters" note to the training-inference mismatch docs (English and Chinese). Supporting truncated sampling properly would mean renormalizing the trainer log-probs over vLLM's candidate set, as TRL does with return_sampling_mask, which needs a newer vLLM than the versions ms-swift currently recommends.

Activity

  1. added
    bug
    on Nov 30, 2026
  2. hjh0119 commented on Nov 30, 2026

    @hjh0119
    Collaborator

    Thanks for the report. We don't recommend setting top_k/top_p/min_p/repetition_penalty
    (or structured outputs) together with the train-inference alignment features (rollout_importance_sampling_mode,
    off_policy_sequence_mask_delta, log_rollout_offpolicy_metrics): rollout log-probs come from processed_logprobs
    normalized over the truncated set, while the trainer recomputes them over the full vocabulary, so the sampling
    transform itself is read as mismatch. We'll reject this combination (warning for the metrics-only case) and note it
    in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions