[Auto] Handle flash_attn distribution mapping KeyError (cluster-45520-3): merged 1 of 2 PRs#37
Open
[Auto] Handle flash_attn distribution mapping KeyError (cluster-45520-3): merged 1 of 2 PRs#37
Conversation
…not in the distribution map
is_flash_attn_2_available / _3 / _4 / _greater_or_equal do two checks:
is_available, _ = _is_package_available("flash_attn", return_version=True)
is_available = is_available and "flash-attn" in [
pkg.replace("_", "-") for pkg in PACKAGE_DISTRIBUTION_MAPPING["flash_attn"]
]
Step 1 uses importlib.util.find_spec, which returns a spec if any
"flash_attn" import is findable (an editable install, a namespace
package, a bundled shim, or a stub module under another project).
Step 2 then assumes that every findable import name also has an entry
in importlib.metadata.packages_distributions().
That assumption does not hold. On Python 3.13 with ComfyUI setups
(huggingface#45520), and in any environment where the import is resolvable via a
non-pip source, packages_distributions() has no "flash_attn" key.
Because the list comprehension is evaluated before the `in` operator,
short-circuit evaluation of the outer `and` does not protect us - the
KeyError fires during `transformers` import and takes down the whole
process before any model is loaded.
Swap the four raising subscripts for `.get(name, [])`. If the name is
missing from the distribution map we simply conclude that the requested
flash-attention flavour is not properly installed - which is the same
answer is_flash_attn_*_available() would have returned anyway - instead
of raising. The inner helper `_is_package_available` already wraps the
same subscript in a try/except, so we are only making the outer call
sites match that contract.
Fixes huggingface#45520
…/transformers into merge-cluster-cluster-45520-3-20260427115403
Owner
Author
|
Trace for this mergeability run: https://huggingface.co/datasets/evalstate/transformers-merge-experiments/blob/main/2604271308-nO0tEB__dev__codex.jsonl |
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.
Cluster: cluster-45520-3
Base ref: origin/main
Branch: merge-cluster-cluster-45520-3-20260427115403
Merged PRs:
.get(..., [])to avoid KeyError.Skipped PRs:
is_flash_attn_3_available()change appears unrelated/risky.Failed PRs:
Notes:
https://github.com/huggingface/transformers.gitsucceeded.4bbd2407c4and is ahead oforigin/mainby 2 commits.python -m compileall -q src/transformers/utils/import_utils.pysucceeded.Next steps:
make style; run broadermake check-repoif resources allow.