This is very likely because the input is a negative number.
Since logarithmic function has the domain x>0, you have to ensure that the input is non-negative and non-zero.
I would use a non-linearity like ReLU or sigmoid to ensure non-negativity and then add a small ‘epsilon’ to ensure non-zero:
eps=1e-7
t = F.relu(t)
t = torch.log(t +eps)

All operations on nan result in nan, so everything will become nan quickly.