Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions torchao/float8/float8_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ def tensor_to_amax(
else:
assert scaling_granularity is ScalingGranularity.AXISWISE, "unsupported"
assert axiswise_dim is not None, "unsupported"
# Fix for bfloat16 precision amplification in amax_to_scale()
if x.dtype == torch.bfloat16:
x = torch.abs(x).to(torch.float32)
amax = torch.amax(torch.abs(x), dim=axiswise_dim, keepdim=True)

# If the user asked for distributed reduction, do it.
Expand Down
Loading