-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Description
Bug Report
Describe the bug
Consider the following test case:
def test_reduce_log_sum_exp_int():
node = oh.make_node("ReduceLogSumExp", inputs=["data"], outputs=["res"])
sess = ReferenceEvaluator(node, optimized=False)
data = np.asarray([1], np.int64)
sess.run(None, {"data": data})Running this function crashes with the following error:
Traceback (most recent call last):
File "<string>", line 17, in __PYTHON_EL_eval
File "/Users/c.bourjau/repos/quantco/onnx-tests/t.py", line 41, in <module>
test_reduce_log_sum_exp_int()
~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/Users/c.bourjau/repos/quantco/onnx-tests/t.py", line 34, in test_reduce_log_sum_exp_int
result, = sess.run(None, {"data": data})
~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
File "/Users/c.bourjau/repos/quantco/onnx-tests/.pixi/envs/default/lib/python3.13/site-packages/onnx/reference/reference_evaluator.py", line 593, in run
outputs = node.run(*inputs, **linked_attributes)
File "/Users/c.bourjau/repos/quantco/onnx-tests/.pixi/envs/default/lib/python3.13/site-packages/onnx/reference/op_run.py", line 472, in run
res = self._run(*args, **kwargs)
File "/Users/c.bourjau/repos/quantco/onnx-tests/.pixi/envs/default/lib/python3.13/site-packages/onnx/reference/ops/op_reduce_log_sum_exp.py", line 45, in _run
return compute_log_sum_exp(data, axes, keepdims)
File "/Users/c.bourjau/repos/quantco/onnx-tests/.pixi/envs/default/lib/python3.13/site-packages/onnx/reference/ops/op_reduce_log_sum_exp.py", line 14, in compute_log_sum_exp
data_max[ind] = -np.inf
~~~~~~~~^^^^^
OverflowError: cannot convert float infinity to integer
The error occurs since __setitem__ must not change the data type of the mutated NumPy array (which is int64 in this case). The specification of the operator explicitly names int64 as a supported data type.
Expected behavior
The ReduceLogSumExp operator is listed as a function in the specification. However, neither Log nor Exp supports integers. While it can still be implemented as a "function" using Cast nodes, it is not clear if this was the intention. The resolution to this issue may either be the realization that the specification should not include integers for this operator (would also apply to ReduceLogSum), or to fix the reference implementation in some way. Either way, the specification should be updated to make the casting behavior explicit.
Notes
This bug was discovered using the onnx-tests project.