How to save a modified model

Is there any good way to save the network structure after pruning so that it can be loaded directly?

How did you prune the model? If you’ve removed certain nodes, the state_dict should contain all necessary parameters.

I extracted the parameters via model.state_dict, and removed the channel according to a certain threshold.Give an example below:
conv1 = self.conv1(x)
conv2 = self.conv2(conv1 )

conv1 param (output_channel1,input_channel1,kernel_x,kernel_y)
conv2 param (output_channel2,output_channel1,kernel_x,kernel_y)

remove 20% param in output_channel1 and after removed
conv1 param (output_channel1 x 80%,input_channel1,kernel_x,kernel_y)
conv2 param (output_channel2,output_channel1 x 80%,kernel_x,kernel_y)

I purned the model channel , but if I want to use this purned parameter, I have to modify the this is very troublesome.I think that loading the purned parameters first, reading the corresponding number of channels, and passing the number of channels per layer when generating the network can solve this problem.But I feel that this kind of practice is also more troublesome. I would like to ask you what better way, let me save the structure and parameters directly after purning the parameters.

@ptrblck Hi, do you know how to solve this problem

I’m not sure if there is a better way than to prune the model and save the state_dict with the new model definition.
If you would like to keep the same model definition, you could work with masks to prune the parameters, but I guess that’s not really what you want.

Thank you for your answer