Skip to content

[Auto] Handle flash_attn distribution mapping KeyError (cluster-45520-3): merged 1 of 2 PRs#37

Open
evalstate wants to merge 2 commits intomainfrom
merge-cluster-cluster-45520-3-20260427115403
Open

[Auto] Handle flash_attn distribution mapping KeyError (cluster-45520-3): merged 1 of 2 PRs#37
evalstate wants to merge 2 commits intomainfrom
merge-cluster-cluster-45520-3-20260427115403

Conversation

@evalstate
Copy link
Copy Markdown
Owner

Cluster: cluster-45520-3
Base ref: origin/main
Branch: merge-cluster-cluster-45520-3-20260427115403

Merged PRs:

Skipped PRs:

Failed PRs:

  • None.

Notes:

Next steps:

SAY-5 and others added 2 commits April 19, 2026 22:44
…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
@evalstate
Copy link
Copy Markdown
Owner Author

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.

2 participants