Fix KeyError for flash_attn in import_utils.py on Python 3.13Fix #45650
Closed
aryanp2107 wants to merge 1 commit intohuggingface:mainfrom
Closed
Fix KeyError for flash_attn in import_utils.py on Python 3.13Fix #45650aryanp2107 wants to merge 1 commit intohuggingface:mainfrom
aryanp2107 wants to merge 1 commit intohuggingface:mainfrom
Conversation
Contributor
|
View the CircleCI Test Summary for this PR: https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=45650&sha=c0b6ec |
Member
|
There was already an existing PR, please check first before firing your code agent at issues! #45524 |
This was referenced Apr 27, 2026
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 does this PR do?
Fixes #45520
When
flash_attnis not installed, direct dictionary access onPACKAGE_DISTRIBUTION_MAPPING["flash_attn"]throws aKeyErrorbecause the key doesn't exist in the dictionary returned by
importlib.metadata.packages_distributions(). This affects Python 3.13environments where Flash Attention is not available.
Replaced direct dictionary access with
.get()and an empty list defaulton four lines (951, 970, 982, 993), so the list comprehension iterates
over an empty list instead of crashing. This is consistent with the safe
access pattern already used in
_is_package_available()at line 59.Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
@ivarflakstad (listed for AMD ROCm, relevant since the issue was reported on ROCm)