Back Home

GitHub Repo

PyTorch Community Reports CUDA Interpolation Shortcut Bug That May Skip Resampling for Same-Size Outputs

A reproduction on a PyTorch development build shows that CUDA bicubic interpolation may return the input unchanged when a non-integer scale factor still produces the same output dimensions. A fix has been proposed but not merged; the impact on released versions remains unconfirmed.

Pytorch Deepdream (https://github.com/gordicaleksa/pytorch-deepdream) by gordicaleksa (https://github.com/gordicaleksa/pytorch-deepdream/commits?author=gordicaleksa) · MIT · Image source
zh-Hant

On October 3, the PyTorch community reported a silent numerical error in image resampling: in CUDA eager mode, F.interpolate with bicubic interpolation may skip interpolation when the specified scale factor is not one but the calculated output dimensions match the input. The case used development build 2.15.0a0, CUDA 12.6, and an RTX A6000; it does not establish that all released versions are affected. Issue report

The reproduction applies scale_factor=(1.2,1.2), mode='bicubic', and align_corners=False to a 4×4 tensor; the output remains 4×4. Using the CPU double-precision result as a reference, the reporter measured a maximum absolute error of about 1.673 for CUDA eager mode. The CPU single-precision result and CUDA torch.compile path each differed by about one-millionth or less. This comparison shows that the discrepancy is far larger than ordinary floating-point rounding error in this case. Reproduction and measurements

The technical point is that matching output shapes do not imply matching sampling coordinates. The official documentation explains that align_corners=False aligns by pixel boundaries. With recompute_scale_factor=True, PyTorch first determines the output size and then derives the interpolation scale, which can produce different results from using the original scale factor directly. Therefore, checking tensor dimensions alone is not enough to determine whether the operation can be skipped. API documentation

A fix proposed the same day attributes the issue to a “same size means copy” fast path and recommends skipping interpolation only after additionally confirming that an explicit scale factor is one or that no scale factor was supplied. The proposal covers several CPU, CUDA, and quantized kernels, but that is the author’s proposed fix scope; the original reproduction directly supports the CUDA bicubic case. At the time of review, the proposal remained open, with no evidence of a released fix. Fix proposal

For computer vision engineers, this case is a reminder that non-integer scale factors in preprocessing or feature-map resizing may warrant numerical checks on small tensors, not just shape validation. In practice, regression tests can include same-size outputs with non-unit scale factors and compare CPU, CUDA, and compiled paths. Follow-up should track the fix review, affected versions, and validation of other interpolation modes; there is currently no evidence quantifying the effect on real-world model accuracy.

Sources

  1. CUDA F.interpolate(mode="bicubic") incorrectly returns the input when a non-unit scale_factor rounds to the same output size
  2. Fix F.interpolate incorrectly using identity shortcut when scale_factor != 1.0
  3. torch.nn.functional.interpolate — PyTorch 2.14 documentation