Skip to content

fix(cli): stringify list values from a YAML/JSON config before building argv - #10248

Merged
tastelikefeet merged 1 commit into
modelscope:mainfrom
Lesereingrape:fix/cli-config-list-argv
Sep 26, 2026
Merged

tastelikefeet merged 1 commit into
modelscope:mainfrom
Lesereingrape:fix/cli-config-list-argv

Conversation

@Lesereingrape

Copy link
Copy Markdown
Contributor

PR type

  • Bug Fix
  • Feature
  • Others

PR information

Launching from a YAML/JSON config crashes before the run starts whenever the config sets a documented list parameter whose elements are not strings.

parse_yaml_args converts a scalar value with str(v) and a dict value with json.dumps(v), but appends a list's elements raw:

if isinstance(v, list):
    config_argv += v

so numbers stay numbers in argv, and cli_main then fails on the line that prints the command it is about to exec (swift/cli/main.py:99, and subprocess.run(args) right after it would hit the same thing).

Measured with the current main (c08110b3) and parse_yaml_args called exactly as cli_main calls it:

# config: model + dataset list + `interleave_prob: [0.5, 0.5]`
['--model', 'Qwen/Qwen2.5-7B-Instruct', '--dataset', 'AI-ModelScope/alpaca-gpt4-data-zh', '--interleave_prob', 0.5, 0.5]
' '.join(argv)  ->  TypeError: sequence item 5: expected str instance, float found

# config: {"num_samples": 10, "data_range": [0, 2]}
['--num_samples', '10', '--data_range', 0, 2]
' '.join(argv)  ->  TypeError: sequence item 3: expected str instance, int found

# control, config with only string list values (e.g. `dataset`)
['--model', 'Qwen/Qwen2.5-7B-Instruct', '--dataset', 'AI-ModelScope/alpaca-gpt4-data-zh', 'swift/self-cognition']
' '.join(argv)  ->  ok

These are ordinary parameters, not edge cases: interleave_prob is declared Optional[List[float]] (swift/arguments/base_args/data_args.py:87), data_range is List[int] (swift/arguments/sampling_args.py:73) and vllm_server_port is List[int] (swift/megatron/arguments/megatron_args.py:126). docs/source_en/Instruction/Command-line-parameters.md presents the YAML/JSON launch as supported for swift infer/rlhf/... and megatron sft/rlhf too, and suggests using YAML "for parameters that are infrequently modified" — a string list such as dataset works, and the first numeric list in the same file breaks the launch.

The fix is the one missing conversion, matching what the scalar and dict branches already do:

config_argv += [str(i) for i in v]

The value still arrives unchanged: parse_args(DataArguments, ['--interleave_prob', '0.5', '0.5']) returns [0.5, 0.5], so the launcher only needs strings to join and exec.

Tested with the new tests/utils/test_cli_config_args.py, which pins the two crashing cases and the two cases that must not change (a string list such as dataset, a dict value such as vllm_engine_kwargs):

  • on main before the fix: Ran 4 tests ... FAILED (failures=2), and both failures are the ' '.join(argv) TypeError above;
  • after the fix: Ran 4 tests ... OK;
  • flake8, isort --check-only and yapf --diff report nothing on either file.

Disclosure: this PR was prepared, tested and submitted by an AI agent working on behalf of the account owner.

…ng argv

parse_yaml_args converts scalar values with str() and dict values with json.dumps(), but appends
list elements raw, so a config that sets a documented numeric list (interleave_prob, data_range,
vllm_server_port) leaves floats or ints in argv and cli_main aborts on ' '.join(args).
@tastelikefeet
tastelikefeet merged commit 5380d03 into modelscope:main Sep 26, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants