Skip to content

Support the --accelerate_config=<name> equals-sign CLI syntax - #6953

Closed
amanyagami wants to merge 1 commit into
huggingface:mainfrom
amanyagami:fix/accelerate-config-cli-parsing
Closed

Support the --accelerate_config=<name> equals-sign CLI syntax#6953
amanyagami wants to merge 1 commit into
huggingface:mainfrom
amanyagami:fix/accelerate-config-cli-parsing

Conversation

@amanyagami

@amanyagami amanyagami commented Aug 28, 2026

Copy link
Copy Markdown

What does this PR do?

trl.cli.accelerate_config.resolve_accelerate_config_argument() is responsible for turning
--accelerate_config <name_or_path> on the trl <command> CLI into the --config_file <path> argument that gets
forwarded to accelerate launch. It only recognized the two-token form
(--accelerate_config single_gpu): it looks up "--accelerate_config" as a standalone element of launch_args
with launch_args.index("--accelerate_config") and reads the following element as the value.

The equals-sign form that argparse-style CLIs commonly support, --accelerate_config=single_gpu, doesn't match
that lookup at all. Because "--accelerate_config" not in launch_args is true in that case, the function returns
launch_args unchanged, --accelerate_config=single_gpu gets passed straight through to accelerate launch
(which has no idea what to do with it) instead of being resolved to --config_file .../single_gpu.yaml, and the
requested config is silently ignored.

Root cause

resolve_accelerate_config_argument() assumed --accelerate_config and its value are always two separate argv
elements, with no handling for the --flag=value form.

Fix

Before doing the existing lookup, scan launch_args for an element starting with "--accelerate_config=", and if
found, split it into the two-token form (["--accelerate_config", "<value>"]) and rebuild launch_args with that
substitution. The rest of the function is untouched and now only ever has to deal with the two-token form, so both
syntaxes resolve identically (same --config_file <path> output and remaining args preserved).

Tests

Added tests/test_cli_accelerate_config.py with regression tests for:

  • the two-token form still works,
  • the new --accelerate_config=<name> form resolves correctly,
  • both forms produce the exact same output for the same input,
  • --accelerate_config absent from args is a no-op,
  • missing value after --accelerate_config still raises ValueError,
  • an invalid config name still raises ValueError, for both syntaxes.

I confirmed these tests fail on main (3 of the 6 fail: the equals-form test, the equivalence test, and the
invalid-name-for-equals-form test) and pass after the fix.

Test output (after fix)

$ python -m pytest tests/test_cli_accelerate_config.py -v
============================= test session starts ==============================
platform linux -- Python 3.12.12, pytest-9.1.1, pluggy-1.6.0
collected 6 items

tests/test_cli_accelerate_config.py::TestResolveAccelerateConfigArgument::test_two_token_form PASSED [ 16%]
tests/test_cli_accelerate_config.py::TestResolveAccelerateConfigArgument::test_equals_form PASSED [ 33%]
tests/test_cli_accelerate_config.py::TestResolveAccelerateConfigArgument::test_equals_form_matches_two_token_form PASSED [ 50%]
tests/test_cli_accelerate_config.py::TestResolveAccelerateConfigArgument::test_no_accelerate_config_argument PASSED [ 66%]
tests/test_cli_accelerate_config.py::TestResolveAccelerateConfigArgument::test_missing_value_raises PASSED [ 83%]
tests/test_cli_accelerate_config.py::TestResolveAccelerateConfigArgument::test_invalid_config_name_raises PASSED [100%]

============================== 6 passed in 7.95s ===============================

Also ran the full existing CLI test suite to check for regressions:

$ python -m pytest tests/test_cli_utils.py tests/test_cli_accelerate_config.py -q
.........................................                                [100%]
41 passed in 41.92s

pre-commit run --files trl/cli/accelerate_config.py tests/test_cli_accelerate_config.py passes (ruff check, ruff
format, doc-builder style check all green).

Fixes #6874

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline, Pull Request section?
  • Was this discussed/approved via a GitHub issue? Please add a link to it if that's the case.
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

AI writing disclosure

We welcome the use of AI tools to help with contributions. For transparency and to help us improve our review process, please indicate the level of AI involvement in this PR.

  • No AI usage: the PR was written entirely by a human.
  • AI-assisted: some parts were suggested or improved by AI, but the PR was written and reviewed by a human.
  • AI-generated: the PR was mostly or fully generated by an AI tool.

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag members/contributors who may be interested in your PR.


Note

Low Risk
Small, localized CLI argument parsing change with dedicated tests; no auth, data, or training logic touched.

Overview
Fixes a bug where --accelerate_config=single_gpu was passed through to accelerate launch unchanged instead of being rewritten to --config_file with the bundled YAML path.

resolve_accelerate_config_argument now normalizes any --accelerate_config=<value> argv token into the existing two-token form before lookup, so both CLI styles behave the same and the rest of the resolver is unchanged.

Adds tests/test_cli_accelerate_config.py with regression coverage for both forms, equivalence, no-op when the flag is absent, missing values, and invalid config names (including equals form).

Reviewed by Cursor Bugbot for commit deb6ae0. Bugbot is set up for automated code reviews on this repo. Configure here.

resolve_accelerate_config_argument() only recognized the two-token
form (--accelerate_config single_gpu). The equals-sign form
(--accelerate_config=single_gpu), which argparse-style CLIs commonly
support, was left untouched in the launch args and passed straight
through to accelerate, which doesn't understand --accelerate_config
at all, silently ignoring the requested config instead of resolving
it to --config_file.

Normalize the =-joined form into the two-token form up front so the
rest of the function only has to handle a single case; both syntaxes
now resolve identically.

Fixes huggingface#6874
@DaoyuanLi2816

DaoyuanLi2816 commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Correction to my earlier overlap note: the earliest implementation is #6875, opened on August 23 for #6874. It already covers both CLI spellings, empty-value validation, trailing arguments, and CLI integration. Linking the canonical earlier PR so the implementations can be consolidated rather than reviewed independently.

@amanyagami

Copy link
Copy Markdown
Author

Closing in favor of #6875, which was opened earlier (Aug 23) and covers the same fix (both CLI spellings, empty-value validation, trailing arguments, CLI integration tests). Thanks @DaoyuanLi2816 for the pointer — apologies for the duplicate effort.

@amanyagami amanyagami closed this Aug 28, 2026
@amanyagami
amanyagami deleted the fix/accelerate-config-cli-parsing branch August 29, 2026 08:20
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.

Bug: normalize --accelerate_config=<name> CLI syntax

2 participants