asteroid-team / asteroid

The PyTorch-based audio source separation toolkit for researchers
https://asteroid-team.github.io/
MIT License
2.24k stars 421 forks source link

Exporting ConvTasNet to ONNX seems to be broken in >0.3.5 #530

Open iver56 opened 3 years ago

iver56 commented 3 years ago

🐛 Bug

When I try to export a ConvTasNet model to ONNX, I get various error messages. See more info below.

To Reproduce

import torch
from asteroid import ConvTasNet

model = ConvTasNet(n_src=1)

input_tensor = torch.zeros(1, 1, 12000, dtype=torch.float32)

model_output = model(input_tensor)

print(model_output.shape)

torch.onnx.export(
    model,  # model being run
    input_tensor,  # model input (or a tuple for multiple inputs)
    'hello_convtasnet.onnx',  # where to save the model (can be a file or file-like object)
    export_params=True,  # store the trained parameter weights inside the model file
    opset_version=11,  # the ONNX version to export the model to
    do_constant_folding=True,  # whether to execute constant folding for optimization
    input_names=["input"],  # the model's input names
    output_names=["output"],  # the model's output names
)

Expected behavior

I expect that the code runs without errors, and I expect to see a ~19 MB file called hello_convtasnet.onnx. I also want to be able to run the ONNX model with onnxruntime.

Environment

I've tried to run the code above in various environments/configurations:

asteroid 0.3.4, pytorch 1.7.1, opset_version=10 (I edited the value to this in the code), Windows

C:\Users\iver5\Anaconda3\envs\my_python_env-gpu\lib\site-packages\asteroid\filterbanks\enc_dec.py:169: TracerWarning: Converting a tensor to a Python boolean 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!
  if channels == 1 and self.as_conv1d:
Traceback (most recent call last):
  File "C:\Users\iver5\Anaconda3\envs\my_python_env-gpu\lib\site-packages\torch\onnx\symbolic_opset9.py", line 900, in _convert_padding_node
    padding = [sym_help._get_const(v, 'i', 'padding') for v in input_list]
  File "C:\Users\iver5\Anaconda3\envs\my_python_env-gpu\lib\site-packages\torch\onnx\symbolic_opset9.py", line 900, in <listcomp>
    padding = [sym_help._get_const(v, 'i', 'padding') for v in input_list]
  File "C:\Users\iver5\Anaconda3\envs\my_python_env-gpu\lib\site-packages\torch\onnx\symbolic_helper.py", line 105, in _get_const
    raise RuntimeError("ONNX symbolic expected a constant value of the {} argument, got `{}`".format(arg_name, value))
RuntimeError: ONNX symbolic expected a constant value of the padding argument, got `3108 defined in (%3108 : Long(requires_grad=0, device=cpu) = onnx::Sub(%3100, %3106) # C:\Users\iver5\Anaconda3\envs\my_python_env-gpu\lib\site-packages\asteroid\utils\torch_utils.py:73:0
)`

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/iver5/Code/my_python_env/my_python_env/noise_reducer_pytorch/conv_tas_net_onnx_playground.py", line 20, in <module>
    output_names=["output"],  # the model's output names
  File "C:\Users\iver5\Anaconda3\envs\my_python_env-gpu\lib\site-packages\torch\onnx\__init__.py", line 230, in export
    custom_opsets, enable_onnx_checker, use_external_data_format)
  File "C:\Users\iver5\Anaconda3\envs\my_python_env-gpu\lib\site-packages\torch\onnx\utils.py", line 91, in export
    use_external_data_format=use_external_data_format)
  File "C:\Users\iver5\Anaconda3\envs\my_python_env-gpu\lib\site-packages\torch\onnx\utils.py", line 639, in _export
    dynamic_axes=dynamic_axes)
  File "C:\Users\iver5\Anaconda3\envs\my_python_env-gpu\lib\site-packages\torch\onnx\utils.py", line 421, in _model_to_graph
    dynamic_axes=dynamic_axes, input_names=input_names)
  File "C:\Users\iver5\Anaconda3\envs\my_python_env-gpu\lib\site-packages\torch\onnx\utils.py", line 203, in _optimize_graph
    graph = torch._C._jit_pass_onnx(graph, operator_export_type)
  File "C:\Users\iver5\Anaconda3\envs\my_python_env-gpu\lib\site-packages\torch\onnx\__init__.py", line 263, in _run_symbolic_function
    return utils._run_symbolic_function(*args, **kwargs)
  File "C:\Users\iver5\Anaconda3\envs\my_python_env-gpu\lib\site-packages\torch\onnx\utils.py", line 934, in _run_symbolic_function
    return symbolic_fn(g, *inputs, **attrs)
  File "C:\Users\iver5\Anaconda3\envs\my_python_env-gpu\lib\site-packages\torch\onnx\symbolic_opset9.py", line 912, in constant_pad_nd
    padding = _convert_padding_node(padding)
  File "C:\Users\iver5\Anaconda3\envs\my_python_env-gpu\lib\site-packages\torch\onnx\symbolic_opset9.py", line 902, in _convert_padding_node
    return sym_help._onnx_opset_unsupported_detailed('Pad', 9, 11, 'The sizes of the padding must be constant')
  File "C:\Users\iver5\Anaconda3\envs\my_python_env-gpu\lib\site-packages\torch\onnx\symbolic_helper.py", line 196, in _onnx_opset_unsupported_detailed
    'opset {}. {}. Please try opset version {}.'.format(op_name, current_opset, reason, supported_opset))
