microsoft / nni

An open source AutoML toolkit for automate machine learning lifecycle, including feature engineering, neural architecture search, model compression and hyper-parameter tuning.
https://nni.readthedocs.io
MIT License
14.06k stars 1.82k forks source link

TypeError: Conv2d.forward() missing 1 required positional argument: 'input' #5572

Open Yanni-Chen opened 1 year ago

Yanni-Chen commented 1 year ago

Describe the issue: I am trying to use NNI to prune and speed up the compressed model. However, when using ModelSpeedup, a Type error occurs. TypeError: Conv2d.forward() missing 1 required positional argument: 'input'

Environment:

Configuration:

I test the DNN models cloned from https://github.com/kuangliu/pytorch-cifar. The Resent18 models are trained with their own script.

Then, I use the following configures to prune the trained model

config_list = [{ 'sparsity_per_layer': sparsity,
'op_types': ['Conv2d', 'Linear'] }, { 'exclude': True, 'op_names': ['module.conv1', 'module. Linear'] }] pruner = L1NormPruner(model, configlist) , masks = pruner.compress() for name, mask in masks.items(): print(name, ' sparsity : ', '{:.2}'.format(mask['weight'].sum() / mask['weight'].numel())) pruner._unwrap_model() dummy_input = torch.rand(8, 3, 32, 32).to(next(model.parameters ()).device) ModelSpeedup(model, (dummy_input), masks).speedup_model()

The output log information is

屏幕截图 2023-05-22 105441

屏幕截图 2023-05-22 105307

J-shang commented 1 year ago

hello @Yanni-chen , we have released a new speedup version, you could have a try:

pip install nni=3.0rc1

from nni.compression.pytorch.speedup.v2 import ModelSpeedup
Yanni-Chen commented 1 year ago

Hello @J-shang, I installed the new version with pip install nni==3.0rc. However, when running 'from nni.compression.pytorch.speedup.v2 import ModelSpeedup', A new imported error occurred.

image

J-shang commented 1 year ago

hello @Yanni-Chen , I think this may case by your typeguard version, could you reinstall typeguard?

Yanni-Chen commented 1 year ago

Hello @J-shang, I installed typeguard by 'conda install ypeguard'. Then, a RuntimeError reported image