PoissonNLLLoss stirling's approximation term not getting added

I’m encountering some unexpected behavior in PyTorch’s PoissonNLLLoss. The full parameter whether set to either True or False, it returns the same answer.

import torch
import torch.nn as nn

criterion = nn.PoissonNLLLoss(log_input = True, full = False, reduction = 'sum')

input = torch.tensor([1.0, 1.0, 1.9, 1.6, -1.9, 3.7, -1.0, 0.5], requires_grad = True)
target = torch.tensor([1.0, 3.0, 1.0, 2.0, 1.0, 4.0, 2.0, 1.0])

loss = criterion(input, target)
print('loss:', loss)
loss.backward()
print('grad:', input.grad)

Output:

loss: tensor(39.1890, grad_fn=<SumBackward0>)
grad: tensor([ 1.9331, -0.3169,  6.3966,  3.3222, -0.9567, 41.0032, -1.8361,  0.7298])

When the value of full is changed to True, there is no change in result. It seems that Stirling’s Approximation term is not getting added. Can someone tell what’s wrong?

Ohh. Got it! It is already solved here https://github.com/pytorch/pytorch/pull/28637/files. Seems like I need to upgrade PyTorch :smiley: