Skip to content
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

Gemma2: eager attention by default #32865

Merged
merged 2 commits into from
Aug 22, 2024
Merged

Conversation

gante
Copy link
Member

@gante gante commented Aug 17, 2024

What does this PR do?

See title :)

We know that SDPA yields inferior modeling results, so we should use eager by default. This has been the source of some model quality GH issues, e.g. #32848

Slow tests for gemma 2 ran, no regressions

@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.

Comment on lines +105 to +106
config._attn_implementation = "sdpa"
model = Gemma2Model(config)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here we should check that you can set the attention in the canonical way - rather than overriding the private attribute

Suggested change
config._attn_implementation = "sdpa"
model = Gemma2Model(config)
model = Gemma2Model(config, attn_implementation="sdpa")

Copy link
Member Author

Choose a reason for hiding this comment

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

@amyeroberts hehe I had the same idea, but this actually doesn't work :D

The API you're suggesting is for .from_pretrained(), not for __init__()

Copy link
Collaborator

Choose a reason for hiding this comment

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

we can pass _attn_implementation I think no?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The API you're suggesting is for .from_pretrained(), not for init()

Oh, true!

we can pass _attn_implementation I think no?

I don't think we can for the model init as it just accepts config as an input arg

Comment on lines +105 to +106
config._attn_implementation = "sdpa"
model = Gemma2Model(config)
Copy link
Collaborator

Choose a reason for hiding this comment

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

we can pass _attn_implementation I think no?

@gante gante merged commit 975b988 into huggingface:main Aug 22, 2024
21 checks passed
@gante gante deleted the gemma_2_eager_default branch August 22, 2024 14:59
zucchini-nlp pushed a commit to zucchini-nlp/transformers that referenced this pull request Aug 30, 2024
zucchini-nlp pushed a commit to zucchini-nlp/transformers that referenced this pull request Aug 30, 2024
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.

4 participants