Torch.onnx.dynamo_export help

D3cpt: <p>I am trying out the new dynamo_export and it is stuck when i tried to reshape a tensor.</p>
<p>long trace stack below:</p>
<blockquote>
<p>/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/onnx/_internal/exporter.py:130: UserWarning: torch.onnx.dynamo_export only implements opset version 18 for now. If you need to use a different opset version, please register them with register_custom_op.<br>
warnings.warn(<br>
/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/nn/functional.py:4358: UserWarning: Default grid_sample and affine_grid behavior has changed to align_corners=False since 1.3.0. Please specify align_corners=True if the old behavior is desired. See the documentation of grid_sample for details.<br>
warnings.warn(<br>
/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/nn/functional.py:4296: UserWarning: Default grid_sample and affine_grid behavior has changed to align_corners=False since 1.3.0. Please specify align_corners=True if the old behavior is desired. See the documentation of grid_sample for details.<br>
warnings.warn(<br>
Traceback (most recent call last):<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/utils.py”, line 1433, in run_node<br>
return getattr(args[0], node.target)(*args[1:], **kwargs)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/utils/_stats.py”, line 20, in wrapper<br>
return fn(*args, **kwargs)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_subclasses/fake_tensor.py”, line 1304, in <strong>torch_dispatch</strong><br>
return self.dispatch(func, types, args, kwargs)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_subclasses/fake_tensor.py”, line 1510, in dispatch<br>
return decomposition_table[func](*args, **kwargs)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_refs/<strong>init</strong>.py”, line 4450, in view<br>
return _reshape_view_helper(a, <em>shape, allow_copy=False)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_refs/<strong>init</strong>.py”, line 3583, in <em>reshape_view_helper<br>
shape = utils.infer_size(shape, a.numel())<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/<em>prims_common/<strong>init</strong>.py”, line 824, in infer_size<br>
numel == newsize or (dim is not None and newsize &gt; 0 and numel % newsize == 0),<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/<strong>init</strong>.py”, line 361, in <strong>bool</strong><br>
return self.node.bool</em>()<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/fx/experimental/symbolic_shapes.py”, line 1036, in bool</em><br>
return self.guard_bool(“”, 0)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/fx/experimental/symbolic_shapes.py”, line 1006, in guard_bool<br>
r = self.shape_env.evaluate_expr(self.expr, self.hint, fx_node=self.fx_node)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/fx/experimental/recording.py”, line 246, in wrapper<br>
return event.run(self)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/fx/experimental/recording.py”, line 151, in run<br>
return self.f(<em>args, **kwargs)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/fx/experimental/symbolic_shapes.py”, line 3834, in evaluate_expr<br>
concrete_val = self.size_hint(orig_expr)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/fx/experimental/symbolic_shapes.py”, line 3633, in size_hint<br>
raise self._make_data_dependent_error(result_expr, expr)<br>
torch.fx.experimental.symbolic_shapes.GuardOnDataDependentSymNode: It appears that you’re trying to get a value out of symbolic int/float whose value is data-dependent (and thus we do not know the true value.) The expression we were trying to evaluate is Eq(2</em>i0, 98) (unhinted: Eq(2</em>i0, 98)). Scroll up to see where each of these data-dependent accesses originally occurred.</p>
<p>The above exception was the direct cause of the following exception:</p>
<p>Traceback (most recent call last):<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/utils.py”, line 1352, in get_fake_value<br>
return wrap_fake_exception(<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/utils.py”, line 921, in wrap_fake_exception<br>
return fn()<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/utils.py”, line 1353, in<br>
lambda: run_node(tx.output, node, args, kwargs, nnmodule)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/utils.py”, line 1452, in run_node<br>
raise RuntimeError(fn_str + str(e)).with_traceback(e.<strong>traceback</strong>) from e<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/utils.py”, line 1433, in run_node<br>
return getattr(args[0], node.target)(*args[1:], **kwargs)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/utils/_stats.py”, line 20, in wrapper<br>
return fn(*args, **kwargs)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_subclasses/fake_tensor.py”, line 1304, in <strong>torch_dispatch</strong><br>
return self.dispatch(func, types, args, kwargs)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_subclasses/fake_tensor.py”, line 1510, in dispatch<br>
return decomposition_table[func](<em>args, **kwargs)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_refs/<strong>init</strong>.py”, line 4450, in view<br>
return _reshape_view_helper(a, <em>shape, allow_copy=False)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_refs/<strong>init</strong>.py”, line 3583, in <em>reshape_view_helper<br>
shape = utils.infer_size(shape, a.numel())<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/<em>prims_common/<strong>init</strong>.py”, line 824, in infer_size<br>
numel == newsize or (dim is not None and newsize &gt; 0 and numel % newsize == 0),<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/<strong>init</strong>.py”, line 361, in <strong>bool</strong><br>
return self.node.bool</em>()<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/fx/experimental/symbolic_shapes.py”, line 1036, in bool</em><br>
return self.guard_bool(“”, 0)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/fx/experimental/symbolic_shapes.py”, line 1006, in guard_bool<br>
r = self.shape_env.evaluate_expr(self.expr, self.hint, fx_node=self.fx_node)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/fx/experimental/recording.py”, line 246, in wrapper<br>
return event.run(self)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/fx/experimental/recording.py”, line 151, in run<br>
return self.f(<em>args, **kwargs)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/fx/experimental/symbolic_shapes.py”, line 3834, in evaluate_expr<br>
concrete_val = self.size_hint(orig_expr)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/fx/experimental/symbolic_shapes.py”, line 3633, in size_hint<br>
raise self._make_data_dependent_error(result_expr, expr)<br>
RuntimeError: Failed running call_method reshape(</em>(FakeTensor(…, device=‘cuda:0’, size=(1, i0, 2), grad_fn=), 1, 98, -1), **{}):<br>
It appears that you’re trying to get a value out of symbolic int/float whose value is data-dependent (and thus we do not know the true value.) The expression we were trying to evaluate is Eq(2</em>i0, 98) (unhinted: Eq(2</em>i0, 98)). Scroll up to see where each of these data-dependent accesses originally occurred.</p>
<p>During handling of the above exception, another exception occurred:</p>
<p>Traceback (most recent call last):<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/onnx/_internal/exporter.py”, line 1195, in dynamo_export<br>
).export()<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/onnx/_internal/exporter.py”, line 941, in export<br>
graph_module = self.options.fx_tracer.generate_fx(<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/onnx/_internal/fx/dynamo_graph_extractor.py”, line 199, in generate_fx<br>
graph_module, graph_guard = torch._dynamo.export(<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/eval_frame.py”, line 1216, in inner<br>
result_traced = opt_f(*args, **kwargs)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/eval_frame.py”, line 406, in _fn<br>
return fn(*args, **kwargs)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/onnx/_internal/fx/dynamo_graph_extractor.py”, line 154, in wrapped<br>
return output_adapter.apply(model_func(*args, **kwargs))<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/eval_frame.py”, line 554, in catch_errors<br>
return callback(frame, cache_entry, hooks, frame_state)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py”, line 140, in _fn<br>
return fn(*args, **kwargs)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py”, line 380, in _convert_frame_assert<br>
return _compile(<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py”, line 559, in _compile<br>
guarded_code = compile_inner(code, one_graph, hooks, transform)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/utils.py”, line 190, in time_wrapper<br>
r = func(*args, **kwargs)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py”, line 481, in compile_inner<br>
out_code = transform_code_object(code, transform)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/bytecode_transformation.py”, line 1028, in transform_code_object<br>
transformations(instructions, code_options)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py”, line 451, in transform<br>
tracer.run()<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py”, line 2094, in run<br>
super().run()<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py”, line 739, in run<br>
and self.step()<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py”, line 702, in step<br>
getattr(self, inst.opname)(inst)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py”, line 403, in wrapper<br>
return inner_fn(self, inst)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py”, line 1135, in CALL_FUNCTION<br>
self.call_function(fn, args, {})<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py”, line 576, in call_function<br>
self.push(fn.call_function(self, args, kwargs))<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/variables/functions.py”, line 307, in call_function<br>
return super().call_function(tx, args, kwargs)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/variables/functions.py”, line 261, in call_function<br>
return super().call_function(tx, args, kwargs)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/variables/functions.py”, line 90, in call_function<br>
return tx.inline_user_function_return(<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py”, line 612, in inline_user_function_return<br>
result = InliningInstructionTranslator.inline_call(self, fn, args, kwargs)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/<em>dynamo/symbolic_convert.py”, line 2221, in inline_call<br>
return cls.inline_call</em>(parent, func, args, kwargs)<br>
File "/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/<em>dynamo/symbolic_convert.py", line 2343, in inline_call</em><br>
tracer.run()<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py”, line 739, in run<br>
and self.step()<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py”, line 702, in step<br>
getattr(self, inst.opname)(inst)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py”, line 403, in wrapper<br>
return inner_fn(self, inst)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py”, line 1135, in CALL_FUNCTION<br>
self.call_function(fn, args, {})<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py”, line 576, in call_function<br>
self.push(fn.call_function(self, args, kwargs))<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/variables/functions.py”, line 307, in call_function<br>
return super().call_function(tx, args, kwargs)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/variables/functions.py”, line 261, in call_function<br>
return super().call_function(tx, args, kwargs)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/variables/functions.py”, line 90, in call_function<br>
return tx.inline_user_function_return(<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py”, line 612, in inline_user_function_return<br>
result = InliningInstructionTranslator.inline_call(self, fn, args, kwargs)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/<em>dynamo/symbolic_convert.py”, line 2221, in inline_call<br>
return cls.inline_call</em>(parent, func, args, kwargs)<br>
File "/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/<em>dynamo/symbolic_convert.py", line 2343, in inline_call</em><br>
tracer.run()<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py”, line 739, in run<br>
and self.step()<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py”, line 702, in step<br>
getattr(self, inst.opname)(inst)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py”, line 403, in wrapper<br>
return inner_fn(self, inst)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py”, line 1135, in CALL_FUNCTION<br>
self.call_function(fn, args, {})<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py”, line 576, in call_function<br>
self.push(fn.call_function(self, args, kwargs))<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/variables/misc.py”, line 617, in call_function<br>
return self.obj.call_method(tx, self.name, args, kwargs).add_options(self)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/variables/tensor.py”, line 693, in call_method<br>
return wrap_fx_proxy(<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/variables/builder.py”, line 1289, in wrap_fx_proxy<br>
return wrap_fx_proxy_cls(<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/variables/builder.py”, line 1376, in wrap_fx_proxy_cls<br>
example_value = get_fake_value(proxy.node, tx)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/_dynamo/utils.py”, line 1381, in get_fake_value<br>
raise UserError(<br>
torch._dynamo.exc.UserError: Tried to use data-dependent value in the subsequent computation. This can happen when we encounter unbounded dynamic value that is unknown during tracing time.You will need to explicitly give hint to the compiler. Please take a look at constrain_as_value OR constrain_as_size APIs</p>
<p>from user code:<br>
File “/home/evas/Downloads/SPIGA/SPIGA/spiga/models/spiga.py”, line 82, in forward<br>
embedded_ft = self.extract_embedded(pts_proj, visual_field, step)<br>
File “/home/evas/Downloads/SPIGA/SPIGA/spiga/models/spiga.py”, line 124, in extract_embedded<br>
shape_ft = self.calculate_distances(pts_proj)<br>
File “/home/evas/Downloads/SPIGA/SPIGA/spiga/models/spiga.py”, line 163, in calculate_distances<br>
dist_wo_self = dist[:, self.diagonal_mask, :].reshape(B, L, -1)</p>
<pre><code class="lang-auto">dist: tensor([[[-0.0072, -0.0387],
         [-0.0144, -0.0772],
         [-0.0311, -0.1161],
         ...,
         [ 0.1014, -0.2628],
         [ 0.1312, -0.2631],
         [ 0.2310, -0.0109]]], device='cuda:0', grad_fn=&lt;IndexBackward0&gt;)
shape: (1, 98)
</code></pre>
<p>The above exception was the direct cause of the following exception:</p>
<p>Traceback (most recent call last):<br>
File “/home/evas/Downloads/SPIGA/SPIGA/app_CH.py”, line 74, in<br>
tracked_obj = processor.process_frame(frame, [faces[0]])<br>
File “/home/evas/Downloads/SPIGA/SPIGA/spiga/demo/analyze/extract/spiga_processor.py”, line 35, in process_frame<br>
features = self.processor.inference(frame, bboxes)<br>
File “/home/evas/Downloads/SPIGA/SPIGA/spiga/inference/framework.py”, line 70, in inference<br>
outputs = self.net_forward(batch_crops)<br>
File “/home/evas/Downloads/SPIGA/SPIGA/spiga/inference/framework.py”, line 98, in net_forward<br>
torch.onnx.dynamo_export(self.model, inputs).save(“wflw.onnx”)<br>
File “/home/evas/anaconda3/envs/CH_test/lib/python3.10/site-packages/torch/onnx/_internal/exporter.py”, line 1206, in dynamo_export<br>
raise OnnxExporterError(<br>
torch.onnx.OnnxExporterError: Failed to export the model to ONNX. Generating SARIF report at ‘report_dynamo_export.sarif’. SARIF is a standard format for the output of static analysis tools. SARIF logs can be loaded in VS Code SARIF viewer extension, or SARIF web viewer (<a href="https://microsoft.github.io/sarif-web-component/" class="inline-onebox" rel="noopener nofollow ugc">Sarif Viewer</a>). Please report a bug on PyTorch Github: <a href="https://github.com/pytorch/pytorch/issues" class="inline-onebox" rel="noopener nofollow ugc">Issues · pytorch/pytorch · GitHub</a></p>
</blockquote>

DodoI: <p>Hi, do you have an update?</p>