pytorch - 💡(How to fix) Fix Hard crash (SIGFPE) on torch.floor_divide with INT_MIN and -1, but Eager mode works normally [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
pytorch/pytorch#184406Fetched 2026-05-20 03:38:54
View on GitHub
Comments
0
Participants
1
Timeline
6
Reactions
0
Participants
Timeline (top)
labeled ×2mentioned ×2subscribed ×2

Error Message

However, when compiled with torch.compile(backend="inductor"), the program hard crashes (segmentation fault / SIGFPE). This happens because Inductor generates raw codegen (C++/Triton) that directly executes the integer division INT_MIN / -1, which triggers a hardware arithmetic exception and instantly kills the entire Python process without a catchable traceback.

Root Cause

However, when compiled with torch.compile(backend="inductor"), the program hard crashes (segmentation fault / SIGFPE). This happens because Inductor generates raw codegen (C++/Triton) that directly executes the integer division INT_MIN / -1, which triggers a hardware arithmetic exception and instantly kills the entire Python process without a catchable traceback.

Code Example

import torch

def f(x, y):
    return torch.floor_divide(x, y)

cf = torch.compile(f, backend="inductor")
x = torch.tensor([-2147483648], dtype=torch.int32)
y = torch.tensor([-1], dtype=torch.int32)
print(cf(x, y), flush=True)
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

When performing integer division (torch.floor_divide) on int32 tensors where the dividend is INT_MIN (-2147483648) and the divisor is -1, Eager mode handles the overflow gracefully (matching PyTorch's ATen wrap-around semantics).

However, when compiled with torch.compile(backend="inductor"), the program hard crashes (segmentation fault / SIGFPE). This happens because Inductor generates raw codegen (C++/Triton) that directly executes the integer division INT_MIN / -1, which triggers a hardware arithmetic exception and instantly kills the entire Python process without a catchable traceback.

Here is a minimal reproducible script comparing Eager mode and Compiled mode:


import torch

def f(x, y):
    return torch.floor_divide(x, y)

cf = torch.compile(f, backend="inductor")
x = torch.tensor([-2147483648], dtype=torch.int32)
y = torch.tensor([-1], dtype=torch.int32)
print(cf(x, y), flush=True)

Versions

PyTorch Version: 2.10.0+cpu

cc @chauhang @penguinwu

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING