It works for me in 1.7.1 using:
#include <torch/torch.h>
#include <iostream>

int main() {
  auto input = torch::randn({3, 10, 24, 24});
  auto target = torch::randint(0, 10, {3, 24, 24}, torch::kLong);
  torch::nn::NLLLoss criterion;
  auto loss = criterion->forward(input, target);
  std::cout << loss << std::endl;
}

Also, note that there are different implementations, such as LossNLL2d.cpp 3, which might accept multiple dimensions (I haven’t checked, which function is called in my example though).