Repository navigation
Description
🐛 Describe the bug
The portable integer div kernel computes val_a / val_b before it applies the requested rounding mode. For INT_MIN / -1 that signed division overflows on x86-64: idiv raises #DE, which the OS delivers as SIGFPE. The process is terminated inside execute(); there is no Python exception to catch. Eager ATen explicitly handles this pair (c10/util/generic_math.h:62) and returns INT_MIN for floor mode.
The same crash occurs for int32 and int64, for the tensor and scalar divisor forms, and for broadcast inputs (the first offending lane is enough). Normal values, including negative operands, are correct, so this is a missing overflow check rather than a wrong div implementation.
Root cause.
kernels/portable/cpu/op_div.cpp (v1.6.0 and current main) divides before applying the mode:
// div_out_mode, tensor divisor, :151
CTYPE_COMPUTE value = val_a / val_b;
// div_scalar_mode_out, :277
CTYPE_COMPUTE value = val_a / val_b;The mode handling (std::trunc / utils::floor_divide) happens afterwards. kernels/portable/cpu/util/math_util.h:34 repeats the unguarded a / b in the integer floor_divide overload. ATen guards exactly this case before dividing:
if (a == std::numeric_limits<scalar_t>::min() && b == scalar_t(-1))
return a;Reproduction
Save as repro.py and run it in a subprocess, because the failure kills the interpreter:
import subprocess, sys, tempfile
import torch
class M(torch.nn.Module):
def forward(self, a, b):
return torch.div(a, b, rounding_mode="floor")
a = torch.tensor([-2147483648], dtype=torch.int32)
b = torch.tensor([-1], dtype=torch.int32)
print("eager:", M()(a, b).tolist()) # [-2147483648]
from torch.export import export
import executorch.exir as exir
edge = exir.to_edge_transform_and_lower(export(M(), (a, b))) # no delegate
p = tempfile.mktemp(suffix=".pte")
with open(p, "wb") as f:
edge.to_executorch().write_to_file(f)
code = f"""
import torch
from executorch.runtime import Runtime
p = {p!r}
a = torch.tensor([-2147483648], dtype=torch.int32)
b = torch.tensor([-1], dtype=torch.int32)
out = Runtime.get().load_program(p).load_method("forward").execute([a, b])
print(out[0].tolist())
"""
r = subprocess.run([sys.executable, "-c", code])
print("child return code:", r.returncode) # -8 (136 in a shell)Output:
Expected (eager ATen, same build):
div([-2147483648], [-1], floor) = [-2147483648]
Actual (ExecuTorch 1.6.0 portable):
child return code: -8 # SIGFPE, no traceback
Normal-input control (same exported program):
eager [7, -7, 8] / [2, 2, 2] = [3, -4, 4]
portable [7, -7, 8] / [2, 2, 2] = [3, -4, 4]
int64 behaves the same (INT64_MIN / -1). int8/int16 do not crash because C++ integer promotion performs the division in int.
Error
The child process dies with signal 8 (SIGFPE); there is no traceback.
child return code: -8
$ echo $? # when the repro is run as a shell command
136
Versions
Collecting environment information...
PyTorch version: 2.15.0+cpu
Is debug build: False
CUDA used to build PyTorch: Could not collect
ROCm SDK used to build PyTorch: N/A
HIP used to build PyTorch: N/A
OS: Ubuntu 22.04.4 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.35
Python version: 3.13.12 | packaged by Anaconda, Inc. | (main, Feb 24 2026, 16:13:31) [GCC 14.3.0] (64-bit runtime)
Python platform: Linux-6.8.0-100-generic-x86_64-with-glibc2.35
Is CUDA available: False
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration:
GPU 0: NVIDIA A800-SXM4-80GB
GPU 1: NVIDIA A800-SXM4-80GB
GPU 2: NVIDIA A800-SXM4-80GB
GPU 3: NVIDIA A800-SXM4-80GB
GPU 4: NVIDIA A800-SXM4-80GB
GPU 5: NVIDIA A800-SXM4-80GB
GPU 6: NVIDIA A800-SXM4-80GB
GPU 7: NVIDIA A800-SXM4-80GB
Nvidia driver version: 580.95.05
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.9.3.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv.so.9.3.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn.so.9.3.0
/usr/lib/x86_64-linux-gnu/libcudnn_engines_precompiled.so.9.3.0
/usr/lib/x86_64-linux-gnu/libcudnn_engines_runtime_compiled.so.9.3.0
/usr/lib/x86_64-linux-gnu/libcudnn_graph.so.9.3.0
/usr/lib/x86_64-linux-gnu/libcudnn_heuristic.so.9.3.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops.so.9.3.0
Is XPU available: False
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: False
Caching allocator config: N/A
CPU:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Address sizes: 46 bits physical, 57 bits virtual
Byte Order: Little Endian
CPU(s): 128
On-line CPU(s) list: 0-127
Vendor ID: GenuineIntel
BIOS Vendor ID: Intel(R) Corporation
Model name: Intel(R) Xeon(R) Platinum 8358P CPU @ 2.60GHz
BIOS Model name: Intel(R) Xeon(R) Platinum 8358P CPU @ 2.60GHz
CPU family: 6
Model: 106
Thread(s) per core: 2
Core(s) per socket: 32
Socket(s): 2
Stepping: 6
CPU max MHz: 3400.0000
CPU min MHz: 800.0000
BogoMIPS: 5200.00
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 intel_ppin ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local split_lock_detect wbnoinvd dtherm ida arat pln pts vnmi avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq la57 rdpid fsrm md_clear pconfig flush_l1d arch_capabilities
Virtualization: VT-x
L1d cache: 3 MiB (64 instances)
L1i cache: 2 MiB (64 instances)
L2 cache: 80 MiB (64 instances)
L3 cache: 96 MiB (2 instances)
NUMA node(s): 2
NUMA node0 CPU(s): 0-31,64-95
NUMA node1 CPU(s): 32-63,96-127
Vulnerability Gather data sampling: Mitigation; Microcode
Vulnerability Indirect target selection: Vulnerable
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Mmio stale data: Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed: Not affected
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; PBRSB-eIBRS SW sequence; BHI SW loop, KVM SW loop
Vulnerability Srbds: Not affected
Vulnerability Tsa: Not affected
Vulnerability Tsx async abort: Not affected
Vulnerability Vmscape: Not affected
Versions of relevant libraries:
[pip3] executorch==1.6.0
[pip3] numpy==2.4.4
[pip3] nvidia-cublas==13.10.0.20
[pip3] nvidia-cuda-cupti==13.5.25
[pip3] nvidia-cuda-nvrtc==13.5.37
[pip3] nvidia-cuda-runtime==13.5.37
[pip3] nvidia-cuda-runtime-cu13==0.0.0a0
[pip3] nvidia-cudnn-cu13==9.26.0.51
[pip3] onnx==1.23.2
[pip3] onnxruntime==1.32.0
[pip3] optree==0.19.1
[pip3] pytorch_tokenizers==1.6.0
[pip3] tf2onnx==1.17.0
[pip3] torch==2.15.0+cpu
[pip3] torchao==0.18.0
[conda] numpy 2.4.4 pypi_0 pypi
[conda] optree 0.19.1 pypi_0 pypi
Activity
Fix INT_MIN / -1 overflow in portable integer div and floor_divide (p…