pytorch - 💡(How to fix) Fix `torch.compile` + `torch._higher_order_ops.map`: Inductor generates invalid C++ wrapper code (CppCompileError)

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

InductorError: CppCompileError: C++ compile error

Command:
g++ /tmp/.../header.hpp -D TORCH_INDUCTOR_CPP_WRAPPER ...

Code Example

InductorError: CppCompileError: C++ compile error

Command:
g++ /tmp/.../header.hpp -D TORCH_INDUCTOR_CPP_WRAPPER ...

---

import torch
import torch.nn.functional as F

torch.manual_seed(42)
xs = torch.randn(8, 64, device='cuda')  # no requires_grad

def body_fn(x):
    return F.gelu(x)

def fn(xs):
    return torch._higher_order_ops.map(body_fn, xs).sum()

# EagerOK
print(fn(xs))

# CompiledCRASH
torch._dynamo.reset()
fn_c = torch.compile(fn, fullgraph=True)
print(fn_c(xs))  # <-- CppCompileError

---

PyTorch: 2.13.0.dev20260501+cu126
Python: 3.11
CUDA: 12.6
GPU: Tesla T4
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

🐛 Describe the bug

torch.compile(fullgraph=True) with the Inductor backend crashes when compiling a function that uses torch._higher_order_ops.map. The Inductor code generator produces C++ wrapper code that fails to compile with g++. This is a compiler codegen bug, not an API usage issue — the generated code itself is invalid.

  • Eager mode: works fine
  • aot_eager backend: works fine
  • eager backend: works fine
  • Inductor backend: CRASHES (CppCompileError)

The crash occurs even in pure inference mode (no grad, no backward). This is not related to the documented autograd limitation of map.

Error message

InductorError: CppCompileError: C++ compile error

Command:
g++ /tmp/.../header.hpp -D TORCH_INDUCTOR_CPP_WRAPPER ...

To reproduce

import torch
import torch.nn.functional as F

torch.manual_seed(42)
xs = torch.randn(8, 64, device='cuda')  # no requires_grad

def body_fn(x):
    return F.gelu(x)

def fn(xs):
    return torch._higher_order_ops.map(body_fn, xs).sum()

# Eager — OK
print(fn(xs))

# Compiled — CRASH
torch._dynamo.reset()
fn_c = torch.compile(fn, fullgraph=True)
print(fn_c(xs))  # <-- CppCompileError

Without fullgraph=True, a different error occurs (DataDependentOutputException), suggesting Dynamo graph capture also has issues with map.

Versions

Versions

PyTorch: 2.13.0.dev20260501+cu126
Python: 3.11
CUDA: 12.6
GPU: Tesla T4

cc @chauhang @penguinwu @voznesenskym @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @aakhundov @coconutruben @jataylo @ydwu4 @bdhirsh @bobrenjc93 @aorenste

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.compile` + `torch._higher_order_ops.map`: Inductor generates invalid C++ wrapper code (CppCompileError)