Skip to content

viable/strict/1786915540

@andyrobert3 andyrobert3 tagged this 16 Aug 17:11
On MPS/CUDA/x86 CPU, FFT operations failed for tensors with an empty batch
dimension: no backend can plan/execute a transform over a zero-element tensor,
and shape inference under tracing tripped over the empty output as well.

- **MPSGraph** rejects empty tensor placeholders :
  ```
  RuntimeError: [srcBuf length] > 0 INTERNAL ASSERT FAILED at "aten/src/ATen/native/mps/OperationUtils.mm":536, please report a bug to PyTorch. Placeholder tensor is empty!
  ```
- **cuFFT** could not plan over an empty tensor:
  ```
  RuntimeError: cuFFT error: CUFFT_INVALID_SIZE
  # Exception raised from CUFFT_CHECK at aten/src/ATen/native/cuda/CuFFTUtils.h:71, in _fft_c2c_cufft
  ```
- **MKL** (oneMKL DFTI) could not build a descriptor over an empty tensor:
  ```
  RuntimeError: MKL FFT error: Intel oneMKL DFTI ERROR: Inconsistent configuration parameters
  ```
- **Meta** registration could not compute the empty output: under fake/proxy
  tracing the shared `_exec_fft` resizes the functionalized output in place,
  which is rejected for a zero-element (numel-preserving) resize:
  ```
  RuntimeError: tried to directly modify sizes for customized tensor
  # failed while attempting to run meta for aten._fft_c2r.default -> _fft_c2c -> _exec_fft -> out.resize_(...)
  ```

Fixed by short-circuiting empty transforms: the eager kernels (MPS `out=` paths, CUDA/MKL `_exec_fft`) and the Python meta `_exec_fft` resize the output to its expected shape and return early when it has no elements.
The MPS `out=` paths also gained an explicit device check, since the early return skips the device validation that graph execution used to implicitly provide.
Empty-batch coverage is added as a `SampleInput` in the shared FFT OpInfo.

Fixes https://github.com/pytorch/pytorch/issues/190011

Pull Request resolved: https://github.com/pytorch/pytorch/pull/190483
Approved by: https://github.com/malfet

Co-authored-by: Nikita Shulga <nikita.shulga@gmail.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Assets 2
Loading