Skip to content

Instantly share code, notes, and snippets.

@albertz
Created June 14, 2023 06:59
Show Gist options
  • Save albertz/d552f52db6461b330a9da869360616b6 to your computer and use it in GitHub Desktop.
Save albertz/d552f52db6461b330a9da869360616b6 to your computer and use it in GitHub Desktop.
EXCEPTION
Traceback (most recent call last):
File "/home/icemole/Documentos/work/repos/returnn_pytorch/tools/torch_export_to_onnx.py", line 209, in <module>
line: main()
locals:
main = <local> <function main at 0x7f638c451750>
File "/home/icemole/Documentos/work/repos/returnn_pytorch/tools/torch_export_to_onnx.py", line 197, in main
line: export_func(
pt_model_fwd,
(extern_data_raw, {}),
f=args.out_onnx_filename,
verbose=True,
input_names=list(extern_data_raw.keys()),
output_names=model_outputs_raw_keys,
dynamic_axes=dynamic_axes,
)
locals:
export_func = <local> <function export at 0x7f638da628c0>
pt_model_fwd = <local> ForwardModulePT(
(model): Model(
(layers): Sequential(
(0): Conv1d(9, 50, kernel_size=(5,), stride=(1,), padding=(2,))
(1): ReLU()
(2): Conv1d(50, 100, kernel_size=(5,), stride=(1,), padding=(2,))
(3): ReLU()
(4): Conv1d(100, 2, kernel_size=(5,), stride=(1,), p...
extern_data_raw = <local> {'data': tensor([[[ 7.9832e-02, -1.5952e-01, 2.2222e-02, -4.2779e-01, -5.3182e-01,
-1.1748e-01, 2.2208e-01, -7.6798e-01, 1.4246e-01],
[-3.4652e-02, 1.1343e+00, -1.0475e-01, -5.2512e-01, 1.9128e+00,
-2.0267e+00, 1.1194e+00, 7.7919e-01, -1.1011e+00],
[ 1..., len = 6
f = <not found>
args = <local> Namespace(config='demos/demo-torch.config', checkpoint='/tmp/icemole/returnn/demos/demo-torch/model.005.pt', out_onnx_filename='/tmp/icemole/returnn/demos/demo-torch/model.005.onnx', verbosity=4, device='cpu')
args.out_onnx_filename = <local> '/tmp/icemole/returnn/demos/demo-torch/model.005.onnx', len = 52
verbose = <not found>
input_names = <not found>
list = <builtin> <class 'list'>
extern_data_raw.keys = <local> <built-in method keys of dict object at 0x7f638c2d5080>
output_names = <not found>
model_outputs_raw_keys = <local> ['output', 'output:size0', 'output:size1'], _[0]: {len = 6}
dynamic_axes = <local> {'data': {0: 'batch:data', 1: 'time:var-unk:data'}, 'data:size0': {}, 'data:size1': {0: 'batch:data_dim0_size'}, 'classes': {0: 'batch:classes', 1: 'time:var-unk:classes'}, 'classes:size0': {}, 'classes:size1': {0: 'batch:classes_dim0_size'}, 'output': {0: 'batch:output', 1: 'time:var-unk:output'..., len = 8
File "/home/icemole/Documentos/work/repos/returnn_pytorch/venv/lib/python3.10/site-packages/torch/onnx/utils.py", line 504, in export
line: _export(
model,
args,
f,
export_params,
verbose,
training,
input_names,
output_names,
operator_export_type=operator_export_type,
opset_version=opset_version,
do_constant_folding=do_constant_folding,
dynamic_axes=dynamic_axes,
keep_initializers_as_inputs=keep_initializers_as_inputs,
custom_opsets=custom_opsets,
export_modules_as_functions=export_modules_as_functions,
)
locals:
_export = <global> <function _export at 0x7f638da63760>
model = <local> ForwardModulePT(
(model): Model(
(layers): Sequential(
(0): Conv1d(9, 50, kernel_size=(5,), stride=(1,), padding=(2,))
(1): ReLU()
(2): Conv1d(50, 100, kernel_size=(5,), stride=(1,), padding=(2,))
(3): ReLU()
(4): Conv1d(100, 2, kernel_size=(5,), stride=(1,), p...
args = <local> ({'data': tensor([[[ 7.9832e-02, -1.5952e-01, 2.2222e-02, -4.2779e-01, -5.3182e-01,
-1.1748e-01, 2.2208e-01, -7.6798e-01, 1.4246e-01],
[-3.4652e-02, 1.1343e+00, -1.0475e-01, -5.2512e-01, 1.9128e+00,
-2.0267e+00, 1.1194e+00, 7.7919e-01, -1.1011e+00],
[ ..., _[0]: {len = 6}
f = <local> '/tmp/icemole/returnn/demos/demo-torch/model.005.onnx', len = 52
export_params = <local> True
verbose = <local> True
training = <local> <TrainingMode.EVAL: 0>
input_names = <local> ['data', 'data:size0', 'data:size1', 'classes', 'classes:size0', 'classes:size1'], len = 6
output_names = <local> ['output', 'output:size0', 'output:size1'], _[0]: {len = 6}
operator_export_type = <local> <OperatorExportTypes.ONNX: 0>
opset_version = <local> None
do_constant_folding = <local> True
dynamic_axes = <local> {'data': {0: 'batch:data', 1: 'time:var-unk:data'}, 'data:size0': {}, 'data:size1': {0: 'batch:data_dim0_size'}, 'classes': {0: 'batch:classes', 1: 'time:var-unk:classes'}, 'classes:size0': {}, 'classes:size1': {0: 'batch:classes_dim0_size'}, 'output': {0: 'batch:output', 1: 'time:var-unk:output'..., len = 8
keep_initializers_as_inputs = <local> None
custom_opsets = <local> None
export_modules_as_functions = <local> False
File "/home/icemole/Documentos/work/repos/returnn_pytorch/venv/lib/python3.10/site-packages/torch/onnx/utils.py", line 1529, in _export
line: graph, params_dict, torch_out = _model_to_graph(
model,
args,
verbose,
input_names,
output_names,
operator_export_type,
val_do_constant_folding,
fixed_batch_size=fixed_batch_size,
training=training,
dynamic_axes=dynamic_axes,
)
locals:
graph = <not found>
params_dict = <not found>
torch_out = <not found>
_model_to_graph = <global> <function _model_to_graph at 0x7f638da63400>
model = <local> ForwardModulePT(
(model): Model(
(layers): Sequential(
(0): Conv1d(9, 50, kernel_size=(5,), stride=(1,), padding=(2,))
(1): ReLU()
(2): Conv1d(50, 100, kernel_size=(5,), stride=(1,), padding=(2,))
(3): ReLU()
(4): Conv1d(100, 2, kernel_size=(5,), stride=(1,), p...
args = <local> ({'data': tensor([[[ 7.9832e-02, -1.5952e-01, 2.2222e-02, -4.2779e-01, -5.3182e-01,
-1.1748e-01, 2.2208e-01, -7.6798e-01, 1.4246e-01],
[-3.4652e-02, 1.1343e+00, -1.0475e-01, -5.2512e-01, 1.9128e+00,
-2.0267e+00, 1.1194e+00, 7.7919e-01, -1.1011e+00],
[ ..., _[0]: {len = 6}
verbose = <local> True
input_names = <local> ['data', 'data:size0', 'data:size1', 'classes', 'classes:size0', 'classes:size1'], len = 6
output_names = <local> ['output', 'output:size0', 'output:size1'], _[0]: {len = 6}
operator_export_type = <local> <OperatorExportTypes.ONNX: 0>
val_do_constant_folding = <local> True
fixed_batch_size = <local> False
training = <local> <TrainingMode.EVAL: 0>
dynamic_axes = <local> {'data': {0: 'batch:data', 1: 'time:var-unk:data'}, 'data:size0': {}, 'data:size1': {0: 'batch:data_dim0_size'}, 'classes': {0: 'batch:classes', 1: 'time:var-unk:classes'}, 'classes:size0': {}, 'classes:size1': {0: 'batch:classes_dim0_size'}, 'output': {0: 'batch:output', 1: 'time:var-unk:output'..., len = 8
File "/home/icemole/Documentos/work/repos/returnn_pytorch/venv/lib/python3.10/site-packages/torch/onnx/utils.py", line 1111, in _model_to_graph
line: graph, params, torch_out, module = _create_jit_graph(model, args)
locals:
graph = <not found>
params = <not found>
torch_out = <not found>
module = <not found>
_create_jit_graph = <global> <function _create_jit_graph at 0x7f638da63130>
model = <local> ForwardModulePT(
(model): Model(
(layers): Sequential(
(0): Conv1d(9, 50, kernel_size=(5,), stride=(1,), padding=(2,))
(1): ReLU()
(2): Conv1d(50, 100, kernel_size=(5,), stride=(1,), padding=(2,))
(3): ReLU()
(4): Conv1d(100, 2, kernel_size=(5,), stride=(1,), p...
args = <local> ({'data': tensor([[[ 7.9832e-02, -1.5952e-01, 2.2222e-02, -4.2779e-01, -5.3182e-01,
-1.1748e-01, 2.2208e-01, -7.6798e-01, 1.4246e-01],
[-3.4652e-02, 1.1343e+00, -1.0475e-01, -5.2512e-01, 1.9128e+00,
-2.0267e+00, 1.1194e+00, 7.7919e-01, -1.1011e+00],
[ ..., _[0]: {len = 6}
File "/home/icemole/Documentos/work/repos/returnn_pytorch/venv/lib/python3.10/site-packages/torch/onnx/utils.py", line 987, in _create_jit_graph
line: graph, torch_out = _trace_and_get_graph_from_model(model, args)
locals:
graph = <not found>
torch_out = <not found>
_trace_and_get_graph_from_model = <global> <function _trace_and_get_graph_from_model at 0x7f638da62f80>
model = <local> ForwardModulePT(
(model): Model(
(layers): Sequential(
(0): Conv1d(9, 50, kernel_size=(5,), stride=(1,), padding=(2,))
(1): ReLU()
(2): Conv1d(50, 100, kernel_size=(5,), stride=(1,), padding=(2,))
(3): ReLU()
(4): Conv1d(100, 2, kernel_size=(5,), stride=(1,), p...
args = <local> ({'data': tensor([[[ 7.9832e-02, -1.5952e-01, 2.2222e-02, -4.2779e-01, -5.3182e-01,
-1.1748e-01, 2.2208e-01, -7.6798e-01, 1.4246e-01],
[-3.4652e-02, 1.1343e+00, -1.0475e-01, -5.2512e-01, 1.9128e+00,
-2.0267e+00, 1.1194e+00, 7.7919e-01, -1.1011e+00],
[ ..., _[0]: {len = 6}
File "/home/icemole/Documentos/work/repos/returnn_pytorch/venv/lib/python3.10/site-packages/torch/onnx/utils.py", line 891, in _trace_and_get_graph_from_model
line: trace_graph, torch_out, inputs_states = torch.jit._get_trace_graph(
model,
args,
strict=False,
_force_outplace=False,
_return_inputs_states=True,
)
locals:
trace_graph = <not found>
torch_out = <not found>
inputs_states = <not found>
torch = <global> <module 'torch' from '/home/icemole/Documentos/work/repos/returnn_pytorch/venv/lib/python3.10/site-packages/torch/__init__.py'>
torch.jit = <global> <module 'torch.jit' from '/home/icemole/Documentos/work/repos/returnn_pytorch/venv/lib/python3.10/site-packages/torch/jit/__init__.py'>
torch.jit._get_trace_graph = <global> <function _get_trace_graph at 0x7f638dc13490>
model = <local> ForwardModulePT(
(model): Model(
(layers): Sequential(
(0): Conv1d(9, 50, kernel_size=(5,), stride=(1,), padding=(2,))
(1): ReLU()
(2): Conv1d(50, 100, kernel_size=(5,), stride=(1,), padding=(2,))
(3): ReLU()
(4): Conv1d(100, 2, kernel_size=(5,), stride=(1,), p...
args = <local> ({'data': tensor([[[ 7.9832e-02, -1.5952e-01, 2.2222e-02, -4.2779e-01, -5.3182e-01,
-1.1748e-01, 2.2208e-01, -7.6798e-01, 1.4246e-01],
[-3.4652e-02, 1.1343e+00, -1.0475e-01, -5.2512e-01, 1.9128e+00,
-2.0267e+00, 1.1194e+00, 7.7919e-01, -1.1011e+00],
[ ..., _[0]: {len = 6}
strict = <not found>
_force_outplace = <not found>
_return_inputs_states = <not found>
File "/home/icemole/Documentos/work/repos/returnn_pytorch/venv/lib/python3.10/site-packages/torch/jit/_trace.py", line 1184, in _get_trace_graph
line: outs = ONNXTracedModule(f, strict, _force_outplace, return_inputs, _return_inputs_states)(*args, **kwargs)
locals:
outs = <not found>
ONNXTracedModule = <global> <class 'torch.jit._trace.ONNXTracedModule'>
f = <local> ForwardModulePT(
(model): Model(
(layers): Sequential(
(0): Conv1d(9, 50, kernel_size=(5,), stride=(1,), padding=(2,))
(1): ReLU()
(2): Conv1d(50, 100, kernel_size=(5,), stride=(1,), padding=(2,))
(3): ReLU()
(4): Conv1d(100, 2, kernel_size=(5,), stride=(1,), p...
strict = <local> False
_force_outplace = <local> False
return_inputs = <local> False
_return_inputs_states = <local> True
args = <local> ({'data': tensor([[[ 7.9832e-02, -1.5952e-01, 2.2222e-02, -4.2779e-01, -5.3182e-01,
-1.1748e-01, 2.2208e-01, -7.6798e-01, 1.4246e-01],
[-3.4652e-02, 1.1343e+00, -1.0475e-01, -5.2512e-01, 1.9128e+00,
-2.0267e+00, 1.1194e+00, 7.7919e-01, -1.1011e+00],
[ ..., _[0]: {len = 6}
kwargs = <local> {}
File "/home/icemole/Documentos/work/repos/returnn_pytorch/venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1194, in Module._call_impl
line: return forward_call(*input, **kwargs)
locals:
forward_call = <local> <bound method ONNXTracedModule.forward of ONNXTracedModule(
(inner): ForwardModulePT(
(model): Model(
(layers): Sequential(
(0): Conv1d(9, 50, kernel_size=(5,), stride=(1,), padding=(2,))
(1): ReLU()
(2): Conv1d(50, 100, kernel_size=(5,), stride=(1,), padding=(...
input = <local> ({'data': tensor([[[ 7.9832e-02, -1.5952e-01, 2.2222e-02, -4.2779e-01, -5.3182e-01,
-1.1748e-01, 2.2208e-01, -7.6798e-01, 1.4246e-01],
[-3.4652e-02, 1.1343e+00, -1.0475e-01, -5.2512e-01, 1.9128e+00,
-2.0267e+00, 1.1194e+00, 7.7919e-01, -1.1011e+00],
[ ..., _[0]: {len = 6}
kwargs = <local> {}
File "/home/icemole/Documentos/work/repos/returnn_pytorch/venv/lib/python3.10/site-packages/torch/jit/_trace.py", line 127, in ONNXTracedModule.forward
line: graph, out = torch._C._create_graph_by_tracing(
wrapper,
in_vars + module_state,
_create_interpreter_name_lookup_fn(),
self.strict,
self._force_outplace,
)
locals:
graph = <not found>
out = <not found>
torch = <global> <module 'torch' from '/home/icemole/Documentos/work/repos/returnn_pytorch/venv/lib/python3.10/site-packages/torch/__init__.py'>
torch._C = <global> <module 'torch._C' from '/home/icemole/Documentos/work/repos/returnn_pytorch/venv/lib/python3.10/site-packages/torch/_C.cpython-310-x86_64-linux-gnu.so'>
torch._C._create_graph_by_tracing = <global> <built-in method _create_graph_by_tracing of PyCapsule object at 0x7f641a31cb70>
wrapper = <local> <function ONNXTracedModule.forward.<locals>.wrapper at 0x7f638c2bf7f0>
in_vars = <local> [tensor([[[ 7.9832e-02, -1.5952e-01, 2.2222e-02, -4.2779e-01, -5.3182e-01,
-1.1748e-01, 2.2208e-01, -7.6798e-01, 1.4246e-01],
[-3.4652e-02, 1.1343e+00, -1.0475e-01, -5.2512e-01, 1.9128e+00,
-2.0267e+00, 1.1194e+00, 7.7919e-01, -1.1011e+00],
[ 1.1302e+0..., len = 6
module_state = <local> [Parameter containing:
tensor([[[ 0.2969, 0.1807, -0.2058, -0.5377, -0.0236],
[-0.2986, 0.1896, 0.6093, 0.2943, 0.0186],
[-0.0740, -0.2344, -0.1361, -0.0865, 0.1116],
...,
[-0.0398, -0.2474, -0.2914, -0.2815, -0.3621],
[-0.0245, -0.2042, -0.2577,..., len = 6
_create_interpreter_name_lookup_fn = <global> <function _create_interpreter_name_lookup_fn at 0x7f638dc124d0>
self = <local> ONNXTracedModule(
(inner): ForwardModulePT(
(model): Model(
(layers): Sequential(
(0): Conv1d(9, 50, kernel_size=(5,), stride=(1,), padding=(2,))
(1): ReLU()
(2): Conv1d(50, 100, kernel_size=(5,), stride=(1,), padding=(2,))
(3): ReLU()
(4): Conv...
self.strict = <local> False
self._force_outplace = <local> False
File "/home/icemole/Documentos/work/repos/returnn_pytorch/venv/lib/python3.10/site-packages/torch/jit/_trace.py", line 118, in ONNXTracedModule.forward.<locals>.wrapper
line: outs.append(self.inner(*trace_inputs))
locals:
outs = <local> []
outs.append = <local> <built-in method append of list object at 0x7f638c2f8b40>
self = <local> ONNXTracedModule(
(inner): ForwardModulePT(
(model): Model(
(layers): Sequential(
(0): Conv1d(9, 50, kernel_size=(5,), stride=(1,), padding=(2,))
(1): ReLU()
(2): Conv1d(50, 100, kernel_size=(5,), stride=(1,), padding=(2,))
(3): ReLU()
(4): Conv...
self.inner = <local> ForwardModulePT(
(model): Model(
(layers): Sequential(
(0): Conv1d(9, 50, kernel_size=(5,), stride=(1,), padding=(2,))
(1): ReLU()
(2): Conv1d(50, 100, kernel_size=(5,), stride=(1,), padding=(2,))
(3): ReLU()
(4): Conv1d(100, 2, kernel_size=(5,), stride=(1,), p...
trace_inputs = <local> ({'data': tensor([[[ 7.9832e-02, -1.5952e-01, 2.2222e-02, -4.2779e-01, -5.3182e-01,
-1.1748e-01, 2.2208e-01, -7.6798e-01, 1.4246e-01],
[-3.4652e-02, 1.1343e+00, -1.0475e-01, -5.2512e-01, 1.9128e+00,
-2.0267e+00, 1.1194e+00, 7.7919e-01, -1.1011e+00],
[ ..., _[0]: {len = 6}
File "/home/icemole/Documentos/work/repos/returnn_pytorch/tools/torch_export_to_onnx.py", line 87, in ForwardModulePT.__call__
line: return rf.get_run_ctx().outputs.as_raw_tensor_dict()
locals:
rf = <global> <module 'returnn.frontend' from '/home/icemole/Documentos/work/repos/returnn_pytorch/returnn/frontend/__init__.py'>
rf.get_run_ctx = <global> <function get_run_ctx at 0x7f638c439870>
outputs = <not found>
outputs.as_raw_tensor_dict = <not found>
File "/home/icemole/Documentos/work/repos/returnn_pytorch/returnn/tensor/tensor_dict.py", line 88, in TensorDict.as_raw_tensor_dict
line: out[key_] = dim.get_dim_value()
locals:
out = <local> {'output': tensor([[[ 7.4615, -8.9174],
[ 12.0366, -13.1756],
[ 27.6231, -29.9030],
[ 25.2957, -26.7124],
[ 40.0092, -42.1561],
[ 24.7264, -26.0574],
[ 49.5347, -50.2851],
[ 28.1509, -28.4984],
[ 42.6256, -44.0171],
...
key_ = <local> 'output:size0', len = 12
dim = <local> Dim{B}
dim.get_dim_value = <local> <bound method _DimMixin.get_dim_value of Dim{B}>
File "/home/icemole/Documentos/work/repos/returnn_pytorch/returnn/tensor/_dim_extra.py", line 1656, in _DimMixin.get_dim_value
line: res = self.get_dim_value_tensor()
locals:
res = <not found>
self = <local> Dim{B}
self.get_dim_value_tensor = <local> <bound method _DimMixin.get_dim_value_tensor of Dim{B}>
File "/home/icemole/Documentos/work/repos/returnn_pytorch/returnn/tensor/_dim_extra.py", line 1710, in _DimMixin.get_dim_value_tensor
line: raise Exception("%s: need placeholder, self.dimension or self.dyn_size for dim value" % self)
locals:
Exception = <builtin> <class 'Exception'>
self = <local> Dim{B}
Exception: Dim{B}: need placeholder, self.dimension or self.dyn_size for dim value
Process finished with exit code 1
@albertz
Copy link
Author

albertz commented Jun 14, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment