-
Notifications
You must be signed in to change notification settings - Fork 801
Description
🐛 Describe the bug
I have a model with a mean operator. When I convert the model to the channels last memory format and export to a .pte file, the inference crashes. I am using the executor_runner, and I get the following error:
I 00:00:00.001024 executorch:executor_runner.cpp:440] Method loaded.
E 00:00:00.001070 executorch:tensor_util_portable.cpp:130] Check failed (all_contiguous || all_channels_last): 2 input tensors have different dim orders
E 00:00:00.001102 executorch:op_mean.cpp:37] Check failed (tensors_have_same_dim_order(in, out)):
E 00:00:00.001114 executorch:method.cpp:1376] KernelCall failed at instruction 0:0 in operator aten::mean.out: 0x12
E 00:00:00.001120 executorch:method.cpp:1386] arg 0 with type id 1
E 00:00:00.001124 executorch:method.cpp:1386] arg 1 with type id 8
E 00:00:00.001127 executorch:method.cpp:1386] arg 2 with type id 5
E 00:00:00.001131 executorch:method.cpp:1386] arg 3 with type id 0
E 00:00:00.001134 executorch:method.cpp:1386] arg 4 with type id 1
E 00:00:00.001171 executorch:method.cpp:1386] arg 5 with type id 1
F 00:00:00.001179 executorch:executor_runner.cpp:485] In function main(), assert failed (status == Error::Ok): Execution of method forward failed with status 0x12
The issue is that the mean operator has input with the channels last dim order, but the output is contiguous, which causes an assertion error in op_mean.cpp:37. I believe the lowering process should not produce the mean operator with different input/output dim orders, but instead the node should compute in channels last, and the dim_order_ops._clone_dim_order should be inserted after, to change the dim order to contiguous.
I am attaching the .pte model in question. The code to reproduce the model creation:
import torch
from executorch.exir.capture._config import ExecutorchBackendConfig
from executorch.exir.program._program import to_edge_transform_and_lower
from torch.export import export
class MeanModel(torch.nn.Module):
def __init__(self):
super().__init__()
def forward(self, x):
x = torch.mean(x, dim=[2, 3], keepdim=True)
return x.reshape([-1, 2])
def to_executorch_program(model, example_input):
exir_program_aten = torch.export.export(model, example_input, strict=True)
partitioners = []
edge_program_manager = to_edge_transform_and_lower(
export(exir_program_aten.module(), example_input, strict=True),
partitioner=partitioners,
)
return edge_program_manager.to_executorch(
config=ExecutorchBackendConfig(extract_delegate_segments=False)
)
if __name__ == "__main__":
model = MeanModel().eval().to(memory_format=torch.channels_last)
input_tensor = (torch.randn(1, 2, 3, 4).to(memory_format=torch.channels_last),)
executorch_program_manager = to_executorch_program(model, input_tensor)
executorch_program_manager.save("channels_last_mean_bug.pte")Versions
Collecting environment information...
PyTorch version: 2.10.0.dev20251025+cpu
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A
OS: Ubuntu 20.04.6 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-2ubuntu1~20.04) 11.4.0
Clang version: Could not collect
CMake version: version 3.31.10
Libc version: glibc-2.31
Python version: 3.10.12 (main, Oct 1 2025, 11:13:47) [GCC 9.4.0] (64-bit runtime)
Python platform: Linux-6.6.87.2-microsoft-standard-WSL2-x86_64-with-glibc2.31
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:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
Address sizes: 46 bits physical, 48 bits virtual
CPU(s): 16
On-line CPU(s) list: 0-15
Thread(s) per core: 2
Core(s) per socket: 8
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 186
Model name: 13th Gen Intel(R) Core(TM) i5-1350P
Stepping: 2
CPU MHz: 2188.810
BogoMIPS: 4377.62
Virtualization: VT-x
Hypervisor vendor: Microsoft
Virtualization type: full
L1d cache: 384 KiB
L1i cache: 256 KiB
L2 cache: 10 MiB
L3 cache: 12 MiB
NUMA node0 CPU(s): 0-15
Vulnerability Gather data sampling: Not affected
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Mmio stale data: Not affected
Vulnerability Reg file data sampling: Mitigation; Clear Register File
Vulnerability Retbleed: Mitigation; Enhanced IBRS
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2: Mitigation; Enhanced / Automatic IBRS; IBPB conditional; RSB filling; PBRSB-eIBRS SW sequence; BHI BHI_DIS_S
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Not affected
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology tsc_reliable nonstop_tsc cpuid tsc_known_freq pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves avx_vnni vnmi umip waitpkg gfni vaes vpclmulqdq rdpid movdiri movdir64b fsrm md_clear serialize flush_l1d arch_capabilities
Versions of relevant libraries:
[pip3] executorch==1.1.0a0+a069bba
[pip3] flake8==6.1.0
[pip3] flake8-breakpoint==1.1.0
[pip3] flake8-bugbear==24.4.26
[pip3] flake8-comprehensions==3.14.0
[pip3] flake8-plugin-utils==1.3.3
[pip3] flake8-pyi==23.5.0
[pip3] mypy==1.14.1
[pip3] mypy_extensions==1.1.0
[pip3] numpy==2.0.0
[pip3] optree==0.18.0
[pip3] pytorch_tokenizers==1.0.1
[pip3] torch==2.10.0.dev20251025+cpu
[pip3] torchao==0.14.0+git01849b2b1
[pip3] torchaudio==2.10.0.dev20251025+cpu
[pip3] torchdata==0.11.0
[pip3] torchsr==1.0.4
[pip3] torchtune==0.6.1
[pip3] torchvision==0.25.0.dev20251025+cpu
[conda] Could not collect
Metadata
Metadata
Assignees
Labels
Type
Projects
Status