I pruned a simple model and when I try to show all the named_parameters, “weight” and “weight_mask” don’t doesn’t appear despite them existing (as you can see from the last two print statements). Why is this?
import torch.nn as nn
import torch.nn.functional as F
import torch
import torch.nn.utils.prune as prune
class Net(nn.Module):
def __init__(self):
super().__init__()
self.fc1 = nn.Linear(2,5)
self.fc3 = nn.Linear(5, 2)
def forward(self, x):
x = F.relu(self.fc1(x))
x = self.fc3(x)
return x
net = Net()
prune.l1_unstructured(net.fc3, name="weight", amount = 1)
for name, param in net.fc3.named_parameters():
print(name)
# The above only prints weight_orig. It should also print "weight" and "weight_mask"
print(net.fc3.weight)
print(net.fc3.weight_mask)