Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix Llama4 offset #37414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 10, 2025
Merged

Fix Llama4 offset #37414

merged 2 commits into from
Apr 10, 2025

Conversation

Cyrilvallez
Copy link
Member

@Cyrilvallez Cyrilvallez commented Apr 10, 2025

What does this PR do?

See title. It's the same as before + 1. Indeed, we need to add the +1 to match correctly the positions, it's also what is done in gemma2 here https://github.com/huggingface/transformers/blob/main/src/transformers/models/gemma2/modeling_gemma2.py#L912-L913 as it uses the length (which is equal to cache_position[-1] + 1).
I used first_cache_position - attention_chunk_size + 1 here as I feel it simpler to understand when looking at the cache code (see the 1-offset here https://github.com/huggingface/transformers/blob/main/src/transformers/cache_utils.py#L1921-L1922), but it is striclty equal. I.e. we always have max(first_cache_position - attention_chunk_size + 1, 0) == max(last_cache_position + 1 - key_length, 0)

@github-actions github-actions bot marked this pull request as draft April 10, 2025 08:37
Copy link

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.

@Cyrilvallez Cyrilvallez marked this pull request as ready for review April 10, 2025 08:53
@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

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.

This seems to work better / is simpler thanks

@ArthurZucker ArthurZucker merged commit 6d8b0b3 into main Apr 10, 2025
24 checks passed
@ArthurZucker ArthurZucker deleted the llama4-offset branch April 10, 2025 09:41
ArthurZucker pushed a commit that referenced this pull request Apr 10, 2025
* add +1

* Update modeling_llama4.py
cyr0930 pushed a commit to cyr0930/transformers that referenced this pull request Apr 18, 2025
* add +1

* Update modeling_llama4.py
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.

3 participants