RuntimeError: rINTERNAL ASSERT FAILED at "/media/nvidia/NVME/pytorch/pytorch-v1.9.0/aten/src/ATen/core/jit_type_base.h":184, please report a bug to PyTorch

Tuturoo: <p>I am trying to convert pytorch (.pth) to ONNX for tensorRT. I receive this error.</p>

ptrblck: <p>Could you post a minimal, executable code snippet which would reproduce the issue in the latest release, please?</p>

Tuturoo: <p>from pathlib import Path<br>
import numpy as np<br>
import torch.onnx<br>
from yolov3.utils import utils as utils<br>
from yolov3.models.yolov3 import YOLOv3</p>
<p>config_path = Path( “yolov3_custom.yaml”)<br>
model_path = Path(“yolov3_007000.pth”)<br>
batch_size = 1<br>
config1 = utils.load_config(config_path)</p>
<p>def create_model(config, weights_path=None):<br>
# モデルを作成する。<br>
if config[“model”][“name”] == “yolov3”:<br>
model = YOLOv3(config[“model”])</p>
<pre><code># 重みを読み込む。
if weights_path.suffix == ".pth":
    state = torch.load(weights_path, map_location=lambda storage, loc: storage.cuda(0))
    model.load_state_dict(state["model_state_dict"])
    print(f"state_dict format weights file loaded. {weights_path}")

return model
</code></pre>
<p>torch_model = create_model(config1, model_path)<br>
torch_model.eval()<br>
x = torch.randn(batch_size, 3, 320, 320, requires_grad=True)<br>
torch_out = torch_model(x)</p>
<p>torch.onnx.export(  torch_model,<br>
x,<br>
“model.onnx”,<br>
export_params=True,<br>
opset_version=12,<br>
do_constant_folding=True,<br>
input_names = [‘input’],<br>
output_names = [‘output’],<br>
dynamic_axes = {‘input’ : {0: ‘batch_size’},<br>
‘output’: {0: ‘batch_size’}}<br>
)</p>
<p>I am using Jetson AGX Xavier jetpack 4.6 Ubuntu 18.04</p>

Tuturoo: <p>/media/toyota/9C33-6BBD/hito_line_TensorRT/yolov3/models/yolo_layer.py:122: TracerWarning: torch.tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect.<br>
anchors = torch.tensor(self.anchors, dtype=x.dtype, device=x.device)<br>
/media/toyota/9C33-6BBD/hito_line_TensorRT/yolov3/models/yolo_layer.py:123: TracerWarning: torch.tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect.<br>
all_anchors = torch.tensor(self.all_anchors, dtype=x.dtype, device=x.device)<br>
Traceback (most recent call last):<br>
File “convertONNX.py”, line 43, in <br>
‘output’: {0: ‘batch_size’}}<br>
File “/home/toyota/.local/lib/python3.6/site-packages/torch/onnx/<strong>init</strong>.py”, line 280, in export<br>
custom_opsets, enable_onnx_checker, use_external_data_format)<br>
File “/home/toyota/.local/lib/python3.6/site-packages/torch/onnx/utils.py”, line 94, in export<br>
use_external_data_format=use_external_data_format)<br>
File “/home/toyota/.local/lib/python3.6/site-packages/torch/onnx/utils.py”, line 695, in _export<br>
dynamic_axes=dynamic_axes)<br>
File “/home/toyota/.local/lib/python3.6/site-packages/torch/onnx/utils.py”, line 467, in _model_to_graph<br>
module=module)<br>
File “/home/toyota/.local/lib/python3.6/site-packages/torch/onnx/utils.py”, line 200, in _optimize_graph<br>
graph = torch._C._jit_pass_onnx(graph, operator_export_type)<br>
File “/home/toyota/.local/lib/python3.6/site-packages/torch/onnx/<strong>init</strong>.py”, line 313, in _run_symbolic_function<br>
return utils._run_symbolic_function(*args, **kwargs)<br>
File “/home/toyota/.local/lib/python3.6/site-packages/torch/onnx/utils.py”, line 971, in _run_symbolic_function<br>
return torch._C._jit_onnx_convert_pattern_from_subblock(block, n, env)<br>
File “/home/toyota/.local/lib/python3.6/site-packages/torch/onnx/<strong>init</strong>.py”, line 313, in _run_symbolic_function<br>
return utils._run_symbolic_function(*args, **kwargs)<br>
File “/home/toyota/.local/lib/python3.6/site-packages/torch/onnx/utils.py”, line 994, in <em>run_symbolic_function<br>
return symbolic_fn(g, *inputs, **attrs)<br>
File “/home/toyota/.local/lib/python3.6/site-packages/torch/onnx/symbolic_opset11.py”, line 101, in index_put<br>
if indices_list[idx</em>].type().scalarType() == ‘Bool’:<br>
RuntimeError: rINTERNAL ASSERT FAILED at “/media/nvidia/NVME/pytorch/pytorch-v1.9.0/aten/src/ATen/core/jit_type_base.h”:184, please report a bug to PyTorch.</p>
<p>This is the Full error message</p>

jilei_mao: <p>hi， I get the same error， did you solve it？ <img src="https://discuss.pytorch.org/images/emoji/apple/sweat_smile.png?v=12" title=":sweat_smile:" class="emoji" alt=":sweat_smile:" loading="lazy" width="20" height="20"></p>