Repository navigation
[PyTorch] Keep history and scale for zero amax in the unfused DelayedScaling update - #3966
Merged
Merged
Conversation
…Scaling 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>
Contributor
[Medium impact] The PR appears safe to merge, with a non-blocking request to restore regression coverage. Summary
Reviews (3) · Last reviewed commit: "Remove comment and test" · Reviewed by Greptile |
…ison 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>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I have reviewed the change and its test. I understand that it keeps the previous scale and amax history when the current amax is zero, making the unfused update consistent with the fused update.
Description
When the current amax is zero (a module that did not run this step), the unfused amax/scale update (
NVTE_UNFUSED_FP8_UPDATE=1, or a callableamax_compute_algo/scaling_factor_compute_algo) rotates the amax history, and withmaxit recomputes the scale from the older entries.fp8_delayed_scaling.rstdocuments: "its history is not rotated and scale remains unchanged"._amax_and_scale_updaterestores the history and the scale of every entry whose current amax is zero. It also extends the fused/unfused comparison, which used a history of length 1 only, to lengths 4 and 1024.Fixes #3965
Tested on an RTX 4090 (sm89) with torch 2.14.1+cu130 and TE 2.21.0 from PyPI, with this patch applied to the installed package. The new test ran as a standalone file with the same code.
maxandmost_recent× history 4 and 1024).TestFP8Recipeintests/pytorch/test_recipe.py: 40 passed, 4 skipped, both before and after.Type of change
Changes
transformer_engine/pytorch/quantization.py:_amax_and_scale_updatekeeps the amax history and the scale of entries whose current amax is zero.tests/pytorch/test_recipe.py:test_fused_and_unfused_update_agree_on_history. It covers history lengths 4 and 1024, algorithmsmaxandmost_recent, and positive, inf-in-window and zero-current amaxes.Checklist: