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

do not scale gradient in bf16 mode #1036

Merged
merged 1 commit into from
Feb 2, 2023
Merged

Conversation

kashif
Copy link
Contributor

@kashif kashif commented Feb 2, 2023

GradScaler only makes sense in float16 mode and not for bf16 on the GPU. Removed block of code which did this for bf16.

Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

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

Let's just wait a little bit for the conversation in the internal thread to be concluded before merging, but otherwise LGTM!
Thanks for making the fix!

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Feb 2, 2023

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

@kashif
Copy link
Contributor Author

kashif commented Feb 2, 2023

would be great if @stas00 can also have a look 🙇🏽

@stas00
Copy link
Contributor

stas00 commented Feb 2, 2023

I confirm.

bf16 has an almost the same dynamic range as fp32, so no scaling is needed.

In case you want to do another PR, @kashif - the same needs to be fixed in HF Trainer

https://github.com/huggingface/transformers/blob/98d88b23f54e5a23e741833f1e973fdf600cc2c5/src/transformers/trainer.py#L573

probably it should be:

                if self.amp_dtype == torch.float16:
                    self.do_grad_scaling = True

@kashif
Copy link
Contributor Author

kashif commented Feb 2, 2023

sure @stas00 let me get the Trainer fixed

@sgugger sgugger merged commit e89131c into huggingface:main Feb 2, 2023
@kashif kashif deleted the grad-scale branch February 3, 2023 15:14
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

4 participants