_thnn_conv2d_forward

sergio4457: <p>torch.onnx.export(model,dummy_input,model_name,verbose=True,<br>
input_names=[input_name],output_names=[output_name])</p>
<hr>
<p>RuntimeError                              Traceback (most recent call last)<br>
 in <br>
1 torch.onnx.export(model,dummy_input,model_name,verbose=True,<br>
----&gt; 2                   input_names=[input_name],output_names=[output_name])</p>
<p>~\anaconda3\envs\fastai\lib\site-packages\torch\onnx_<em>init</em>_.py in export(model, args, f, export_params, verbose, training, input_names, output_names, aten, export_raw_ir, operator_export_type, opset_version, _retain_param_name, do_constant_folding, example_outputs, strip_doc_string, dynamic_axes, keep_initializers_as_inputs)<br>
146                         operator_export_type, opset_version, _retain_param_name,<br>
147                         do_constant_folding, example_outputs,<br>
–&gt; 148                         strip_doc_string, dynamic_axes, keep_initializers_as_inputs)<br>
149<br>
150</p>
<p>~\anaconda3\envs\fastai\lib\site-packages\torch\onnx\utils.py in export(model, args, f, export_params, verbose, training, input_names, output_names, aten, export_raw_ir, operator_export_type, opset_version, _retain_param_name, do_constant_folding, example_outputs, strip_doc_string, dynamic_axes, keep_initializers_as_inputs)<br>
64             _retain_param_name=_retain_param_name, do_constant_folding=do_constant_folding,<br>
65             example_outputs=example_outputs, strip_doc_string=strip_doc_string,<br>
—&gt; 66             dynamic_axes=dynamic_axes, keep_initializers_as_inputs=keep_initializers_as_inputs)<br>
67<br>
68</p>
<p>~\anaconda3\envs\fastai\lib\site-packages\torch\onnx\utils.py in _export(model, args, f, export_params, verbose, training, input_names, output_names, operator_export_type, export_type, example_outputs, propagate, opset_version, _retain_param_name, do_constant_folding, strip_doc_string, dynamic_axes, keep_initializers_as_inputs, fixed_batch_size)<br>
414                                                         example_outputs, propagate,<br>
415                                                         _retain_param_name, do_constant_folding,<br>
–&gt; 416                                                         fixed_batch_size=fixed_batch_size)<br>
417<br>
418         # TODO: Don’t allocate a in-memory string for the protobuf</p>
<p>~\anaconda3\envs\fastai\lib\site-packages\torch\onnx\utils.py in _model_to_graph(model, args, verbose, training, input_names, output_names, operator_export_type, example_outputs, propagate, _retain_param_name, do_constant_folding, _disable_torch_constant_prop, fixed_batch_size)<br>
277             model.graph, tuple(in_vars), False, propagate)<br>
278     else:<br>
–&gt; 279         graph, torch_out = _trace_and_get_graph_from_model(model, args, training)<br>
280         state_dict = _unique_state_dict(model)<br>
281         params = list(state_dict.values())</p>
<p>~\anaconda3\envs\fastai\lib\site-packages\torch\onnx\utils.py in _trace_and_get_graph_from_model(model, args, training)<br>
234     # training mode was.)<br>
235     with set_training(model, training):<br>
–&gt; 236         trace_graph, torch_out, inputs_states = torch.jit._get_trace_graph(model, args, _force_outplace=True, _return_inputs_states=True)<br>
237         warn_on_static_input_change(inputs_states)<br>
238</p>
<p>~\anaconda3\envs\fastai\lib\site-packages\torch\jit_<em>init</em>_.py in _get_trace_graph(f, args, kwargs, _force_outplace, return_inputs, _return_inputs_states)<br>
275     if not isinstance(args, tuple):<br>
276         args = (args,)<br>
–&gt; 277     outs = ONNXTracedModule(f, _force_outplace, return_inputs, _return_inputs_states)(*args, **kwargs)<br>
278     return outs<br>
279</p>
<p>~\anaconda3\envs\fastai\lib\site-packages\torch\nn\modules\module.py in <strong>call</strong>(self, *input, **kwargs)<br>
530             result = self._slow_forward(*input, **kwargs)<br>
531         else:<br>
–&gt; 532             result = self.forward(*input, **kwargs)<br>
533         for hook in self._forward_hooks.values():<br>
534             hook_result = hook(self, input, result)</p>
<p>~\anaconda3\envs\fastai\lib\site-packages\torch\jit_<em>init</em>_.py in forward(self, *args)<br>
358             in_vars + module_state,<br>
359             _create_interpreter_name_lookup_fn(),<br>
–&gt; 360             self._force_outplace,<br>
361         )<br>
362</p>
<p>~\anaconda3\envs\fastai\lib\site-packages\torch\jit_<em>init</em>_.py in wrapper(*args)<br>
345             if self._return_inputs_states:<br>
346                 inputs_states.append(_unflatten(args[:len(in_vars)], in_desc))<br>
–&gt; 347             outs.append(self.inner(*trace_inputs))<br>
348             if self._return_inputs_states:<br>
349                 inputs_states[0] = (inputs_states[0], trace_inputs)</p>
<p>~\anaconda3\envs\fastai\lib\site-packages\torch\nn\modules\module.py in <strong>call</strong>(self, *input, **kwargs)<br>
528                 input = result<br>
529         if torch._C._get_tracing_state():<br>
–&gt; 530             result = self._slow_forward(*input, **kwargs)<br>
531         else:<br>
532             result = self.forward(*input, **kwargs)</p>
<p>~\anaconda3\envs\fastai\lib\site-packages\torch\nn\modules\module.py in _slow_forward(self, *input, **kwargs)<br>
514                 recording_scopes = False<br>
515         try:<br>
–&gt; 516             result = self.forward(*input, **kwargs)<br>
517         finally:<br>
518             if recording_scopes:</p>
<p>~\anaconda3\envs\fastai\lib\site-packages\torch\nn\modules\container.py in forward(self, input)<br>
98     def forward(self, input):<br>
99         for module in self:<br>
–&gt; 100             input = module(input)<br>
101         return input<br>
102</p>
<p>~\anaconda3\envs\fastai\lib\site-packages\torch\nn\modules\module.py in <strong>call</strong>(self, *input, **kwargs)<br>
528                 input = result<br>
529         if torch._C._get_tracing_state():<br>
–&gt; 530             result = self._slow_forward(*input, **kwargs)<br>
531         else:<br>
532             result = self.forward(*input, **kwargs)</p>
<p>~\anaconda3\envs\fastai\lib\site-packages\torch\nn\modules\module.py in _slow_forward(self, *input, **kwargs)<br>
514                 recording_scopes = False<br>
515         try:<br>
–&gt; 516             result = self.forward(*input, **kwargs)<br>
517         finally:<br>
518             if recording_scopes:</p>
<p>~\anaconda3\envs\fastai\lib\site-packages\torch\nn\modules\container.py in forward(self, input)<br>
98     def forward(self, input):<br>
99         for module in self:<br>
–&gt; 100             input = module(input)<br>
101         return input<br>
102</p>
<p>~\anaconda3\envs\fastai\lib\site-packages\torch\nn\modules\module.py in <strong>call</strong>(self, *input, **kwargs)<br>
528                 input = result<br>
529         if torch._C._get_tracing_state():<br>
–&gt; 530             result = self._slow_forward(*input, **kwargs)<br>
531         else:<br>
532             result = self.forward(*input, **kwargs)</p>
<p>~\anaconda3\envs\fastai\lib\site-packages\torch\nn\modules\module.py in _slow_forward(self, *input, **kwargs)<br>
514                 recording_scopes = False<br>
515         try:<br>
–&gt; 516             result = self.forward(*input, **kwargs)<br>
517         finally:<br>
518             if recording_scopes:</p>
<p>~\anaconda3\envs\fastai\lib\site-packages\torch\nn\modules\conv.py in forward(self, input)<br>
343<br>
344     def forward(self, input):<br>
–&gt; 345         return self.conv2d_forward(input, self.weight)<br>
346<br>
347 class Conv3d(_ConvNd):</p>
<p>~\anaconda3\envs\fastai\lib\site-packages\torch\nn\modules\conv.py in conv2d_forward(self, input, weight)<br>
340                             _pair(0), self.dilation, self.groups)<br>
341         return F.conv2d(input, weight, self.bias, self.stride,<br>
–&gt; 342                         self.padding, self.dilation, self.groups)<br>
343<br>
344     def forward(self, input):</p>
<p>RuntimeError: Expected object of device type cuda but got device type cpu for argument <span class="hashtag">#1</span> ‘self’ in call to _thnn_conv2d_forward</p>

ptrblck: <p>It seems your code raises a device mismatch error, i.e. the model and inputs are not both on the GPU.<br>
Try to push both to the device via:</p>
<pre><code class="lang-python">device = 'cuda:0'
model.to(device)
input = input.to(device)
</code></pre>
<p>before executing the model (or trying to export it).</p>