torch.onnx.errors.UnsupportedOperatorError: Exporting the operator 'aten::randint' to ONNX opset version 18 is not supported

from here, it seems like aten:randint should be in the onnx exporter. But i am getting the error in the title.
Any advice? Thank you!

You might be using an older PyTorch release. Since the linked PR was merge on July 12, you might need to install a nightly release or build from source.

Thank you for the fast response. I am using the following versions:
pytorch-lightning 1.8.1 pypi_0 pypi
torch 2.0.1+cu117 pypi_0 pypi
torchaudio 2.0.2+cu117 pypi_0 pypi
torchmetrics 0.11.4 pypi_0 pypi
torchvision 0.15.2+cu117 pypi_0 pypi

Is this version still too old? i will try with nightly release first, else build from source.

Yes, torch==2.0.1 is still too old as it was released on May 8 and is based on 2.0.0 from March 15 with a few important fixes.

I see. i shall try out the nightly release.

Just to note, i tried copying over the aten::randint operator over to my current optset version, and it ran with the following error:

File “D:\CH\Anaconda\envs\distraction\lib\site-packages\torch\onnx\”, line 93, in _parse_arg
return [int(v) for v in node_val]
File “D:\CH\Anaconda\envs\distraction\lib\site-packages\”, line 930, in iter
raise TypeError(“iteration over a 0-d tensor”)
TypeError: iteration over a 0-d tensor
(Occurred when translating randint).

Just tried the nightly release. the operator is available but i got the same error as above. I have verified that the model runs properly when not exporting. I am also using the same inference video to act as the dummy input to export.

I don’t understand this statement. How did you verify the operator is available and why does is then still fail?

what i meant is that i can find @_onnx_symbolic("aten::randint") in opset 9 as stated here, when i installed the nightly version. However, i am getting the above error exporting when there is none during inference.

would you reckon that it is due to error on my end or the export code is missing something?

Were you able to run the unit tests which were added in the linked PR? If not, I would guess that your version might still not contain the needed PR.

libraries version:

torch                     2.1.0.dev20230830+cu118          pypi_0    pypi
torchaudio                2.1.0.dev20230830+cu118          pypi_0    pypi
torchmetrics              0.11.4                   pypi_0    pypi
torchvision               0.16.0.dev20230830+cu118          pypi_0    pypi
onnx                      1.14.0                   pypi_0    pypi
onnxruntime-gpu           1.15.1                   pypi_0    pypi

Final output after git clone and running

python -m pytest > test_results.txt

================================================================================ - (too long so only pasted the summary part)

possible to advice?

You didn’t follow up on my previous answer but just posted outputs of an ONNXRT test, so did you run the newly added test shown in the linked PR and if so, was it successful?

In the linked PR, 2 files were changed, namely and Hence, i tried running the ONNXRT test.

sorry if my understanding is incorrect. what test am i suppose to run?