PyTorch Inductor returns NaNs on zero-size interpolate
Compiled F.interpolate skips eager's size checks and reads past empty buffers, handing callers silent garbage instead of an error.
PyTorch's Inductor backend mishandles torch.nn.functional.interpolate when an input has an empty spatial dimension, returning a tensor full of NaNs from an out-of-bounds read instead of failing the way eager mode does.
In eager execution, interpolate rejects zero-length spatial sizes with a clear runtime error that input and output sizes must be greater than zero. Under torch.compile, that validation never runs. The aot_eager path surfaces an index error from the decomposition. Inductor goes further wrong: it accepts the call, emits a kernel that loads past a zero-element buffer with no bounds check, and produces an output of the requested shape filled with uninitialized values. The same pattern appears for nearest, linear, and bilinear modes, on CPU and CUDA, in 2.14 and nightly builds. The reverse case, a non-empty input scaled to a zero output size, is also accepted silently.
For anyone compiling a pipeline that sometimes sees empty batches, the practical result is NaN contamination downstream rather than the exception eager would have raised. On CUDA, the same unchecked load is an illegal memory access waiting to happen. The flaw is in the lowering: the generated kernel never guards the empty-buffer case that eager treats as invalid.