Skip to content

Read ACCELERATE_BYPASS_DEVICE_MAP case-insensitively, like every other boolean flag - #4241

Open
Sreekant13 wants to merge 1 commit into
huggingface:mainfrom
Sreekant13:fix-bypass-device-map-case
Open

Read ACCELERATE_BYPASS_DEVICE_MAP case-insensitively, like every other boolean flag#4241
Sreekant13 wants to merge 1 commit into
huggingface:mainfrom
Sreekant13:fix-bypass-device-map-case

Conversation

@Sreekant13

@Sreekant13 Sreekant13 commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Reads ACCELERATE_BYPASS_DEVICE_MAP case-insensitively, the way every other boolean environment flag in the library is read.

All three sites compared the raw value, so ACCELERATE_BYPASS_DEVICE_MAP=True silently did nothing:

# accelerator.py:1475, 1816, 1890 (before)
os.environ.get("ACCELERATE_BYPASS_DEVICE_MAP", "false") != "true"

It is the only one of eleven such flags read this way. ACCELERATE_USE_FSDP, ACCELERATE_USE_DEEPSPEED, ACCELERATE_USE_MEGATRON_LM, ACCELERATE_USE_SAGEMAKER, ACCELERATE_USE_PARALLELISM_CONFIG, ACCELERATE_ALLOW_CP_STANDALONE, ACCELERATE_DEBUG_MODE, ACCELERATE_DEEPSPEED_ZERO3_SAVE_16BIT_MODEL, FSDP_OFFLOAD_PARAMS and PARALLELISM_CONFIG_SP_SEQ_LENGTH_IS_VARIABLE all .lower() first.

value    BYPASS_DEVICE_MAP   USE_FSDP (sibling, same file)
'true'   True                True
'True'   False               True
'TRUE'   False               True

That inconsistency is what makes it a trap rather than merely strict. True is the spelling a Python user reaches for, and it works for the flag two hundred lines up. When it is ignored the user still hits the device_map='auto' ValueError, whose text does not mention the variable, so nothing points at the value as the cause; the DDP device_ids branch at 1890 takes the non-bypass path for the same reason.

Adding .lower() only widens acceptance to True and TRUE, so no value that works today changes meaning.

Fixes #4240

Before submitting

On that last box, deliberately unticked: the three call sites need a distributed Accelerator and a model loaded with device_map='auto', so a faithful test is heavier than the change. Happy to add one if you would rather have it, and equally happy to route these flags through str_to_bool instead, which would also make them accept 1, yes and on like the library's own documented parser does. I kept that out of here because it is a wider blast radius than a bug fix.

Who can review?

Anyone in the community is free to review the PR once the tests have passed.

…r flag

All three read sites compared the raw value against "true", so
ACCELERATE_BYPASS_DEVICE_MAP=True silently did nothing. It is the only one of
eleven boolean environment flags in the library read this way: USE_FSDP,
USE_DEEPSPEED, USE_MEGATRON_LM, USE_SAGEMAKER, USE_PARALLELISM_CONFIG,
ALLOW_CP_STANDALONE, DEBUG_MODE, DEEPSPEED_ZERO3_SAVE_16BIT_MODEL,
FSDP_OFFLOAD_PARAMS and PARALLELISM_CONFIG_SP_SEQ_LENGTH_IS_VARIABLE all
lowercase first.

That inconsistency is what makes it a trap rather than merely strict: True is
the spelling a Python user reaches for, and it works for ACCELERATE_USE_FSDP
in this same file. When it is ignored the user still hits the
device_map=auto ValueError, whose text does not mention the variable, so
nothing points at the value being the problem; the DDP device_ids branch at
1890 silently takes the non-bypass path for the same reason.

Adding .lower() only widens acceptance to True and TRUE, so no value that
works today changes meaning.

Fixes huggingface#4240.
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.

ACCELERATE_BYPASS_DEVICE_MAP is the only boolean env flag read case-sensitively, so =True is silently ignored

1 participant