Repository navigation
Use wide accumulation for FLOAT8 weight statistics - #34186
Open
Afloat (Afloat16) wants to merge 2 commits into
Open
Afloat (Afloat16) wants to merge 2 commits into
Afloat (Afloat16) wants to merge 2 commits into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No actionable findings were identified in the FLOAT8 weight-statistics stability change.
No open issues 🎉
What changed in this PR
This PR improves FLOAT8 weight quantization stability by preventing intermediate overflow and underflow when computing FP16/FP32 weight statistics.
Changes:
- Compute standard deviation in float64, then cast the final scale back to the original weight dtype.
- Preserve existing behavior for other input dtypes, the FLOAT8 reference distribution, and zero-variance inputs.
- Add numerical regression tests and a saved-model native CPU dequantization roundtrip.
No actionable findings were identified.
| File | Description |
|---|---|
onnxruntime/test/python/quantization/test_float8_weight_statistics.py |
Adds coverage for extreme weights, scale and code accuracy, dtype compatibility, and native inference. |
onnxruntime/python/tools/quantization/quant_utils.py |
Uses float64 statistics for FP16/FP32 FLOAT8 weight quantization while preserving scale dtype. |
Review effort: Balanced
mirounga
self-requested a review
November 13, 2026 16:04
| from pathlib import Path | ||
|
|
||
| import numpy as np | ||
| import onnx |
Remove the mixed import forms flagged by CodeQL without changing the test behavior.
This branch has not been deployed
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.
Description
FLOAT8 weight quantization computes the input standard deviation in the weight dtype. Finite FP16/FP32 weights can therefore produce an infinite or zero scale when the intermediate squared deviations overflow or underflow. The resulting codes can collapse or contain NaNs even when the final scale is representable.
Accumulate the standard deviation in float64 for FP16/FP32 input weights, then cast the final scale back to the original weight dtype. Other direct-helper input dtypes retain NumPy's existing default statistics/result dtype. The codebook reference distribution and zero-variance policy are unchanged.
Validation
math.fsumstandard-deviation references, quantized FP8 codes, ordinary values/options, readonly strided inputs, zero variance and six other direct-helper input dtypes.DequantizeLinear + Addinference consumes the saved/reloaded FP32-weight quantization result, with persisted scales and codes checked independently.git diff --checkpassed.Exact-source native validation: https://github.com/Afloat16/onnxruntime/actions/runs/43406537495
The runtime was built using the repository's official CPU Release build.py/CMake process at
8dea1194e974fa07b1d2f07a190949c3a92cab80. Its C++ sources match basea8246c0d094f1ab0d6bf236228e5e67683321cd7. This Python-only validation installs that built wheel, overlays the complete quantization package from this exact commit, and verifies byte equality and hashes before normal native imports.Motivation and Context
This repairs the direct FLOAT8 weight-statistics path. Histogram calibration, the codebook distribution, integer quantization and constant-weight policy keep their existing behavior. The tests establish numerical correctness for the covered FP16/FP32 scales; they do not measure end-to-end model accuracy or throughput.