I am trying to do the same thing as your question, so i write the following code, but it don’t work. Have you find any solution?
loss_func = t.nn.MSELoss()
optimizer = t.optim.SGD(net.parameters(), lr)

# train the neural network
for epoch in range(EPOCH):
    for i, data in enumerate(train_loader):
        inputs, labels = data
        inputs, labels = Variable(inputs), Variable(labels)
        prediction = net(inputs)
        loss = loss_func(prediction, labels)
        for name, param in net.named_parameters():
            if 'weight' in name:
                L1_1 = Variable(param, requires_grad=True)
                L1_2 = t.norm(L1_1, 1)
                L1_3 = L1_lambda * L1_2
                loss = loss + L1_3
        optimizer.zero_grad()
        loss.backward()
        optimizer.step()