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

Make EosTokenCriteria compatible with mps #30376

Merged
merged 1 commit into from Apr 23, 2024
Merged

Make EosTokenCriteria compatible with mps #30376

merged 1 commit into from Apr 23, 2024

Conversation

pcuenca
Copy link
Member

@pcuenca pcuenca commented Apr 21, 2024

What does this PR do?

EOS termination was moved to stopped criteria in #29459. It uses torch.isin(), which is not compatible with the mps device: pytorch/pytorch#77764 (comment). This PR uses the old method to detect whether any of the EOS tokens were found in the generated sequences.

Fixes #29459 (comment)

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?

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

@zucchini-nlp zucchini-nlp left a comment

Choose a reason for hiding this comment

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

Thanks for fixing! Maybe we can leave the old method only and get rid of extra if conditions. Both methods are compile compatible anyway :)

@pcuenca
Copy link
Member Author

pcuenca commented Apr 22, 2024

Yes, good point, I thought about that too. I opted to keep both because the new method is much more readable and intuitive, so it doesn't really add too much noise in my opinion. It also documents why we are using the long approach, and provides a hint (via the link to the github issue) to remove that case when we have full support of isin() for mps at some point in the future. But sure, we can keep just one if that's preferred :)

Copy link
Member

@gante gante left a comment

Choose a reason for hiding this comment

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

Thank you for the fix 🙏

@gante
Copy link
Member

gante commented Apr 22, 2024

I'm pro the if/else: it serves as a reminder to revisit the code in the future, when mps supports this more readable code path

@amyeroberts
Copy link
Collaborator

I'm not sure we should be doing this - the lack of support is really a torch issue, and not a transformers one. There's many operations which are (unfortunately) unsupported by the mps backend, and I wouldn't want to see a tonne of if/else statements across the library to support this. At the moment, PYTORCH_ENABLE_MPS_FALLBACK=1 is the standard approach to try and use mps, which I believe resolves this issue

@ArthurZucker
Copy link
Collaborator

I don't really mind this as it should be mostly for Llama3, but only if that produces the correct outputs. If not, then we should just recommend to use mlx?
@pcuenca does this produce gibberish or same as on cuda?

@ArthurZucker ArthurZucker removed their request for review April 22, 2024 13:16
Copy link
Collaborator

@amyeroberts amyeroberts left a comment

Choose a reason for hiding this comment

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

As discussed internally in slack - https://huggingface.slack.com/archives/C06SW4886G6/p1713567939087889 - happy to merge as it's currently impacting llama 3, but should have an issue created tracking this to make sure it's removed in the future

@pcuenca pcuenca merged commit 4b63d01 into main Apr 23, 2024
21 checks passed
@pcuenca pcuenca deleted the mps-stop-criteria branch April 23, 2024 13:23
@MilesCranmer
Copy link

Thanks so much for the quick fix. Could this get a release?

@ArthurZucker
Copy link
Collaborator

Yes, will do this asap, just waiting to make sure we don't have other failures.

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.

None yet

7 participants