`--parallelism_config_sp_seq_length_is_variable False` parses as True
System Info
Repository: huggingface/accelerate
Branch: main
Commit inspected: 2278ebbfd5ee958452f344774d3b7191808a70b9
Area: accelerate launch CLI parser / parallelism_config / DeepSpeed sequence parallelism
This is a static CLI parser bug. I could not run `accelerate env` in the scanning
environment because torch is not installed there, but the issue reproduces with
standard-library argparse before any distributed runtime is involved.
Information
- [ ] The official example scripts
- [x] My own modified scripts
Tasks
- [ ] One of the scripts in the examples/ folder of Accelerate or an officially supported
no_trainerscript in theexamplesfolder of thetransformersrepo (such asrun_no_trainer_glue.py) - [x] My own task or dataset (give details below)
Reproduction
--parallelism_config_sp_seq_length_is_variable is documented as a boolean-like CLI option where False has a meaningful runtime behavior:
- if
True, sequence length may vary between batches; - if
False,parallelism_config_sp_seq_lengthshould match the batch sequence length.
However, the parser currently declares the option with type=bool:
https://github.com/huggingface/accelerate/blob/2278ebbfd5ee958452f344774d3b7191808a70b9/src/accelerate/commands/launch.py#L964-L968
The parsed value is then serialized into the runtime environment:
https://github.com/huggingface/accelerate/blob/2278ebbfd5ee958452f344774d3b7191808a70b9/src/accelerate/utils/launch.py#L421-L423
The runtime config later reads that env var:
https://github.com/huggingface/accelerate/blob/2278ebbfd5ee958452f344774d3b7191808a70b9/src/accelerate/utils/dataclasses.py#L2256-L2259
Minimal reproduction of the parser behavior:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument(
"--parallelism_config_sp_seq_length_is_variable",
type=bool,
default=True,
)
args = parser.parse_args([
"--parallelism_config_sp_seq_length_is_variable",
"False",
])
print(type(args.parallelism_config_sp_seq_length_is_variable).__name__)
print(args.parallelism_config_sp_seq_length_is_variable)
Actual output:
bool
True
A natural accelerate launch command that would hit this is:
accelerate launch \
--use_fsdp \
--fsdp_version 2 \
--use_parallelism_config \
--parallelism_config_sp_size 2 \
--parallelism_config_sp_seq_length 128 \
--parallelism_config_sp_seq_length_is_variable False \
train.py
Because bool("False") is True in Python, the user-provided False is silently converted to True. prepare_extend_env_parallelism_config then writes "True" to PARALLELISM_CONFIG_SP_SEQ_LENGTH_IS_VARIABLE, so DeepSpeedSequenceParallelConfig enables variable sequence length even though the user selected fixed sequence length.
This also skips the fixed-length validation path:
https://github.com/huggingface/accelerate/blob/2278ebbfd5ee958452f344774d3b7191808a70b9/src/accelerate/utils/dataclasses.py#L2261-L2265
Expected behavior
Passing:
--parallelism_config_sp_seq_length_is_variable False
should either:
- parse to a false value and serialize
PARALLELISM_CONFIG_SP_SEQ_LENGTH_IS_VARIABLE=False, or - be rejected as an invalid boolean spelling.
It should not silently parse to True.
A focused fix would be to avoid type=bool for this CLI argument and use the existing textual boolean conversion helper, such as str_to_bool, or paired store_true / store_false flags.
Suggested tests:
- parser test:
--parallelism_config_sp_seq_length_is_variable Falseyields a false value; - env bridge test: the launch env contains
PARALLELISM_CONFIG_SP_SEQ_LENGTH_IS_VARIABLE=Falsefor the same CLI input.
Hi I want to help with the CLI parsing issue. I can try to figure out what is going on and send in a fix. Can you please give the CLI parsing issue to me to work on? I will take a look, at the CLI parsing issue and do my best to fix it.
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.
Please note that issues that do not follow the contributing guidelines are likely to be ignored.