Fix: Stable implementation for ReduceLogSumExp (ONNX frontend)
Summary #32839
This patch fixes numerical instability in the ONNX frontend’s ReduceLogSumExp operator.
The previous implementation used a naïve log(sum(exp(x))) formulation, which overflowed to Inf for
values near log(MAX_FLOAT32) (≈ 88.72). This caused incorrect results in the OpenVINO EP of ONNX Runtime,
especially for float16 and float32 models.
Fix
Implemented a numerically stable LogSumExp computation:
k = ReduceMax(x)
lse = k + log( ReduceSum( exp(x - k) ) )
This matches the behavior of:
- ONNX Runtime CPU EP
- PyTorch and NumPy stable LogSumExp
- OpenVINO PyTorch frontend implementation (
log.cpp)
The new implementation is applied to:
- Opset 1–12 (
opset_1::reduce_log_sum_exp) - Opset 13–17 (
opset_13::reduce_log_sum_exp) - Opset 18+ (
opset_18::reduce_log_sum_exp)
Motivation
Fixes incorrect Inf outputs for values ≥ 88.7 when using OpenVINOExecutionProvider.
The issue was originally reported here: [link to GitHub issue].
Validation
Tested using provided reproduction script from the issue:
- Matches ONNX Runtime CPU EP for all tested values
- No overflow observed for large positive inputs
- Behavior consistent across float16/float32 models
Notes
This fix aligns ONNX frontend behavior with the already-correct PyTorch frontend implementation.
could someone of the team approve the CI workflows to move this forward?