i’m manipulating it during training as follow
 with torch.no_grad():
            paramet = list(net.parameters())
            for j in range(200):
                if j not in rows:
                    rows.append(j)             
                    i = random.randint(0,199) 
                    k = random.randint(0,199)
                    save_weight_indexes( (i , k) )        
                    net.fc2.weight[i][k]  = 0. 


i used  WITH TORCH.NO_GRADIENT to wrap the loop and set the weights to zero
Here is my training code
freeze = True
    for epoch in range(2):
        for batch_idx, (data, target) in enumerate(train_loader):
            data, target = Variable(data), Variable(target)

            # resize data from (batch_size, 1, 28, 28) to (batch_size, 28*28)
            data = data.view(-1, 28*28)
            optimizer.zero_grad()                                           
            net_out = net(data)         
            loss = criterion(net_out , target)    
            
            loss.backward()
            remove_random_connections(freeze)  
            freeze = False
            optimizer.step()