Skip to content

Conversation

@winglian
Copy link
Contributor

@winglian winglian commented Apr 6, 2025

What does this PR do?

#37307 (llama4) introduced a regression in make_flex_block_causal_mask with new optional args that llama4 uses. It also added padding, but padding only works if the key_length isn't None. For all models except llama4, flex attention is now broken since none of them pass key_length, and currently they error with.

[rank3]:   File "/root/miniconda3/envs/py3.11/lib/python3.11/site-packages/torch/nn/functional.py", line 5209, in pad                                                                                                                                        
[rank3]:     return torch._C._nn.pad(input, pad, mode, value)                                                                                                                                                                                                
[rank3]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                                                                
[rank3]: TypeError: pad(): argument 'pad' failed to unpack the object at pos 2 with error "type must be tuple of ints,but got NoneType"                                                                                                                      

Also, the batch size was likely mistakenly hard-coded to 1, which probably shouldn't be the case.

Fixes # (issue)

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • 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?

@ArthurZucker

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@github-actions
Copy link
Contributor

github-actions bot commented Apr 6, 2025

Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. The CI will be paused while the PR is in draft mode. When it is ready for review, please click the Ready for review button (at the bottom of the PR page). This will assign reviewers and trigger CI.

Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ArthurZucker
Copy link
Collaborator

Thanks for the prompt fix!

@ArthurZucker ArthurZucker merged commit 54538eb into huggingface:main Apr 7, 2025
18 of 20 checks passed
@winglian winglian deleted the flex-attn-fix branch April 7, 2025 10:24
vasqu pushed a commit to vasqu/transformers that referenced this pull request Apr 7, 2025
@ArthurZucker ArthurZucker added the for patch Tag issues / labels that should be included in the next patch label Apr 7, 2025
cyr0930 pushed a commit to cyr0930/transformers that referenced this pull request Apr 18, 2025
zucchini-nlp pushed a commit to zucchini-nlp/transformers that referenced this pull request May 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

for patch Tag issues / labels that should be included in the next patch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants