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

Added support for bfloat16 to zero-shot classification pipeline #33554

Merged
merged 3 commits into from
Sep 18, 2024

Conversation

umarbutler
Copy link
Contributor

This PR fixes #33386 and adds support for models that output logits in torch.bfloat16 in the zero-shot classification pipeline by casting logits to torch.float32 before they are converted to numpy floats (instead of attempting a direct conversion, which is currently not possible and raises TypeError: Got unsupported ScalarType BFloat16).

@Rocketknight1

Copy link
Member

@Rocketknight1 Rocketknight1 left a comment

Choose a reason for hiding this comment

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

Hey, the idea looks good but remember that this code can also run TensorFlow pipelines! I added a suggestion where we gate your line behind if self.framework == "pt", which should make the tests pass. I also used .float() so we can avoid the import torch at the top, which causes TF problems again.

umarbutler and others added 2 commits September 19, 2024 00:29
Co-authored-by: Matt <Rocketknight1@users.noreply.github.com>
Co-authored-by: Matt <Rocketknight1@users.noreply.github.com>
@umarbutler
Copy link
Contributor Author

@Rocketknight1 Makes sense, thanks for the improvements, I've committed them all.

Copy link
Member

@Rocketknight1 Rocketknight1 left a comment

Choose a reason for hiding this comment

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

Yes, LGTM now. Thank you for the fix, it's really appreciated!

@Rocketknight1 Rocketknight1 merged commit fc83a4d into huggingface:main Sep 18, 2024
16 checks passed
@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.

BernardZach pushed a commit to BernardZach/transformers that referenced this pull request Dec 5, 2024
…ingface#33554)

* Added support for bfloat16 to zero-shot classification pipeline

* Ensure support for TF.

Co-authored-by: Matt <Rocketknight1@users.noreply.github.com>

* Remove dependency on `torch`.

Co-authored-by: Matt <Rocketknight1@users.noreply.github.com>

---------

Co-authored-by: Matt <Rocketknight1@users.noreply.github.com>
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.

Zero-shot classification pipeline does not support bfloat16
3 participants