Skip to content

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
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
@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 <[email protected]>

* Remove dependency on `torch`.

Co-authored-by: Matt <[email protected]>

---------

Co-authored-by: Matt <[email protected]>
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