pytorch - 💡(How to fix) Fix `torch.nansum` with dtype=torch.int64 raises `NotImplementedError` in eager but succeeds in inductor

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…

Error Message

import torch

def fn(x): return torch.nansum(x, dim=1, dtype=torch.int64)

compiled_fn = torch.compile(fn, backend="inductor", fullgraph=True) x = torch.tensor([[float("nan"), 2.0], [3.0, float("nan")]], dtype=torch.float32)

try: eager = fn(x) print("eager returned:", eager) except Exception as exc: eager = type(exc).name + ": " + str(exc) print("eager error:", eager)

try: compiled = compiled_fn(x) print("compiled returned:", compiled) except Exception as exc: compiled = type(exc).name + ": " + str(exc) print("compiled error:", compiled)

Code Example

import torch

def fn(x):
    return torch.nansum(x, dim=1, dtype=torch.int64)

compiled_fn = torch.compile(fn, backend="inductor", fullgraph=True)
x = torch.tensor([[float("nan"), 2.0], [3.0, float("nan")]], dtype=torch.float32)

try:
    eager = fn(x)
    print("eager returned:", eager)
except Exception as exc:
    eager = type(exc).__name__ + ": " + str(exc)
    print("eager error:", eager)

try:
    compiled = compiled_fn(x)
    print("compiled returned:", compiled)
except Exception as exc:
    compiled = type(exc).__name__ + ": " + str(exc)
    print("compiled error:", compiled)

---

eager error: NotImplementedError: "nansum_cpu" not implemented for 'Long'
compiled returned: tensor([2, 3])
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

There is a strict semantic divergence between Eager mode and torch.compile (Inductor backend) when using torch.nansum with dtype=torch.int64 on a float32 tensor containing NaNs.

Eager mode fails and raises NotImplementedError: "nansum_cpu" not implemented for 'Long'.

Inductor successfully lowers the graph, bypasses the missing kernel restriction, and correctly returns the evaluated tensor.

import torch

def fn(x):
    return torch.nansum(x, dim=1, dtype=torch.int64)

compiled_fn = torch.compile(fn, backend="inductor", fullgraph=True)
x = torch.tensor([[float("nan"), 2.0], [3.0, float("nan")]], dtype=torch.float32)

try:
    eager = fn(x)
    print("eager returned:", eager)
except Exception as exc:
    eager = type(exc).__name__ + ": " + str(exc)
    print("eager error:", eager)

try:
    compiled = compiled_fn(x)
    print("compiled returned:", compiled)
except Exception as exc:
    compiled = type(exc).__name__ + ": " + str(exc)
    print("compiled error:", compiled)

Output:

eager error: NotImplementedError: "nansum_cpu" not implemented for 'Long'
compiled returned: tensor([2, 3])

Versions

PyTorch version: 2.10.0+cpu

cc @albanD @mruberry @jbschlosser @walterddr @mikaylagawarecki @malfet @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

pytorch - 💡(How to fix) Fix `torch.nansum` with dtype=torch.int64 raises `NotImplementedError` in eager but succeeds in inductor