RuntimeError: Unsupported: ONNX export of Pad in opset 9. The sizes of the padding must be constant. Please try opset version 11.

Process finished with exit code 1

asteroid 0.3.5, pytorch 1.7.1, ONNX opset version 11, Windows

It executes/exports without errors


asteroid 0.3.5, pytorch 1.8.0, ONNX opset version 11, Windows

It executes/exports without errors


asteroid 0.4.5, pytorch 1.7.1, ONNX opset version 11, Windows

C:\Users\iver5\Anaconda3\envs\my_python_env-gpu\lib\site-packages\asteroid\masknn\convolutional.py:206: 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.
  skip_connection = torch.tensor([0.0], device=output.device)
Traceback (most recent call last):
  File "C:/Users/iver5/Code/my_python_env/my_python_env/noise_reducer_pytorch/conv_tas_net_onnx_playground.py", line 20, in <module>
    output_names=["output"],  # the model's output names
  File "C:\Users\iver5\Anaconda3\envs\my_python_env-gpu\lib\site-packages\torch\onnx\__init__.py", line 230, in export
    custom_opsets, enable_onnx_checker, use_external_data_format)
  File "C:\Users\iver5\Anaconda3\envs\my_python_env-gpu\lib\site-packages\torch\onnx\utils.py", line 91, in export
    use_external_data_format=use_external_data_format)
  File "C:\Users\iver5\Anaconda3\envs\my_python_env-gpu\lib\site-packages\torch\onnx\utils.py", line 639, in _export
    dynamic_axes=dynamic_axes)
  File "C:\Users\iver5\Anaconda3\envs\my_python_env-gpu\lib\site-packages\torch\onnx\utils.py", line 421, in _model_to_graph
    dynamic_axes=dynamic_axes, input_names=input_names)
  File "C:\Users\iver5\Anaconda3\envs\my_python_env-gpu\lib\site-packages\torch\onnx\utils.py", line 203, in _optimize_graph
    graph = torch._C._jit_pass_onnx(graph, operator_export_type)
  File "C:\Users\iver5\Anaconda3\envs\my_python_env-gpu\lib\site-packages\torch\onnx\__init__.py", line 263, in _run_symbolic_function
    return utils._run_symbolic_function(*args, **kwargs)
  File "C:\Users\iver5\Anaconda3\envs\my_python_env-gpu\lib\site-packages\torch\onnx\utils.py", line 934, in _run_symbolic_function
    return symbolic_fn(g, *inputs, **attrs)
  File "C:\Users\iver5\Anaconda3\envs\my_python_env-gpu\lib\site-packages\torch\onnx\symbolic_opset9.py", line 1567, in tensor
    dtype = data.type().scalarType()
RuntimeError: r INTERNAL ASSERT FAILED at "..\\aten\\src\\ATen/core/jit_type.h":171, please report a bug to PyTorch. 

asteroid 0.4.0rc0, pytorch 1.8.0, ONNX opset version 11, Windows

C:\Users\iver5\Anaconda3\lib\site-packages\asteroid\masknn\convolutional.py:187: 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.
  skip_connection = torch.tensor([0.0], device=output.device)
