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