if you want to filter out weight decay only for biases (i.e. have weight decay for weights, but no weight decay for biases), then you can use the per-parameter optimization options, like described here: http://pytorch.org/docs/optim.html#per-parameter-options 464
To get the biases out of the model, you can use model.named_parameters() 119
Here is an example that might help:

  
      github.com
  
  
    pytorch/pytorch/blob/master/test/test_nn.py#L461-L487 202

    module.zero_grad()
    self.assertEqual(module.weight.grad.data, module.weight.data.clone().zero_())
    self.assertEqual(module.bias.grad.data, module.bias.data.clone().zero_())


def test_no_grad(self):
    module = nn.Conv2d(2, 5, kernel_size=3, padding=1)
    input = torch.randn(1, 2, 10, 10)
    x = Variable(input)
    y = Variable(input.clone())


    output = module(x)
    self.assertTrue(output.requires_grad)
    output.backward(torch.ones(1, 5, 10, 10))


    with torch.no_grad():
        output2 = module(y)
        self.assertFalse(output2.requires_grad)
        self.assertRaises(RuntimeError, lambda: output2.backward(torch.ones(1, 5, 10, 10)))


def _test_dropout(self, cls, input):


  This file has been truncated. show original