I have been facing this problem for over 8 hours, not being able to understand my problem.
Could anyone try to help?
This is my class for performing the REINFORCE policy gradient:
def update_policy(self, rewards, log_probs, entropies, gamma):
R = torch.zeros(1, 1)
loss = 0
for i in reversed(range(len(rewards))):
R = gamma * R + rewards[i]
loss = loss - (log_probs[i](Variable®.expand_as(log_probs[i]))).sum() - (constantAentropies[i]).sum()
loss = loss / len(rewards)
    optimizer.zero_grad()  #zero up gradients since pytorch accumulates in "backward()"
    loss.backward(retain_graph=True)
    nn.utils.clip_grad_norm_(self.parameters(), 40)
    optimizer.step()

def act(self, state):
mu, sigma = self.forward(Variable(state))
sigma = F.softplus(sigma)
epsilon = torch.randn(mu.size())
action = (mu + sigma.sqrt()Variable(epsilon)).data
prob = normal(action, mu, sigma)
entropy = -0.5((sigma+2*pi.expand_as(sigma)).log()+1)
log_prob = prob.log()
return action, prob, log_prob, entropy
def forward(self, state):
    x = state
    x = (F.relu(self.linear1(x), inplace=True))
    mu = self.linear2(x)
    sigma = self.linear2_(x)
    return mu, sigma

By logs it looks like the problem derives from " sigma = self.linear2_(x)" But I am not entirely sure of that.
Thanks a lot!!