Skip to content

Fix KeyError for flash_attn in import_utils.py on Python 3.13Fix #45650

Closed
aryanp2107 wants to merge 1 commit intohuggingface:mainfrom
aryanp2107:fix-flash-attn-keyerror
Closed

Fix KeyError for flash_attn in import_utils.py on Python 3.13Fix #45650
aryanp2107 wants to merge 1 commit intohuggingface:mainfrom
aryanp2107:fix-flash-attn-keyerror

Conversation

@aryanp2107
Copy link
Copy Markdown

What does this PR do?

Fixes #45520

When flash_attn is not installed, direct dictionary access on
PACKAGE_DISTRIBUTION_MAPPING["flash_attn"] throws a KeyError
because the key doesn't exist in the dictionary returned by
importlib.metadata.packages_distributions(). This affects Python 3.13
environments where Flash Attention is not available.

Replaced direct dictionary access with .get() and an empty list default
on 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.

  • [ x ] I confirm that this is not a pure code agent PR.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • [ x ] Did you read the contributor guideline,
    Pull Request section?
  • [ x ] Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

@ivarflakstad (listed for AMD ROCm, relevant since the issue was reported on ROCm)

@github-actions
Copy link
Copy Markdown
Contributor

View the CircleCI Test Summary for this PR:

https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=45650&sha=c0b6ec

@Rocketknight1
Copy link
Copy Markdown
Member

There was already an existing PR, please check first before firing your code agent at issues! #45524

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.

KeyError: 'flash_attn' in import_utils.py when running on Python 3.13

2 participants