You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The OneHot operator CPU EP implementation features a division operation in calculating the output shape. When the indices input has a shape with a zero dimension, this results in UB here since divide by zero is undefined. On gcc/Linux I get a runtime floating point exception whereas on MacOS/clang 0 is propagated through.
In the ONNX specification for OneHot it states:
The rank of the output tensor will be one greater than the rank of the input tensor.
I believe the correct behaviour when having input indices of shape (0,) and depth with value k should be an output tensor of shape (0, k).
To reproduce
importspox.opset.ai.onnx.v17asopfromspoximportargument, build, Tensorimportnumpyasnpimportonnxruntimeasortif__name__=="__main__":
x=argument(Tensor(np.int64, ("N",)))
cats= [1, 2]
y=op.one_hot(x, op.const([len(cats)], dtype="int64"), op.const([0, 1], dtype="int64"))
mp=build({"x": x}, {"y": y})
s=ort.InferenceSession(mp.SerializeToString())
out=s.run(None, {"x": np.array([], dtype="int64").reshape(0,)})
print(out) # On MacOS I get [array([], shape=(0, 2), dtype=int64)] whereas on Linux I get a ``Floating point exception (core dumped)
Describe the issue
The OneHot operator CPU EP implementation features a division operation in calculating the output shape. When the
indices
input has a shape with a zero dimension, this results in UB here since divide by zero is undefined. On gcc/Linux I get a runtime floating point exception whereas on MacOS/clang 0 is propagated through.In the ONNX specification for OneHot it states:
I believe the correct behaviour when having input
indices
of shape(0,)
anddepth
with valuek
should be an output tensor of shape(0, k)
.To reproduce
Urgency
No response
Platform
Linux
OS Version
4.18
ONNX Runtime Installation
Built from Source
ONNX Runtime Version or Commit ID
1.17.3
ONNX Runtime API
Python
Architecture
X64
Execution Provider
Default CPU
Execution Provider Library Version
No response
LLDB step through on debug build on MacOS:
The text was updated successfully, but these errors were encountered: