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

Handle bfloat16 weights in disk offload #460

Merged
merged 2 commits into from
Jun 21, 2022
Merged

Handle bfloat16 weights in disk offload #460

merged 2 commits into from
Jun 21, 2022

Conversation

sgugger
Copy link
Collaborator

@sgugger sgugger commented Jun 21, 2022

This PR handles a bug reported in #454 concerning bfloat16 and disk offload.
NumPy does not support bfloat16, so while storing those tensors on disk, we need to convert them back as float32 (can't convert them in float16 without losing precision). This not super efficient but it's the best we can offer until NumPy offers support for this dtype.

A new test is added to check the offload on disk with bfloat16 works. It doesn't need any specialized hardware since we don't do anything on the bfloat16 tensor.

@sgugger sgugger requested a review from muellerzr June 21, 2022 20:23
@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Jun 21, 2022

The documentation is not available anymore as the PR was closed or merged.

Copy link
Collaborator

@muellerzr muellerzr left a comment

Choose a reason for hiding this comment

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

One small comment/question there about the tests

dtypes.append(torch.bfloat16)

for dtype in dtypes:
weight = torch.tensor([[1, 2, 3], [4, 5, 6]], dtype=dtype)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we care about the prevision here, would it be a good idea to test these with floats that marginally get close to the float16 reach to ensure they're lossless?

E.g.:

weight = torch.rand((2,3), dtype=dtype)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Probably yes 😅

@sgugger sgugger merged commit e2a968c into main Jun 21, 2022
@sgugger sgugger deleted the bfloat16_offload branch June 21, 2022 22:06
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.

3 participants