Repository navigation
fix(autocast): stream calibration batches instead of materializing all of them #2553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SID-6921
wants to merge
12
commits into
NVIDIA:main
Choose a base branch
from
SID-6921:fix/autocast-calib-stream-batches
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+178
−76
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
929b428
fix(autocast): stream calibration batches instead of materializing al…
SID-6921 532e8af
Address review: trim the changelog entry and track activations in the…
SID-6921 e5b05c2
Track an output activation, not the input feed, in the streaming test
SID-6921 3a1e63e
Merge remote-tracking branch 'origin/main' into fix/autocast-calib-st…
SID-6921 50c5a00
Assert aggregated stats in the streaming regression test
SID-6921 542aff2
Merge remote-tracking branch 'origin/main' into fix/autocast-calib-st…
SID-6921 56689c1
Merge remote-tracking branch 'origin/main' into fix/autocast-calib-st…
SID-6921 3c2449b
Move CHANGELOG entry to the 0.49.0 section
SID-6921 3f92ee0
Merge remote-tracking branch 'origin/main' into fix/autocast-calib-st…
SID-6921 6f21395
Merge branch 'main' into fix/autocast-calib-stream-batches
SID-6921 f33cee6
Merge remote-tracking branch 'origin/main' into fix/autocast-calib-st…
SID-6921 3ed75ee
Fix NaN in first calibration batch poisoning streamed stats permanently
SID-6921 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seeding directly from the first batch changes NaN handling. Previously, aggregation started from
(-inf, inf, -inf)and Pythonmax/minignored a NaN batch reduction. Now, if the first batch contains a NaN, all three statistics start as NaN, and_fold_tensor_statscannot replace them with later finite values (max(nan, value)remains NaN). For example, a NaN first batch followed by an activation of 70000 previously produced absmax=70000; now it produces NaN.IORangeRulethen evaluatesNaN > data_maxas false and may convert that out-of-range node to low precision. Initialize using the previous sentinel-and-fold semantics (or explicitly handle NaN reductions equivalently), and cover this ordering with a regression test.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, this is real. Confirmed it with a quick simulation: NaN first batch then an activation of 70000, old code gives 70000.0, my streaming version gave NaN.
The bug is in how Python's max() handles NaN.
max(acc, x)only replaces acc whenx > acc, and any comparison with NaN is False. The old code always started from -inf/inf sentinels and folded every batch through max()/min(), so a NaN batch lost its comparison and got skipped, same as it would on any later batch. My version seeded stats straight from the first batch's own values, so a NaN there became the running value directly, and no finite batch afterward could ever beat it in the max() comparison.Fixed in 3ed75ee:
_init_tensor_statsnow just creates the sentinel-seeded entries, and the batch loop folds every batch, including the first, through_fold_tensor_stats. Same sentinel-and-fold semantics as before, just streamed.Added
test_multi_batch_nan_first_batch_does_not_poison_stats, reproducing your exact scenario (NaN first batch, finite batch after). Couldn't run the full suite locally (unrelated onnx packaging issue on this machine), but verified the fix against a standalone simulation of your numbers and confirmed it matches the old behavior.