Warning: ONNX Preprocess - Removing mutation on block inputs. This changes graph semantics.
Warning: ONNX Preprocess - Removing mutation on block inputs. This changes graph semantics.
Warning: ONNX Preprocess - Removing mutation on block inputs. This changes graph semantics.
Traceback (most recent call last):
  File "C:\Users\iver5\Anaconda3\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\iver5\Anaconda3\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\iver5\Code\my_python_env\my_python_env\noise_reducer_pytorch\conv_tas_net_onnx_playground.py", line 12, in <module>
    torch.onnx.export(
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\__init__.py", line 271, in export
    return utils.export(model, args, f, export_params, verbose, training,
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\utils.py", line 88, in export
    _export(model, args, f, export_params, verbose, training, input_names, output_names,
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\utils.py", line 691, in _export
    _model_to_graph(model, args, verbose, input_names,
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\utils.py", line 460, in _model_to_graph
    graph = _optimize_graph(graph, operator_export_type,
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\utils.py", line 206, in _optimize_graph
    graph = torch._C._jit_pass_onnx(graph, operator_export_type)
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\__init__.py", line 309, in _run_symbolic_function
    return utils._run_symbolic_function(*args, **kwargs)
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\utils.py", line 994, in _run_symbolic_function
    return symbolic_fn(g, *inputs, **attrs)
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\symbolic_opset9.py", line 344, in wrapper
    return overload(g, *args)
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\symbolic_helper.py", line 142, in wrapper
    args = [_parse_arg(arg, arg_desc, arg_name, fn_name)  # type: ignore
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\symbolic_helper.py", line 142, in <listcomp>
    args = [_parse_arg(arg, arg_desc, arg_name, fn_name)  # type: ignore
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\symbolic_helper.py", line 93, in _parse_arg
    raise RuntimeError("Expected node type 'onnx::Constant' "
RuntimeError: Expected node type 'onnx::Constant' for argument 'dim' of node 'reduce_dim', got 'onnx::Range'.

asteroid 0.4.5, pytorch 1.8.0, ONNX opset version 11, Windows

C:\Users\iver5\Anaconda3\lib\site-packages\asteroid\masknn\convolutional.py:187: 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.
  skip_connection = torch.tensor([0.0], device=output.device)
Warning: ONNX Preprocess - Removing mutation on block inputs. This changes graph semantics.
Warning: ONNX Preprocess - Removing mutation on block inputs. This changes graph semantics.
Warning: ONNX Preprocess - Removing mutation on block inputs. This changes graph semantics.
Traceback (most recent call last):
  File "C:\Users\iver5\Anaconda3\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\iver5\Anaconda3\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\iver5\Code\my_python_env\my_python_env\noise_reducer_pytorch\conv_tas_net_onnx_playground.py", line 12, in <module>
    torch.onnx.export(
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\__init__.py", line 271, in export
    return utils.export(model, args, f, export_params, verbose, training,
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\utils.py", line 88, in export
    _export(model, args, f, export_params, verbose, training, input_names, output_names,
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\utils.py", line 691, in _export
    _model_to_graph(model, args, verbose, input_names,
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\utils.py", line 460, in _model_to_graph
    graph = _optimize_graph(graph, operator_export_type,
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\utils.py", line 206, in _optimize_graph
    graph = torch._C._jit_pass_onnx(graph, operator_export_type)
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\__init__.py", line 309, in _run_symbolic_function
    return utils._run_symbolic_function(*args, **kwargs)
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\utils.py", line 994, in _run_symbolic_function
    return symbolic_fn(g, *inputs, **attrs)
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\symbolic_opset9.py", line 344, in wrapper
    return overload(g, *args)
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\symbolic_helper.py", line 142, in wrapper
    args = [_parse_arg(arg, arg_desc, arg_name, fn_name)  # type: ignore
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\symbolic_helper.py", line 142, in <listcomp>
    args = [_parse_arg(arg, arg_desc, arg_name, fn_name)  # type: ignore
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\symbolic_helper.py", line 93, in _parse_arg
    raise RuntimeError("Expected node type 'onnx::Constant' "
RuntimeError: Expected node type 'onnx::Constant' for argument 'dim' of node 'reduce_dim', got 'onnx::Range'.

asteroid 0.4.5, pytorch 1.8.0, ONNX opset version 11, torchaudio==0.8.0, Windows

C:\Users\iver5\Anaconda3\lib\site-packages\asteroid\masknn\convolutional.py:187: 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.
  skip_connection = torch.tensor([0.0], device=output.device)
Warning: ONNX Preprocess - Removing mutation on block inputs. This changes graph semantics.
Warning: ONNX Preprocess - Removing mutation on block inputs. This changes graph semantics.
Warning: ONNX Preprocess - Removing mutation on block inputs. This changes graph semantics.
Traceback (most recent call last):
  File "C:\Users\iver5\Anaconda3\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\iver5\Anaconda3\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\iver5\Code\my_python_env\my_python_env\noise_reducer_pytorch\conv_tas_net_onnx_playground.py", line 12, in <module>
    torch.onnx.export(
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\__init__.py", line 271, in export
    return utils.export(model, args, f, export_params, verbose, training,
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\utils.py", line 88, in export
    _export(model, args, f, export_params, verbose, training, input_names, output_names,
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\utils.py", line 691, in _export
    _model_to_graph(model, args, verbose, input_names,
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\utils.py", line 460, in _model_to_graph
    graph = _optimize_graph(graph, operator_export_type,
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\utils.py", line 206, in _optimize_graph
    graph = torch._C._jit_pass_onnx(graph, operator_export_type)
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\__init__.py", line 309, in _run_symbolic_function
    return utils._run_symbolic_function(*args, **kwargs)
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\utils.py", line 994, in _run_symbolic_function
    return symbolic_fn(g, *inputs, **attrs)
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\symbolic_opset9.py", line 344, in wrapper
    return overload(g, *args)
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\symbolic_helper.py", line 142, in wrapper
    args = [_parse_arg(arg, arg_desc, arg_name, fn_name)  # type: ignore
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\symbolic_helper.py", line 142, in <listcomp>
    args = [_parse_arg(arg, arg_desc, arg_name, fn_name)  # type: ignore
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\symbolic_helper.py", line 93, in _parse_arg
    raise RuntimeError("Expected node type 'onnx::Constant' "
RuntimeError: Expected node type 'onnx::Constant' for argument 'dim' of node 'reduce_dim', got 'onnx::Range'.

asteroid 0.4.5, pytorch 1.9.0, ONNX opset version 11, torchaudio==0.9.0, Windows

C:\Users\iver5\Anaconda3\lib\site-packages\asteroid\masknn\convolutional.py:206: 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.
  skip_connection = torch.tensor([0.0], device=output.device)
Traceback (most recent call last):
  File "C:\Users\iver5\Anaconda3\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\iver5\Anaconda3\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\iver5\Code\my_python_env\my_python_env\noise_reducer_pytorch\conv_tas_net_onnx_playground.py", line 12, in <module>
    torch.onnx.export(
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\__init__.py", line 275, in export
    return utils.export(model, args, f, export_params, verbose, training,
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\utils.py", line 88, in export
    _export(model, args, f, export_params, verbose, training, input_names, output_names,
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\utils.py", line 689, in _export
    _model_to_graph(model, args, verbose, input_names,
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\utils.py", line 463, in _model_to_graph
    graph = _optimize_graph(graph, operator_export_type,
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\utils.py", line 200, in _optimize_graph
    graph = torch._C._jit_pass_onnx(graph, operator_export_type)
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\__init__.py", line 313, in _run_symbolic_function
    return utils._run_symbolic_function(*args, **kwargs)
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\utils.py", line 994, in _run_symbolic_function
    return symbolic_fn(g, *inputs, **attrs)
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\symbolic_opset9.py", line 389, in wrapper
    return overload(g, *args)
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\symbolic_helper.py", line 166, in wrapper
    args = [_parse_arg(arg, arg_desc, arg_name, fn_name)  # type: ignore[assignment]
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\symbolic_helper.py", line 166, in <listcomp>
    args = [_parse_arg(arg, arg_desc, arg_name, fn_name)  # type: ignore[assignment]
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\symbolic_helper.py", line 93, in _parse_arg
    raise RuntimeError("Expected node type 'onnx::Constant' "
RuntimeError: Expected node type 'onnx::Constant' for argument 'dim' of node 'reduce_dim', got 'onnx::Range'.

asteroid 0.5.1, pytorch 1.9.0, ONNX opset version 11, torchaudio==0.9.0, Windows

C:\Users\iver5\Anaconda3\lib\site-packages\asteroid\masknn\convolutional.py:205: 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.
  skip_connection = torch.tensor([0.0], device=output.device)
Traceback (most recent call last):
  File "C:\Users\iver5\Anaconda3\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\iver5\Anaconda3\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\iver5\Code\my_python_env\my_python_env\noise_reducer_pytorch\conv_tas_net_onnx_playground.py", line 12, in <module>
    torch.onnx.export(
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\__init__.py", line 275, in export
    return utils.export(model, args, f, export_params, verbose, training,
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\utils.py", line 88, in export
    _export(model, args, f, export_params, verbose, training, input_names, output_names,
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\utils.py", line 689, in _export
    _model_to_graph(model, args, verbose, input_names,
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\utils.py", line 463, in _model_to_graph
    graph = _optimize_graph(graph, operator_export_type,
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\utils.py", line 200, in _optimize_graph
    graph = torch._C._jit_pass_onnx(graph, operator_export_type)
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\__init__.py", line 313, in _run_symbolic_function
    return utils._run_symbolic_function(*args, **kwargs)
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\utils.py", line 994, in _run_symbolic_function
    return symbolic_fn(g, *inputs, **attrs)
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\symbolic_opset9.py", line 389, in wrapper
    return overload(g, *args)
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\symbolic_helper.py", line 166, in wrapper
    args = [_parse_arg(arg, arg_desc, arg_name, fn_name)  # type: ignore[assignment]
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\symbolic_helper.py", line 166, in <listcomp>
    args = [_parse_arg(arg, arg_desc, arg_name, fn_name)  # type: ignore[assignment]
  File "C:\Users\iver5\Anaconda3\lib\site-packages\torch\onnx\symbolic_helper.py", line 93, in _parse_arg
    raise RuntimeError("Expected node type 'onnx::Constant' "
RuntimeError: Expected node type 'onnx::Constant' for argument 'dim' of node 'reduce_dim', got 'onnx::Range'.
mpariente commented 3 years ago

Thanks for the very detailed report. I don't think we have bandwidth for that in the coming month.

Is there a way to see which line causes the export error? @faroit do these errors sound familiar?

iver56 commented 3 years ago

Not sure if we can see the exact line that caused the issue, but it should be possible to do a git bisect to narrow down the issue to a single commit

jonashaag commented 3 years ago

I would assume that there is a bug in ONNX/PyTorch ONNX support (at least the error reporting could be improved).

mpariente commented 3 years ago

There is a PR that changed the padding for causal models, can you try just before it maybe?

We haven't changed much in Convtasnet since the beginning.

Le ven. 30 juil. 2021 à 09:51, Jonas Haag @.***> a écrit :

I would assume that there is a bug in ONNX/PyTorch ONNX support (at least the error reporting could be improved).

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/asteroid-team/asteroid/issues/530#issuecomment-889703014, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEND2HBBAMYWTDCFTQUXWVLT2JKYNANCNFSM5BF7GH6A .

iver56 commented 3 years ago

I did a git bisect, and found that this is the "first bad commit":

https://github.com/asteroid-team/asteroid/commit/51e68353f7b2f47708686d4c08b61a2ddec4dafc

iver56 commented 3 years ago

I've narrowed it down a bit, only exporting encoder + decoder (i.e. without the TDConvNet):

import torch

from asteroid.filterbanks import make_enc_dec

class MySimpleEncoderDecoder(torch.nn.Module):
    def __init__(self):
        super().__init__()
        self.encoder, self.decoder = make_enc_dec(
            "free",
            kernel_size=16,
            n_filters=32,
            stride=8,
            sample_rate=8000,
        )

    def forward(self, x):
        encoded = self.encoder(x)
        decoded = self.decoder(encoded)
        return decoded

input_tensor = torch.zeros(1, 1, 12000, dtype=torch.float32)

model = MySimpleEncoderDecoder()

model_output = model(input_tensor)

print(model_output.shape)

torch.onnx.export(
    model,  # model being run
    input_tensor,  # model input (or a tuple for multiple inputs)
    "enc_dec.onnx",  # where to save the model (can be a file or file-like object)
    export_params=True,  # store the trained parameter weights inside the model file
    opset_version=11,  # the ONNX version to export the model to
    do_constant_folding=True,  # whether to execute constant folding for optimization
    input_names=["input"],  # the model's input names
    output_names=["output"],  # the model's output names
)

This also starts failing at the same commit: 51e6835

iver56 commented 3 years ago

So maybe I should open an issue at https://github.com/asteroid-team/asteroid-filterbanks instead? What do you think @mpariente?

iver56 commented 3 years ago

Or maybe not. There's this issue already: https://github.com/asteroid-team/asteroid-filterbanks/issues/10

mpariente commented 3 years ago

Thanks for narrowing it down. Let's keep it here, it will have more visibility.

This has been integrated close to a year ago, and this commit was quite large, there is still a bit of work. Sorry I won't have the bandwidth for that for a while.

mpariente commented 3 years ago

Ah yes, you're right. I should have remembered that.