I want to compute L1 regularization. I need to iterate over my network parameters and ignore the bias for computing the L1 loss. Is there a function for checking if a parameter is a weight or bias?
Here is my code. Is this the recommended way? I am afraid that the string comparison in every loop may slow down training.
l1_reg = None
for name, W in net.named_parameters():
    if name[-6:] != 'weight':
        continue
    if l1_reg is None:
        l1_reg = W.norm(1)
    else:
        l1_reg = l1_reg + W.norm(1)

Thanks in advance :D.