Skip to content

Fix: Disable torch.autocast in RotaryEmbedding of Gemma and LLaMa for MPS device#29439

Merged
ArthurZucker merged 3 commits intohuggingface:mainfrom
currybab:fix-gemma-generate
Mar 6, 2024
Merged

Fix: Disable torch.autocast in RotaryEmbedding of Gemma and LLaMa for MPS device#29439
ArthurZucker merged 3 commits intohuggingface:mainfrom
currybab:fix-gemma-generate

Conversation

@currybab
Copy link
Copy Markdown
Contributor

@currybab currybab commented Mar 4, 2024

What does this PR do?

Fixes #29431

The issue on MPS devices was caused by the merge of #29285 in version 4.38.2.

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?

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.

Copy link
Copy Markdown
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.

That is indeed a problem. Was not aware that autocast is not available for mps.
We probably need to do a patch for this!
I think we can use cpu device even if the tensors are not on CPU no?

Comment thread src/transformers/models/gemma/modeling_gemma.py Outdated
currybab and others added 2 commits March 6, 2024 12:39
@currybab currybab requested a review from ArthurZucker March 6, 2024 13:56
Copy link
Copy Markdown
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 thank you for the prompt fix

@ArthurZucker ArthurZucker merged commit d45f47a into huggingface:main Mar 6, 2024
@ArthurZucker
Copy link
Copy Markdown
Collaborator

FYI @fxmarty and @gante !

@ArthurZucker
Copy link
Copy Markdown
Collaborator

I have not tested this with compile but the dtype should be alright to check / we can always check self.dtype to not be input dependant

@Tran-Thanh1991
Copy link
Copy Markdown

Hi everybody. I'm having the same error, does anyone know how to fix it?

RuntimeError: User specified an unsupported autocast device_type 'cuda:0'

image

@ArthurZucker
Copy link
Copy Markdown
Collaborator

Do you have a reproducer?

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.

RuntimeError: User specified an unsupported autocast device_type 'mps'

3 participants