Pth2onnx couldn't export python method

username: diplomatist
cooked: <p>/home/hx/anaconda3/envs/py38_TensorRT/bin/python /home/hx/TensorRT/Palette-infer-demo/Palette-Image-to-Image-Diffusion-Models-main/pth2onnx.py<br>
/home/hx/anaconda3/envs/py38_TensorRT/lib/python3.8/site-packages/torch/nn/functional.py:2515: UserWarning: <strong>floordiv</strong> is deprecated, and its behavior will change in a future version of pytorch. It currently rounds toward 0 (like the ‘trunc’ function NOT ‘floor’). This results in incorrect rounding for negative values. To keep the current behavior, use torch.div(a, b, rounding_mode=‘trunc’), or for actual floor division, use torch.div(a, b, rounding_mode=‘floor’).<br>
_verify_batch_size([input.size(0) * input.size(1) // num_groups, num_groups] + list(input.size()[2:]))<br>
/home/hx/TensorRT/Palette-infer-demo/Palette-Image-to-Image-Diffusion-Models-main/models/guided_diffusion_modules/unet.py:271: UserWarning: <strong>floordiv</strong> is deprecated, and its behavior will change in a future version of pytorch. It currently rounds toward 0 (like the ‘trunc’ function NOT ‘floor’). This results in incorrect rounding for negative values. To keep the current behavior, use torch.div(a, b, rounding_mode=‘trunc’), or for actual floor division, use torch.div(a, b, rounding_mode=‘floor’).<br>
ch = width // (3 * self.n_heads)<br>
/home/hx/TensorRT/Palette-infer-demo/Palette-Image-to-Image-Diffusion-Models-main/models/guided_diffusion_modules/unet.py:273: TracerWarning: Converting a tensor to a Python float might cause the trace to be incorrect. We can’t record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!<br>
scale = 1 / math.sqrt(math.sqrt(ch))<br>
/home/hx/anaconda3/envs/py38_TensorRT/lib/python3.8/site-packages/torch/onnx/utils.py:461: UserWarning: no signature found for &lt;torch.ScriptMethod object at 0x7fe79c132720&gt;, skipping _decide_input_format<br>
warnings.warn(“%s, skipping _decide_input_format” % e)<br>
Traceback (most recent call last):<br>
File “/home/hx/TensorRT/Palette-infer-demo/Palette-Image-to-Image-Diffusion-Models-main/pth2onnx.py”, line 55, in <br>
torch.onnx.export(unet_script, input, onnx_model, opset_version=13)<br>
File “/home/hx/anaconda3/envs/py38_TensorRT/lib/python3.8/site-packages/torch/onnx/<strong>init</strong>.py”, line 350, in export<br>
return utils.export(<br>
File “/home/hx/anaconda3/envs/py38_TensorRT/lib/python3.8/site-packages/torch/onnx/utils.py”, line 163, in export<br>
_export(<br>
File “/home/hx/anaconda3/envs/py38_TensorRT/lib/python3.8/site-packages/torch/onnx/utils.py”, line 1074, in _export<br>
graph, params_dict, torch_out = _model_to_graph(<br>
File “/home/hx/anaconda3/envs/py38_TensorRT/lib/python3.8/site-packages/torch/onnx/utils.py”, line 727, in _model_to_graph<br>
graph, params, torch_out, module = _create_jit_graph(model, args)<br>
File “/home/hx/anaconda3/envs/py38_TensorRT/lib/python3.8/site-packages/torch/onnx/utils.py”, line 582, in _create_jit_graph<br>
module, params = _C._jit_onnx_list_model_parameters(freezed_m)<br>
RuntimeError:<br>
Couldn’t export Python method.:</p>
<p>The error message did not indicate which operator is incompatible, and I am unable to locate the specific error location.</p>

username: diplomatist
cooked: <p>The problem has been resolved, Couldn’t export Python method The areas that indicate incompatibility do not belong to modules, but rather to Python methods. My model uses the checkpoint function in Python to save memory and accelerate, while onnx does not support checkpoint function acceleration.</p>