Skip to content

Commit b17f6ce

Browse files
NagarsonpggPL
andauthored
[PyTorch] Keep history and scale for zero amax in the unfused DelayedScaling update (#3966)
* [PyTorch] Keep history and scale for zero amax in the unfused DelayedScaling update The fused update skips the history roll and keeps the scale when the current amax is zero (a module that did not run), as documented in fp8_delayed_scaling.rst. The unfused update rotated the history and, with "max", recomputed the scale. Restore both for zero-amax entries, and extend the fused/unfused comparison test to histories of length 4 and 1024. Signed-off-by: Netanel Nagar <277444921+Nagarson@users.noreply.github.com> * [PyTorch] Test two history columns in the fused/unfused update comparison One column carries the case and the other is a control with a positive amax and its own scale, so a change that froze every column would fail. Signed-off-by: Netanel Nagar <277444921+Nagarson@users.noreply.github.com> * Remove comment and test Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> --------- Signed-off-by: Netanel Nagar <277444921+Nagarson@users.noreply.github.com> Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> Co-authored-by: Pawel Gadzinski <pgadzinski@nvidia.com>
1 parent 44f02f2 commit b17f6ce

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎transformer_engine/pytorch/quantization.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,13 +1215,15 @@ def _amax_and_scale_update(
12151215
recipe: DelayedScaling,
12161216
) -> None:
12171217
"""Updates FP8 meta tensors."""
1218+
skip = amax_history[0] == 0
1219+
old_amax_history, old_scale = amax_history.clone(), scale.clone()
12181220
new_amax_history, amax = _compute_amax_and_update_history(
12191221
amax_history,
12201222
recipe.amax_compute_algo,
12211223
)
12221224
new_scale = _compute_scaling_factor(amax, scale, fp8_max, recipe)
1223-
scale.copy_(new_scale)
1224-
amax_history.copy_(new_amax_history)
1225+
scale.copy_(torch.where(skip, old_scale, new_scale))
1226+
amax_history.copy_(torch.where(skip, old_amax_history, new_amax_history))
12251227

12261228

12271229
def split_and_copy(

0 commit comments

Comments
 (0)