pytorch - 💡(How to fix) Fix `torch.remainder` returns incorrect results with float16 tensor and Python scalar on Inductor CPU [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#183083Fetched 2026-05-11 03:12:53
View on GitHub
Comments
0
Participants
1
Timeline
3
Reactions
0
Participants
Timeline (top)
labeled ×3

Code Example

import torch

def f(x):
    return torch.remainder(x, 3.14)

x = torch.tensor(
    [-4.0, -1.5, -0.0, 0.0, 0.1, 1.0, 3.140625, 8.0],
    dtype=torch.float16,
)

eager = f(x)
compiled = torch.compile(f, backend="inductor")(x)

print("eager =", eager)
print("compiled =", compiled)

---

eager = tensor([2.2812, 1.6406, -0.0000, 0.0000, 0.1000, 1.0000, 0.0000, 1.7188],
       dtype=torch.float16)
compiled = tensor([2.2793e+00, 1.6396e+00, 0.0000e+00, 0.0000e+00, 9.9976e-02, 1.0000e+00,
        6.2466e-04, 1.7197e+00], dtype=torch.float16)
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

torch.compile with the Inductor CPU backend returns a different result from eager mode for torch.remainder when the input is a float16 tensor and the divisor is a Python float scalar.

Reproducer

import torch

def f(x):
    return torch.remainder(x, 3.14)

x = torch.tensor(
    [-4.0, -1.5, -0.0, 0.0, 0.1, 1.0, 3.140625, 8.0],
    dtype=torch.float16,
)

eager = f(x)
compiled = torch.compile(f, backend="inductor")(x)

print("eager =", eager)
print("compiled =", compiled)

Output:

eager = tensor([2.2812, 1.6406, -0.0000, 0.0000, 0.1000, 1.0000, 0.0000, 1.7188],
       dtype=torch.float16)
compiled = tensor([2.2793e+00, 1.6396e+00, 0.0000e+00, 0.0000e+00, 9.9976e-02, 1.0000e+00,
        6.2466e-04, 1.7197e+00], dtype=torch.float16)

Versions

PyTorch version: 2.10.0+cpu

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