ms-swift icon indicating copy to clipboard operation
ms-swift copied to clipboard

[Bug] In GRPO, documented --max_length does not propagate to TRL max_prompt_length in ms-swift v4.0.0/v4.0.1

Open qinlu000 opened this issue 8 months ago • 1 comments

Checklist / 检查清单

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

Bug Description / Bug 描述

Describe the bug

In ms-swift GRPO, the documentation says that --max_length should represent max_prompt_length in PPO/GRPO/inference scenarios.

However, in practice for ms-swift==4.0.0 (and after checking v4.0.1 / current main, the code path still looks the same), --max_length does not appear to be propagated into trl.GRPOConfig.max_prompt_length.

At the same time, directly passing --max_prompt_length is rejected by the ms-swift CLI parser with:

ValueError: remaining_argv: ['--max_prompt_length', '4096']

So from the user side, there is currently no official CLI path to explicitly set GRPO max_prompt_length, even though the docs
say --max_length should serve this purpose.

### How to Reproduce / 如何复现

### Version

- ms-swift: 4.0.0
- trl: 0.24.0
- vllm: 0.15.1
- python: 3.12
- torch: please fill if needed
- model: Qwen/Qwen3-8B

### Environment

- 2 x RTX 4090 for training
- 2 x RTX 4090 running vLLM rollout servers
- GRPO with Qwen/Qwen3-8B
- non-thinking setup with:
    - --template qwen3_nothinking
    - --enable_thinking false
    - --response_prefix '<think>\n\n</think>\n\n'

### Minimal reproduction

Command:

CUDA_VISIBLE_DEVICES=2,3 \
NPROC_PER_NODE=2 \
swift rlhf \
  --rlhf_type grpo \
  --model Qwen/Qwen3-8B \
  --dataset data/hanabi.grpo.jsonl \
  --use_vllm true \
  --vllm_mode server \
  --vllm_server_host 127.0.0.1 127.0.0.1 \
  --vllm_server_port 8010 8020 \
  --vllm_server_group_port 51216 51217 \
  --num_generations 8 \
  --generation_batch_size 16 \
  --max_length 4096 \
  --max_completion_length 32 \
  --template qwen3_nothinking \
  --enable_thinking false \
  --response_prefix '<think>\n\n</think>\n\n'

Also, trying to pass --max_prompt_length directly fails:

... --max_prompt_length 4096 ...

with:

ValueError: remaining_argv: ['--max_prompt_length', '4096']

### Expected behavior

Either:

1. --max_length should be correctly propagated to trl.GRPOConfig.max_prompt_length, as documented

or

2. --max_prompt_length should be exposed as a valid CLI argument for RLHF/GRPO

### Actual behavior

- trl.GRPOConfig supports max_prompt_length
- ms-swift docs say --max_length should act as max_prompt_length for GRPO
- but the current RLHF argument bridge does not seem to map max_length -> max_prompt_length
- and --max_prompt_length is not accepted by the CLI parser

### Evidence from code

Documentation says max_length should represent max_prompt_length in GRPO:

- swift/arguments/base_args/template_args.py
- in v4.0.0, the docstring for max_length says:
  > In PPO, GRPO, and inference scenarios, this argument specifies the max_prompt_length.

But the argument bridge does not map it in v4.0.0:

- swift/arguments/rlhf_args.py
- RLHFArguments._prepare_training_args() only handles ppo world_size

And training args are filtered by the target config signature before instantiation:

- swift/trainers/trainer_factory.py

Meanwhile trl.GRPOConfig expects:

- max_prompt_length
- max_completion_length

### Additional Information / 补充信息

### Additional notes

I verified locally that a project-side runtime patch which injects:

training_args["max_prompt_length"] = self.max_length

for rlhf_type in {"grpo", "ppo", "gkd"} makes the final serialized GRPOConfig contain:

max_prompt_length=4096

which suggests the missing bridge is the main issue.

### Question

Is this a bug / documentation mismatch?

If intended, what is the official supported way to set GRPO max_prompt_length from the CLI in ms-swift?

qinlu000 avatar Mar 10 '26 04:03 qinlu000

The max_prompt_length parameter is not used in swift; in GRPO, max_length is utilized to handle prompt lengths.

hjh0119 avatar Mar 10 '26 06:03 hjh0119