pytorch - 💡(How to fix) Fix [inductor] Numerical inconsistency: polygamma + cumulative_trapezoid under torch.compile(dynamic=True) produces wrong results after Conv2d + GroupNorm

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

Eager and compiled outputs have the same shape but contain drastically different values — the compiler silently produces wrong results without any error or warning.

  • Both eager and compiled modes complete without any error — this is a silent correctness bug (INCON type).

Root Cause

Root cause hypothesis

One or both of these Inductor lowerings likely have a numerical correctness issue under symbolic shapes:

Code Example

import torch
import torch.nn as nn

torch.set_grad_enabled(False)

class Model(nn.Module):
    def __init__(self):
        super().__init__()
        self.conv1 = nn.Conv2d(3, 16, kernel_size=3, padding=1)
        self.gn1 = nn.GroupNorm(num_groups=4, num_channels=16)

    def forward(self, x):
        x = self.conv1(x)
        x = self.gn1(x)
        x = torch.polygamma(0, x + 0.1)
        x = x.unsqueeze(2)
        x = torch.cumulative_trapezoid(x)
        return x

model = Model()
x = torch.randn(1, 3, 32, 32)

res_eager = model(*[x])
res_compiled = torch.compile(model, dynamic=True)(x)

print("Max diff:", (res_eager - res_compiled).abs().max().item())
# Output: Max diff: 1420.1875
# The max diff is non-deterministic (varies between 31 and 1420 across runs due to random input), but always present.

---

PyTorch version: 2.13.0.dev20260521+cu126
OS: Linux (Ubuntu 20.04)
Python: 3.12
CUDA: 12.6
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

Under torch.compile(dynamic=True) , a model combining Conv2d → GroupNorm → polygamma → cumulative_trapezoid produces numerically incorrect outputs compared to eager mode, despite both completing without errors. The maximum absolute difference is 1420.2 , indicating a correctness bug in Inductor's lowering or fusion for this operator combination.

Eager and compiled outputs have the same shape but contain drastically different values — the compiler silently produces wrong results without any error or warning.

Minimal repro

import torch
import torch.nn as nn

torch.set_grad_enabled(False)

class Model(nn.Module):
    def __init__(self):
        super().__init__()
        self.conv1 = nn.Conv2d(3, 16, kernel_size=3, padding=1)
        self.gn1 = nn.GroupNorm(num_groups=4, num_channels=16)

    def forward(self, x):
        x = self.conv1(x)
        x = self.gn1(x)
        x = torch.polygamma(0, x + 0.1)
        x = x.unsqueeze(2)
        x = torch.cumulative_trapezoid(x)
        return x

model = Model()
x = torch.randn(1, 3, 32, 32)

res_eager = model(*[x])
res_compiled = torch.compile(model, dynamic=True)(x)

print("Max diff:", (res_eager - res_compiled).abs().max().item())
# Output: Max diff: 1420.1875
# The max diff is non-deterministic (varies between 31 and 1420 across runs due to random input), but always present.

Result

Both outputs have identical shape but the values differ by up to 1420 . The discrepancy is widespread across the tensor, not isolated to a few elements.

Root cause hypothesis

One or both of these Inductor lowerings likely have a numerical correctness issue under symbolic shapes:

  • torch.polygamma(0, x) — the digamma function, polygamma of order 0
  • torch.cumulative_trapezoid(x) — cumulative trapezoidal integration When dynamic=True , Inductor cannot statically determine the integration axis length, which may cause:
  1. An incorrect decomposition or fusion of polygamma with surrounding ops
  2. A numerically unstable approximation in cumulative_trapezoid under symbolic dimensions

Additional context

  • Both eager and compiled modes complete without any error — this is a silent correctness bug (INCON type).
  • Removing dynamic=True or any single operator from the chain may mask the problem.
  • The max diff is non-deterministic (varies between 31 and 1420 across runs due to random input), but always present.

Versions

PyTorch version: 2.13.0.dev20260521+cu126
OS: Linux (Ubuntu 20.04)
Python: 3.12
CUDA: 12.6

cc @mruberry @kshitij12345 @chauhang @penguinwu @ezyang @bobrenjc93 @aditvenk @laithsakka @voznesenskym @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @aakhundov @coconutruben @jataylo

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 [inductor] Numerical inconsistency: polygamma + cumulative_trapezoid under torch.compile(dynamic=True) produces wrong results after Conv2d + GroupNorm