Skip to content

Commit

Permalink
[benchmarks] Fix AMP data-type. (pytorch#6550)
Browse files Browse the repository at this point in the history
  • Loading branch information
ysiraichi authored and amithrm committed Mar 1, 2024
1 parent c6f9170 commit 63f33cd
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions benchmarks/torchbench_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,16 @@ def conversion_dtype(self):
return torch.bfloat16

def _get_autocast_with_kwargs(self):
kwargs = {}

# Set the default data-type based on the accelerator.
if self.benchmark_experiment.accelerator == "cuda":
kwargs["dtype"] = torch.float16
else:
# Both CPU and TPU autocast mode defaults to bfloat16.
kwargs["dtype"] = torch.bfloat16

if self.use_amp():
kwargs = {"dtype": torch.bfloat16}
if self.benchmark_experiment.xla:
# Should call device specific autocast implementations.
# PyTorch/XLA autocast does not run with dynamo, though:
Expand All @@ -394,7 +402,6 @@ def _get_autocast_with_kwargs(self):
else:
autocast = torch.cuda.amp.autocast
else:
kwargs = {}
autocast = contextlib.nullcontext
return (autocast, kwargs)

Expand Down

0 comments on commit 63f33cd

Please sign in to comment.