﻿# ONNX Runtime QLinearSoftmax: saturate before converting a large requantized value

The 1.32 QLinearSoftmax repair checks requantization range before integer conversion; singleton and small-scale tests can expose hidden overflow.

Author: Retrivium team
Updated: 2026-11-15
Canonical URL: https://retrivium.ai/journal/week46-engine-ort-qlinearsoftmax-saturation-before-cast/
Language: en

ONNX Runtime 1.32.0 includes a CPU QLinearSoftmax overflow repair using wider intermediates and saturation before integer conversion. Upstream demonstrates that a quantized optimization could otherwise turn a near-one result into zero. The relevant boundary is requantization, so a correct floating softmax reference alone does not validate the integer output path.

## A bounded probability can yield a large code

Softmax probabilities remain bounded, but dividing by a small output scale can create a large intermediate integer-code value. The probability bound therefore does not make every conversion safe. The PR widens intermediate work and clamps before conversion. A proposed test should compute the real-valued reference, apply scale and zero point, then perform the documented rounding and saturation sequence in a range that avoids reference overflow.

## Singleton reductions are useful edge cases

A single-element softmax has an easily understood probability result, making the output quantizer the main object of the test. Upstream includes this kind of regression alongside other scales and output types. Add signed and unsigned cases with meaningful zero points. A long random vector can spread probabilities enough to avoid the extreme code value, so workload size does not substitute for deliberately chosen numeric boundaries.

## Compare the optimized graph too

A QDQ rewrite can select the quantized operator even when the source model expresses floating operations around quantization nodes. Verify the rewrite’s numerical equivalence, not merely direct kernel execution. Keep an optimization-disabled control and inspect whether the expected fusion occurs. This distinguishes a fixed kernel from a test that accidentally avoided it. The PR explicitly includes QDQ regression coverage, while its reported platform limitations should remain attributed.

## Wider intermediates can affect boundary rounding

Upstream notes that near-tie outputs may differ by a quantization unit. A local acceptance criterion should reflect the intended rounding contract rather than demanding preservation of an overflowed old answer. This article reports the release mechanism and proposed tests, without claiming new cross-platform measurements or a universal model-quality improvement. The useful evidence is correct code-range handling on the actual quantized graph and provider being deployed.

## Sources

- [ONNX Runtime v1.32.0 release](https://github.com/microsoft/onnxruntime/releases/tag/v1.32.0)
- [ONNX Runtime pull request #33277](https://github.com/microsoft/onnxruntime/pull/33277)

## Related reading

- [ONNX QuantizeLinear: the scale shape and axis define what is quantized together](/journal/fg2-onnx-quantize-linear-axis-scale-contract/)
- [ONNX Runtime offline optimization: a saved optimized graph inherits a target contract](/journal/fg2-onnxruntime-offline-graph-target-compatibility/)
