fix(state): make MLU backend part of the _prepare_backend elif chain (#4055)#4057
Open
Anai-Guo wants to merge 1 commit into
Open
fix(state): make MLU backend part of the _prepare_backend elif chain (#4055)#4057Anai-Guo wants to merge 1 commit into
Anai-Guo wants to merge 1 commit into
Conversation
`is_mlu_available()` was checked with a standalone `if` followed by a separate `if is_sdaa_available()` chain, so on an MLU host the cncl/MULTI_MLU selection could be silently overwritten by a later branch (e.g. cuda) instead of short-circuiting. Switch the second `if` to `elif` so all accelerator backends form a single mutually-exclusive chain, matching default_device. Fixes huggingface#4055
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
In
PartialState._prepare_backend, the MLU branch was guarded by a standaloneif, immediately followed by a separateif is_sdaa_available(): ... elif is_musa_available(): ...chain:Because MLU sits outside the mutually-exclusive chain, on an MLU host the
cncl/MULTI_MLUselection is not final: execution falls through into the second chain and a later branch (e.g.torch.cuda.is_available()) can silently overwritebackend/distributed_type. Every other accelerator (SDAA, MUSA, NPU, HPU, CUDA, XPU, NEURON) is already part of oneif/elifchain — MLU is the lone outlier.Fix
Change the second
if is_sdaa_available()toelif, so all backends form a single mutually-exclusive chain with MLU as the head. This matches the structure already used bydefault_device.is_mlu_available()isFalse, so theelifis evaluated exactly as the oldifwas — no behavior change.Closes #4055
🤖 Generated with Claude Code