Poisson loss function

I’ve implemented the following poisson loss function using the first suggested link:

def poissonLoss(xbeta, y):
    """Custom loss function for Poisson model."""
    loss=torch.mean(torch.exp(xbeta)-y*xbeta)
    return loss

Training:

optimizer=torch.optim.SGD(net.parameters())
lossFn=poissonLoss

output_ = net(input_)
loss = lossFn(output_, target_)
net.zero_grad()
loss.backward()
optimizer.step()

Since I’m using pytorch internals, is this the right way to train/backprop/optimize? Not sure about this because my model is not learning.

Thanks,