Hello,
I want to change dynamically bias=True to False after defining the full-layers. How I should do it.
Hello,
I want to change dynamically bias=True to False after defining the full-layers. How I should do it.
I am not sure if it can be done via nn.Linear class.
But you can define your own custom module with nn.functionalal module.
Somewhere on these lines:
def mylinear(nn.Module):
def __init__(self, nin, nout):
self.W = nn.Parameter(torch.zeros(nin, nout))
self.B = nn.Parameter(torch.zeros(nout))
def forward(self, x, condition):
if condition:
### No bias if condition true
return nn.functional.linear(x, self.W, None)
else:
return nn.functional.linear(x, self.W, self.B)
I think it should do the job