my mu cannot have any valid gradient somehow, here is the code:
import torch
torch.manual_seed(0)
mu = torch.zeros(1, requires_grad=True)
sigma = 1.0
eps = torch.randn(1)
sampled = mu + sigma * eps
logp = -((sampled - mu)**2) / 2 - 0.5 * torch.log(torch.tensor(2 * torch.pi))
loss = -logp.sum()
loss.backward()
print("eps:", eps.item())
print("mu.grad:", mu.grad.item()) # should be -eps.item()
I consistently get zero grad, is this normal?