openvpi/DiffSinger

Error exporting to ONNX

github-axel-boidin opened this issue · 3 comments

Hi, I am getting this error and cannot find out how to fix it :

/Users/axel.boidin/miniconda3/envs/diffSinger/lib/python3.8/site-packages/torch/onnx/utils.py:847: UserWarning: no signature found for <torch.ScriptMethod object at 0x2a5005400>, skipping _decide_input_format
  warnings.warn(f"{e}, skipping _decide_input_format")
Traceback (most recent call last):
  File "scripts/export.py", line 231, in <module>
    main()
  File "/Users/axel.boidin/miniconda3/envs/diffSinger/lib/python3.8/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/Users/axel.boidin/miniconda3/envs/diffSinger/lib/python3.8/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/Users/axel.boidin/miniconda3/envs/diffSinger/lib/python3.8/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/axel.boidin/miniconda3/envs/diffSinger/lib/python3.8/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/axel.boidin/miniconda3/envs/diffSinger/lib/python3.8/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "scripts/export.py", line 134, in acoustic
    exporter.export(out)
  File "/Users/axel.boidin/Music/devForMusic/DiffSinger/deployment/exporters/acoustic_exporter.py", line 94, in export
    self.export_model(path / f'{model_name}.onnx')
  File "/Users/axel.boidin/Music/devForMusic/DiffSinger/deployment/exporters/acoustic_exporter.py", line 98, in export_model
    self._torch_export_model()
  File "/Users/axel.boidin/miniconda3/envs/diffSinger/lib/python3.8/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "/Users/axel.boidin/Music/devForMusic/DiffSinger/deployment/exporters/acoustic_exporter.py", line 233, in _torch_export_model
    torch.onnx.export(
  File "/Users/axel.boidin/miniconda3/envs/diffSinger/lib/python3.8/site-packages/torch/onnx/utils.py", line 516, in export
    _export(
  File "/Users/axel.boidin/miniconda3/envs/diffSinger/lib/python3.8/site-packages/torch/onnx/utils.py", line 1596, in _export
    graph, params_dict, torch_out = _model_to_graph(
  File "/Users/axel.boidin/miniconda3/envs/diffSinger/lib/python3.8/site-packages/torch/onnx/utils.py", line 1139, in _model_to_graph
    graph = _optimize_graph(
  File "/Users/axel.boidin/miniconda3/envs/diffSinger/lib/python3.8/site-packages/torch/onnx/utils.py", line 677, in _optimize_graph
    graph = _C._jit_pass_onnx(graph, operator_export_type)
  File "/Users/axel.boidin/miniconda3/envs/diffSinger/lib/python3.8/site-packages/torch/onnx/utils.py", line 1940, in _run_symbolic_function
    return symbolic_fn(graph_context, *inputs, **attrs)
  File "/Users/axel.boidin/miniconda3/envs/diffSinger/lib/python3.8/site-packages/torch/onnx/symbolic_opset9.py", line 7065, in prim_if
    torch._C._jit_pass_onnx_block(
  File "/Users/axel.boidin/miniconda3/envs/diffSinger/lib/python3.8/site-packages/torch/onnx/utils.py", line 1940, in _run_symbolic_function
    return symbolic_fn(graph_context, *inputs, **attrs)
  File "/Users/axel.boidin/miniconda3/envs/diffSinger/lib/python3.8/site-packages/torch/onnx/symbolic_opset9.py", line 6976, in prim_loop
    torch._C._jit_pass_onnx_block(
  File "/Users/axel.boidin/miniconda3/envs/diffSinger/lib/python3.8/site-packages/torch/onnx/utils.py", line 1940, in _run_symbolic_function
    return symbolic_fn(graph_context, *inputs, **attrs)
  File "/Users/axel.boidin/miniconda3/envs/diffSinger/lib/python3.8/site-packages/torch/onnx/symbolic_helper.py", line 395, in wrapper
    return fn(g, *args, **kwargs)
  File "/Users/axel.boidin/miniconda3/envs/diffSinger/lib/python3.8/site-packages/torch/onnx/symbolic_opset9.py", line 1417, in relu
    return _op_with_optional_float_cast(g, "Relu", input, opset_before=14)
  File "/Users/axel.boidin/miniconda3/envs/diffSinger/lib/python3.8/site-packages/torch/onnx/symbolic_opset9.py", line 1381, in _op_with_optional_float_cast
    dtype_0 = _type_utils.JitScalarType.from_value(inputs[0])
  File "/Users/axel.boidin/miniconda3/envs/diffSinger/lib/python3.8/site-packages/torch/onnx/_type_utils.py", line 215, in from_value
    raise errors.SymbolicValueError(
torch.onnx.errors.SymbolicValueError: Cannot determine scalar type for this '<class 'torch.TensorType'>' instance and a default value was not provided.  [Caused by the value 'input.3 defined in (%input.3 : Tensor = onnx::Conv[dilations=[1], group=1, kernel_shape=[1], pads=[0, 0], strides=[1]](%input, %diffusion.denoise_fn.input_projection.weight, %diffusion.denoise_fn.input_projection.bias), scope: deployment.modules.toplevel.DiffSingerAcousticONNX::/deployment.modules.diffusion.GaussianDiffusionONNX::diffusion/modules.diffusion.wavenet.WaveNet::denoise_fn/modules.diffusion.wavenet.Conv1d::input_projection # /Users/axel.boidin/miniconda3/envs/diffSinger/lib/python3.8/site-packages/torch/nn/modules/conv.py:306:0
)' (type 'Tensor') in the TorchScript graph. The containing node has kind 'onnx::Conv'.] 

The containing node has kind 'onnx::Conv'.] 
    (node defined in /Users/axel.boidin/miniconda3/envs/diffSinger/lib/python3.8/site-packages/torch/nn/modules/conv.py(306): _conv_forward
/Users/axel.boidin/miniconda3/envs/diffSinger/lib/python3.8/site-packages/torch/nn/modules/conv.py(310): forward
/Users/axel.boidin/miniconda3/envs/diffSinger/lib/python3.8/site-packages/torch/nn/modules/module.py(1508): _slow_forward
/Users/axel.boidin/miniconda3/envs/diffSinger/lib/python3.8/site-packages/torch/nn/modules/module.py(1527): _call_impl
/Users/axel.boidin/miniconda3/envs/diffSinger/lib/python3.8/site-packages/torch/nn/modules/module.py(1518): _wrapped_call_impl
/Users/axel.boidin/Music/devForMusic/DiffSinger/modules/diffusion/wavenet.py(100): forward
/Users/axel.boidin/miniconda3/envs/diffSinger/lib/python3.8/site-packages/torch/nn/modules/module.py(1508): _slow_forward
/Users/axel.boidin/miniconda3/envs/diffSinger/lib/python3.8/site-packages/torch/nn/modules/module.py(1527): _call_impl
/Users/axel.boidin/miniconda3/envs/diffSinger/lib/python3.8/site-packages/torch/nn/modules/module.py(1518): _wrapped_call_impl
/Users/axel.boidin/miniconda3/envs/diffSinger/lib/python3.8/site-packages/torch/jit/_trace.py(1065): trace_module
/Users/axel.boidin/miniconda3/envs/diffSinger/lib/python3.8/site-packages/torch/jit/_trace.py(798): trace
/Users/axel.boidin/Music/devForMusic/DiffSinger/deployment/exporters/acoustic_exporter.py(202): _torch_export_model
/Users/axel.boidin/miniconda3/envs/diffSinger/lib/python3.8/site-packages/torch/utils/_contextlib.py(115): decorate_context
/Users/axel.boidin/Music/devForMusic/DiffSinger/deployment/exporters/acoustic_exporter.py(98): export_model
/Users/axel.boidin/Music/devForMusic/DiffSinger/deployment/exporters/acoustic_exporter.py(94): export
scripts/export.py(134): acoustic
/Users/axel.boidin/miniconda3/envs/diffSinger/lib/python3.8/site-packages/click/core.py(783): invoke
/Users/axel.boidin/miniconda3/envs/diffSinger/lib/python3.8/site-packages/click/core.py(1434): invoke
/Users/axel.boidin/miniconda3/envs/diffSinger/lib/python3.8/site-packages/click/core.py(1688): invoke
/Users/axel.boidin/miniconda3/envs/diffSinger/lib/python3.8/site-packages/click/core.py(1078): main
/Users/axel.boidin/miniconda3/envs/diffSinger/lib/python3.8/site-packages/click/core.py(1157): __call__
scripts/export.py(231): <module>
)

    Inputs:
        #0: input defined in (%input : Tensor = onnx::If(%261), scope: deployment.modules.toplevel.DiffSingerAcousticONNX::/deployment.modules.diffusion.GaussianDiffusionONNX::diffusion/modules.diffusion.wavenet.WaveNet::denoise_fn # /Users/axel.boidin/Music/devForMusic/DiffSinger/modules/diffusion/wavenet.py:97:0
      block0():
        %263 : Long(1, strides=[1], device=cpu) = onnx::Constant[value={1}](), scope: deployment.modules.toplevel.DiffSingerAcousticONNX::/deployment.modules.diffusion.GaussianDiffusionONNX::diffusion/modules.diffusion.wavenet.WaveNet::denoise_fn
        %264 : Float(*, *, *, device=cpu) = onnx::Squeeze(%x.41, %263), scope: deployment.modules.toplevel.DiffSingerAcousticONNX::/deployment.modules.diffusion.GaussianDiffusionONNX::diffusion/modules.diffusion.wavenet.WaveNet::denoise_fn
        -> (%264)
      block1():
        %265 : Float(*, *, *, *, device=cpu) = onnx::Identity(%x.41), scope: deployment.modules.toplevel.DiffSingerAcousticONNX::/deployment.modules.diffusion.GaussianDiffusionONNX::diffusion/modules.diffusion.wavenet.WaveNet::denoise_fn
        -> (%265)
    )  (type 'Tensor')

... plus the model description. Do you have any clue how to fix this?

What version of PyTorch are you using? ONNX export currently requires 1.13

Ok I was using the 2.1. I will try with the 1.13.

It seems to be working like a charm!! thank you for your very quick answer. Apparently I was able to export the model learn on pytorch 2.1 using this 1.13 version.