Pruning yolox model with [aten::arange/aten::meshgrid/aten::stack] is not Supported!
See original GitHub issueWhen I prune YOLOX model I get an error info.
I need to prune yolox model using torch.arange/torch.meshgrid/torch.stack in yolox_head.
Triggered error during model speed-up phase:
ERROR (nni.compression.pytorch.speedup.jit_translate/MainThread) aten::arange is not Supported! Please report an issue at https://github.com/microsoft/nni. Thanks~
INFO (nni.compression.pytorch.speedup.compressor/MainThread) Update mask for head.aten::arange.288
ERROR (nni.compression.pytorch.speedup.jit_translate/MainThread) aten::arange is not Supported! Please report an issue at https://github.com/microsoft/nni. Thanks~
INFO (nni.compression.pytorch.speedup.compressor/MainThread) Update mask for backbone.C3_n3.conv3.conv
INFO (nni.compression.pytorch.speedup.compressor/MainThread) Update mask for head.aten::meshgrid.289
ERROR (nni.compression.pytorch.speedup.jit_translate/MainThread) aten::meshgrid is not Supported! Please report an issue at https://github.com/microsoft/nni. Thanks~
INFO (nni.compression.pytorch.speedup.compressor/MainThread) Update mask for backbone.C3_n3.conv3.bn
INFO (nni.compression.pytorch.speedup.compressor/MainThread) Update mask for head.prim::ListUnpack.290
INFO (nni.compression.pytorch.speedup.compressor/MainThread) Update mask for backbone.C3_n3.conv3.act
INFO (nni.compression.pytorch.speedup.compressor/MainThread) Update mask for head.aten::stack.291
ERROR (nni.compression.pytorch.speedup.jit_translate/MainThread) aten::stack is not Supported! Please report an issue at https://github.com/microsoft/nni. Thanks~
INFO (nni.compression.pytorch.speedup.compressor/MainThread) Update mask for backbone.bu_conv1.conv
nni Environment :
- nni version: 2.7
- nni mode(local|pai|remote): local
- OS: Ubuntu 18.04
- python version: 3.8
- is conda or virtualenv used?: YES
- is running in docker?: NO
Try to modify in jit_translate.py: create a fun:
def arange_python(node, speedup):
class arangeModule(torch.nn.Module):
def forward(self, x):
return torch.arange(int(x))
return arangeModule
and add the maping 'aten::arange': arange_python
in trans_from_jit_to_python
but still error:
[2022-05-25 10:14:08] INFO (nni.compression.pytorch.speedup.compressor/MainThread) Update mask for head.aten::arange.287
2022-05-25 10:14:08 | ERROR | yolox.core.launch:98 - An error has been caught in function 'launch', process 'MainProcess' (5735), thread 'MainThread' (140500556732224):
Traceback (most recent call last):
File "/home/yq/pycharm_project/YOLOX-main/tools/prune.py", line 315, in <module>
launch(
β <function launch at 0x7fc7fcfa4280>
> File "/home/yq/pycharm_project/YOLOX-main/yolox/core/launch.py", line 98, in launch
main_func(*args)
β β (βββββββββββββββββββββ€βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ...
β <function main at 0x7fc7efe648b0>
File "/home/yq/pycharm_project/YOLOX-main/tools/prune.py", line 154, in main
model = prune_main(model, "cuda:0")
β β YOLOX(
β (backbone): YOLOPAFPN(
β (backbone): CSPDarknet(
β (stem): Focus(
β (conv): BaseConv(
β (conv): ...
β <function prune_main at 0x7fc7ef859e50>
File "/home/yq/pycharm_project/YOLOX-main/tools/prune.py", line 298, in prune_main
ModelSpeedup(model, torch.rand(1, 3, 640, 640), masks).speedup_model()
β β β β β {'backbone.backbone.stem.conv.conv': {'weight': tensor([[[[1., 1., 1.],
β β β β [1., 1., 1.],
β β β β [1., 1., 1.]],
β β β β
β β β β ...
β β β β <built-in method rand of type object at 0x7fc8accc4520>
β β β <module 'torch' from '/home/yq/anaconda3/envs/yolox-py38/lib/python3.8/site-packages/torch/__init__.py'>
β β YOLOX(
β (backbone): YOLOPAFPN(
β (backbone): CSPDarknet(
β (stem): Focus(
β (conv): BaseConv(
β (conv): ...
β <class 'nni.compression.pytorch.speedup.compressor.ModelSpeedup'>
File "/home/yq/anaconda3/envs/yolox-py38/lib/python3.8/site-packages/nni/compression/pytorch/speedup/compressor.py", line 512, in speedup_model
self.infer_modules_masks()
β β <function ModelSpeedup.infer_modules_masks at 0x7fc7e0a6c700>
β <nni.compression.pytorch.speedup.compressor.ModelSpeedup object at 0x7fc7c71e93d0>
File "/home/yq/anaconda3/envs/yolox-py38/lib/python3.8/site-packages/nni/compression/pytorch/speedup/compressor.py", line 355, in infer_modules_masks
self.update_direct_sparsity(curnode)
β β β name: head.aten::arange.287, type: func, op_type: aten::arange, sub_nodes: ['__module.head_aten::arange'], inputs: ['6522'], ...
β β <function ModelSpeedup.update_direct_sparsity at 0x7fc7e0a6c550>
β <nni.compression.pytorch.speedup.compressor.ModelSpeedup object at 0x7fc7c71e93d0>
File "/home/yq/anaconda3/envs/yolox-py38/lib/python3.8/site-packages/nni/compression/pytorch/speedup/compressor.py", line 216, in update_direct_sparsity
_auto_infer = AutoMaskInference(
β <class 'nni.compression.pytorch.speedup.infer_mask.AutoMaskInference'>
File "/home/yq/anaconda3/envs/yolox-py38/lib/python3.8/site-packages/nni/compression/pytorch/speedup/infer_mask.py", line 83, in __init__
self.output = self.module(*dummy_input)
β β β β [80]
β β β <class 'nni.compression.pytorch.speedup.jit_translate.arange_python.<locals>.arangeModule'>
β β <nni.compression.pytorch.speedup.infer_mask.AutoMaskInference object at 0x7fc7c6decca0>
β <nni.compression.pytorch.speedup.infer_mask.AutoMaskInference object at 0x7fc7c6decca0>
TypeError: __init__() takes 1 positional argument but 2 were given
I donβt know how to fix it, hope to get your help πΊ
Issue Analytics
- State:
- Created a year ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How to Train YOLOX On a Custom Dataset - Roboflow Blog
In this post, we will walk through how you can train YOLOX to recognize object detection data for your custom use case.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
thank u, I want to try it myself first. β
Iβm very sorry, I found out that this is a bug created by me while modifying the nni source code. I RE-installed the nni and only modified the
jit_translate.py
define the arange_python:add
'aten::arange': arange_python
intrans_from_jit_to_python
The real debug info is as follows:
It seems to call
arange_python
twice in thespeedup/compressor.py
Init class
AutoMaskInference
for the first time.dummy_input is assigned to
[tensor[0]]
and is called a second time in member functionupdate_direct_sparsity()
.Finally,
arange_python
returns an empty tensor which caused sebsequent errors.I donβt know how to fix it, please help.