Hello pytorchers,
I would like to specify the weights used by my model during its forward pass. I basically have 2 sets of weights.
2  >    class Policy(nn.Module):
>  23         
>  24         def __init__(self,hidden_size,num_inputs,action_space):
>  25                 super(Policy,self).__init__()
>  26                 self.action_space = action_space
>  27                 self.num_outputs = action_space.shape[0]
>  28                 self.num_inputs = num_inputs
>  29                 self.hidden_size = hidden_size
>  30 
>  31                 self.fc1 = nn.Linear(self.num_inputs,self.hidden_size)
>  32                 self.mean = nn.Linear(self.hidden_size,self.num_outputs)
>  33                 self.std = nn.Linear(self.hidden_size,self.num_outputs)
>  34 
>  35         def forward(self,inputs,weights=None):
>  36                 x = F.relu(F.linear(inputs,weights['fc1.weight'],weights['fc1.bias']))
>  37                 mu = F.linear(x,weights['mean.weight'],weights['mean.bias'])
>  38                 sigma_sq = F.linear(x,weights['std.weight'],weights['std.bias'])
>  39                 sigma_sq = torch.exp(sigma_sq)
>  40                 return mu,sigma_sq

Q. Is this the right way to do it?
My forward function has a weights argument and I use the functional form of the Linear layer so that I can explicitly specify the weights.
I am not sure about my init() function where I declare self.fc1,self.mean and self.std. The main reason for doing this is so that I can create my two sets of weights with the same named parameters like so :
model = Policy()      
base_weights = OrderedDict((name, param) for (name, param) in model.named_parameters())`

Thanks in advance,
Gautam