-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[BugFix] Support bf16 in zero-copy tensor serialization #16860
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be dumb question, but is this conversion lossless? I thought we need to upcast it to fp32 to preserve precision since bf16 and fp16 have different exponents
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
torch.view
doesn't alter the data, it's more like a type cast in C.@njhill -- What I thought of doing here is also this, but perhaps simplified / generalized more ->
And do that in reverse on the decode path. Torch has a bunch of weird 'bits' types that Numpy doesn't support, so probably doing this encoding for every single type doesn't make much sense. WDYT ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ywang96 yes like @p88h said this isn't actually a conversion, it's just temporarily pretending that the raw bf16 data is raw fp16 data.
@p88h I like that idea for a general case but I'm not sure there's any other unsupported types that we care about here tbh, and it means some additional conversions for the common/supported types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@p88h shall we get this merged to address the immediate issue and then you could open a follow-on PR for the above? Then we could microbenchmark it for the supported type cases...
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the more generic variant: #16866
There isn't any more conversions - view() is basically free, the only real difference is that this will now send a longer dtype string since it will use torch naming.
As for what types are there it is quite a bunch - https://pytorch.org/docs/stable/tensors.html
All of the quantized types, custom 8bit floats are not supported by numpy.