Skip to content
Open
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
4 changes: 2 additions & 2 deletions heavyball/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ def __init__(self, correction, smax):
self.smax = smax

def decode(self, x):
ls = (_log_ulp(x) - 1).float()
ls = _log_ulp(x).float()
return x.float() + _scale_by_exp2(self.correction.float() / self.smax, ls)

@staticmethod
Expand All @@ -1141,7 +1141,7 @@ def _bf16_to_f32(x):
def compute_correction(self, fp32, narrow):
narrow_f32 = self._bf16_to_f32(narrow) if narrow.dtype == torch.bfloat16 else narrow.float()
e = fp32 - narrow_f32
ls = (_log_ulp(narrow) - 1).float()
ls = _log_ulp(narrow).float()
e_norm = _scale_by_exp2(e, -ls)
scaled = e_norm.clamp(-1.0, 1.0) * self.smax
self.correction.copy_(scaled.abs().add(0.5).floor().copysign(scaled).to(self.correction.dtype))
Expand Down