GitHub Repo
PyTorch Community Reports Inductor Loss Function Validation Bug: Mismatched Target Dimensions May Still Return a Value
An October 8 reproduction on a PyTorch development build found that Inductor-compiled nll_loss may accept targets with incorrect spatial dimensions and calculate a loss. The same inputs raise an exception in eager and aot_eager, but the impact on released versions and any fix remain unconfirmed.

On October 8, the PyTorch community filed a minimal reproduction involving training correctness: when torch.nn.functional.nll_loss receives targets with mismatched spatial dimensions, ordinary eager execution and torch.compile(backend="aot_eager") both reject the input. With Inductor, however, the function returns a loss tensor. The report used development build 2.15.0a0+git1a080e5; the issue remains open, and its page does not list a fix PR. Community report
The example uses an input of (2, 3, 2, 2), representing two samples, three classes, and spatial dimensions of two by two; the target has shape (2, 2, 1). The official documentation specifies that for multidimensional negative log-likelihood loss, the target shape should match the input dimensions after removing the class axis. The expected shape here is therefore (2, 2, 2). The documentation also requires the input to contain log-probabilities and target values to fall within the valid class range. API documentation
Notably, the reproduction uses random values as input. Its focus is whether the invalid shape is rejected, not whether a particular loss value is reasonable. aot_eager also traces and executes the computation graph, yet still raises an exception; based on this comparison, the reporter pointed to Inductor’s lowering or decomposition path. This is a clue supported by the backend comparison, not a root cause confirmed by maintainers. Reproduction and backend comparison
For engineering teams, this kind of difference could delay detection of a data preprocessing shape error. For example, if a pixel classification pipeline produces targets with the wrong width, checking only whether the loss is a finite number could miss a violation of the input contract. This risk is inferred from the example; the report does not demonstrate a full training run, gradient results, or a decline in model quality.
Teams using compiled training can check shapes before data reaches the loss function and include deliberately malformed targets in comparison tests across eager and compiled backends. Next, watch for upstream confirmation of affected versions, restoration of the shape check, and regression tests for exception behavior. The available evidence is insufficient to conclude that all released versions or inputs with valid shapes are affected.