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

[benchmarks] Set autocast kwargs only if AMP. #6612

Merged
merged 1 commit into from
Feb 26, 2024

Conversation

ysiraichi
Copy link
Collaborator

This PR sets the dtype kwarg only if AMP is supposed to be used. Previously, leaving the dtype kwarg made it so nullcontext complained about it. This would crash every inference benchmark.

cc @miladm

@frgossen
Copy link
Collaborator

Can you give a bit more detail on why this is needed?

@ysiraichi
Copy link
Collaborator Author

ysiraichi commented Feb 26, 2024

Otherwise, we are calling nullcontext(dtype=...), here:

def train(self, inputs, collect_full_output=False):
self._optimizer_zero_grad()
with self.autocast(**self.autocast_kwargs):
pred = self.module(*inputs)
loss = self.compute_loss(pred)

Which ends up raising an error.

Copy link
Collaborator

@frgossen frgossen left a comment

Choose a reason for hiding this comment

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

Thanks!

@ysiraichi ysiraichi merged commit f65bae4 into master Feb 26, 2024
18 checks passed
@vanbasten23
Copy link
Collaborator

Otherwise, we are calling nullcontext(dtype=...), here:

def train(self, inputs, collect_full_output=False):
self._optimizer_zero_grad()
with self.autocast(**self.autocast_kwargs):
pred = self.module(*inputs)
loss = self.compute_loss(pred)

Which ends up raising an error.

Not sure if I follow. With the change, for amp case, we'll call nullcontext(dtype=...) with non-empy kwargs.., wouldn't nullcontext complain too?

@ysiraichi
Copy link
Collaborator Author

As far as I understand it, for AMP case, self.autocast will be either torch.amp.autocast or torch.cuda.autocast. Am I missing something?

amithrm pushed a commit to amithrm/xla that referenced this pull request Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants