fix qlinear nan bug#4914
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adjusts MIGraphX’s quantizelinear operator to handle NaN inputs deterministically during quantization, aligning behavior with common ONNX runtime expectations (notably ONNX Runtime CPU EP).
Changes:
- Add explicit NaN handling for integral quantization outputs: NaN inputs now saturate to the quantized type’s minimum value.
- Prevent NaN from flowing through the clamp logic (
std::min/std::max) where it would otherwise silently select the max bound.
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files
🚀 New features to boost your workflow:
|
Regressions detected 🔴 |
|
| output[i] = min_value; | ||
| return; | ||
| } | ||
| auto rounding_mode = fegetround(); |
There was a problem hiding this comment.
But this and the next line out of the visit_all since this does an assignment for each and not needed.
| { | ||
| output[i] = min_value; | ||
| return; | ||
| } |
There was a problem hiding this comment.
If this is consistent with GPU kernels, I think you just need to add this If block and thats it.
| } | ||
| auto rounding_mode = fegetround(); | ||
| fesetround(FE_TONEAREST); | ||
| auto rounded = std::nearbyint(input[i] / scales[i]); |
There was a problem hiding this comment.
Remove this, and just do the nearbyint in the static cast for quantized below.
| auto rounding_mode = fegetround(); | ||
| fesetround(FE_TONEAREST); | ||
| auto rounded = std::nearbyint(input[i] / scales[i]); | ||
| fesetround(rounding_mode); |
There was a problem hiding this comment.
Why are we changing rounding mode again? Is this because we're assigning festround() above per item?
Motivation
ONNX Runtime's CPUExecutionProvider and MIGraphX disagreed on QuantizeLinear output when the input is NaN:
input: [nan]
scale: 0.5
onnxruntime out: [-128]
migraphx out: [ 127] ← MIGraphX
Technical Details
Changelog Category
Add a
CHANGELOG.mdentry for any option other thanNot Applicable