Repository navigation
[OMNIML-6228] Seed the quantizer tests that compare against the reference at exact rounding ties - #2914
Merged
Conversation
…rounding ties test_per_channel_scale and test_per_tensor_scale of TensorQuantizerTester, and test_per_tensor_scale of TensorQuantCommon, compare a fake-quantized random input with the test's own reference quantizer. The two round an element that sits exactly on a tie (x / step = N.5) in opposite directions, so the outputs are one quantization step apart, which neither rtol=1e-2 nor the default tolerances absorb. Over 20,000 RNG states the unseeded tests fail 8 times for the per-channel test (0.040%, e.g. seeds 1786, 5343, 8185, 11150) and once for each per-tensor test (0.005%, seed 8276); each failure is exactly one element one step off. A serial run draws the same input every time, but under pytest-xdist the RNG state depends on the scheduling, and one such failure hit a unit job of PR #2852. The other methods of TensorQuantCommon pass all 20,000 states. Seed the three tests with 123, as test_per_channel_scale of TensorQuantCommon already does. Under outer RNG states 0..11999, the seeds above included, all three now pass every time. Signed-off-by: Shengliang Xu <shengliangx@nvidia.com>
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
Contributor
Collaborator
Author
|
@coderabbitai review |
Contributor
✅ Action performedReview finished.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2914 +/- ##
==========================================
+ Coverage 70.08% 78.82% +8.74%
==========================================
Files 659 659
Lines 74081 74081
==========================================
+ Hits 51917 58392 +6475
+ Misses 22164 15689 -6475
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
shengliangxu
marked this pull request as ready for review
October 21, 2026 17:02
kevalmorabia97
approved these changes
Oct 21, 2026
Contributor
|
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.
What does this PR do?
Type of change: Bug fix (tests)
TensorQuantizerTester.test_per_channel_scalefailed once in a unit job of PR #2852 (unit-3.12(torch_214, tf_latest), xdist worker gw3). It fake-quantizes an unseeded random tensor and compares the result with the test's own reference quantizer (quantin_test_utils/torch/quantization/quant_utils.py). The two round an element that sits exactly on a tie (x / step = N.5) in opposite directions, so that element ends up one quantization step apart (0.02-0.03 here), whichrtol=1e-2cannot absorb. Reported by the CI speed-up work; I reproduced it.Over 20,000 RNG states on CPU the unseeded tests fail like this:
TensorQuantizerTester.test_per_channel_scaleTensorQuantizerTester.test_per_tensor_scaleTensorQuantCommon.test_per_tensor_scaleEvery failure is exactly one element one step off (seed 1786:
x / step = -74.500000, reference -2.1077, quantizer -2.0796). The other methods ofTensorQuantCommonpass all 20,000 states, and itstest_per_channel_scalealready callstorch.manual_seed(123).A serial run draws the same input every time, so this stayed hidden until pytest-xdist (#2845) made the RNG state depend on the scheduling. About 14 unit jobs of a PR run execute these tests, so a 0.05% failure rate per execution is roughly a 0.7% chance that a PR run needs a re-run.
The three tests now start with
torch.manual_seed(123), like the sibling test does.Usage
N/A
Testing
tests/unit/torch/quantization/test_tensor_quantizer_cpu.pyandtest_tensor_quant_cpu.py: 83 passed.tests/gpu/torch/quantization/test_tensor_quantizer_cuda.pyandtest_tensor_quant_cuda.py. I did not run those on a GPU; a fixed input could in principle tie on the CUDA kernel, which would show up as a deterministic failure in this PR's GPU CI rather than a random one.Before your PR is "Ready for review"
CONTRIBUTING.md: N/ASummary by CodeRabbit