executorch icon indicating copy to clipboard operation
executorch copied to clipboard

Empty padding issue (op_constant_pad_nd)

Open IgorSwat opened this issue 9 months ago • 0 comments

🐛 Describe the bug

To be honest, I am not sure if this is a bug or an intended behavior, but since the latest 1.1 release performing a padding operation in exported model (op_constant_pad_nd operator, XNNPACK backend), on a tensor which already has desired size (in other words, the padding size is 0) results in a following error:

[op_constant_pad_nd.cpp:102] Check failed (remaining >= copy_len): Out tensor is too small for the copy operation.
[method.cpp:1384] KernelCall failed at instruction 0:14 in operator aten::constant_pad_nd.out: 0x12
[method.cpp:1390] arg 0 with type id 1
[method.cpp:1390] arg 1 with type id 8
[method.cpp:1390] arg 2 with type id 3
[method.cpp:1390] arg 3 with type id 1
[method.cpp:1390] arg 4 with type id 1
Traceback (most recent call last):

  .......

RuntimeError: method->execute() failed with error 0x12

The sample reproduction would include exporting a model with a fragment which looks somewhat like this:

# The error happens at runtime when pad_amount == 0
pad_amount = self.target_amount - x.shape[1]
x_padded = torch.nn.functional.pad(x, (0, pad_amount), value=0)

and then running the exported .pte model with such input that results in pad_amount = 0. I also don't think this happened before the 1.1 release.

Versions

Collecting environment information... PyTorch version: 2.10.0 Is debug build: False CUDA used to build PyTorch: None ROCM used to build PyTorch: N/A

OS: macOS 26.1 (arm64) GCC version: Could not collect Clang version: 17.0.0 (clang-1700.3.19.1) CMake version: version 3.31.10 Libc version: N/A

Python version: 3.12.11 (main, Jun 3 2025, 15:41:47) [Clang 17.0.0 (clang-1700.0.13.3)] (64-bit runtime) Python platform: macOS-26.1-arm64-arm-64bit Is CUDA available: False CUDA runtime version: No CUDA CUDA_MODULE_LOADING set to: N/A GPU models and configuration: No CUDA Nvidia driver version: No CUDA cuDNN version: No CUDA Is XPU available: False HIP runtime version: N/A MIOpen runtime version: N/A Is XNNPACK available: True Caching allocator config: N/A

CPU: Apple M4 Pro

Versions of relevant libraries: [pip3] executorch==1.1.0a0+17adba1 [pip3] numpy==2.3.5 [pip3] optimum-executorch==0.1.0 [pip3] pytorch_tokenizers==1.1.0 [pip3] torch==2.10.0 [pip3] torchao==0.15.0+git9338966da [pip3] torchaudio==2.10.0 [pip3] torchcodec==0.10.0 [pip3] torchdata==0.11.0 [pip3] torchsr==1.0.4 [pip3] torchtune==0.6.1 [pip3] torchvision==0.25.0 [conda] Could not collect

IgorSwat avatar Feb 11 '26 16:02 IgorSwat