RuntimeError: set_sizes_and_strides is not allowed on a Tensor created from .data or .detach(). in "convert_model_to_nnapi"

JHKim: <p>I write the code by following the nnapi tutorial in pytorch homepage.<br>
My model is resnet50 and this error is occured.</p>
<p>The following operation failed in the TorchScript interpreter.<br>
Traceback of TorchScript (most recent call last):<br>
C:\Users\200522\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\nn\modules\conv.py(396): _conv_forward<br>
C:\Users\200522\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\nn\modules\conv.py(399): forward<br>
C:\Users\200522\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\nn\modules\module.py(860): _slow_forward<br>
C:\Users\200522\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\nn\modules\module.py(887): _call_impl<br>
d:\src\model_2.py(180): forward<br>
C:\Users\200522\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\nn\modules\module.py(860): _slow_forward<br>
C:\Users\200522\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\nn\modules\module.py(887): _call_impl<br>
C:\Users\200522\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\nn\parallel\data_parallel.py(164): forward<br>
C:\Users\200522\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\nn\modules\module.py(860): _slow_forward<br>
C:\Users\200522\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\nn\modules\module.py(887): _call_impl<br>
C:\Users\200522\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\jit_trace.py(940): trace_module<br>
C:\Users\200522\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\jit_trace.py(742): trace<br>
d:\src\convert.py(93): make_mobilenetv2_nnapi<br>
d:\src\convert.py(132): <br>
C:\Users\200522\AppData\Local\Programs\Python\Python37\lib\runpy.py(85): _run_code<br>
C:\Users\200522\AppData\Local\Programs\Python\Python37\lib\runpy.py(96): <em>run_module_code<br>
C:\Users\200522\AppData\Local\Programs\Python\Python37\lib\runpy.py(263): run_path<br>
c:\Users\200522.vscode\extensions\ms-python.python-2022.4.1\pythonFiles\lib\python\debugpy/…\debugpy\server\cli.py(285): run_file<br>
c:\Users\200522.vscode\extensions\ms-python.python-2022.4.1\pythonFiles\lib\python\debugpy/…\debugpy\server\cli.py(444): main<br>
c:\Users\200522.vscode\extensions\ms-python.python-2022.4.1\pythonFiles\lib\python\debugpy_<em>main</em></em>.py(45): <br>
C:\Users\200522\AppData\Local\Programs\Python\Python37\lib\runpy.py(85): <em>run_code<br>
C:\Users\200522\AppData\Local\Programs\Python\Python37\lib\runpy.py(193): <em>run_module_as_main<br>
RuntimeError: set_sizes_and_strides is not allowed on a Tensor created from .data or .detach().<br>
If your intent is to change the metadata of a Tensor (such as sizes / strides / storage / storage_offset)<br>
without autograd tracking the change, remove the .data / .detach() call and wrap the change in a <code>with torch.no_grad():</code> block.<br>
For example, change:<br>
x.data.set</em>(y)<br>
to:<br>
with torch.no_grad():<br>
x.set</em>(y)<br>
File “D:\src\convert.py”, line 95, in make_mobilenetv2_nnapi<br>
nnapi_model = torch.backends._nnapi.prepare.convert_model_to_nnapi(traced, input_tensor)</p>
<p>How can I solve this problem?</p>

ptrblck: <p>Could you check if you are still hitting the issue using the latest nightly binary?<br>
If so, could you create an issue containing a minimal, executable code snippet to reproduce the error on <a href="https://github.com/pytorch/pytorch/issues">GitHub</a>, please?</p>