pytorch - 💡(How to fix) Fix `torch.compile` silently returns a result for `torch.linalg.cholesky` on non-positive-definite input

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

A = torch.tensor( [ [1.0, 2.0], [2.0, 1.0], ], dtype=torch.float32, )

def fn(x): return torch.linalg.cholesky(x)

try: y_eager = fn(A) print("eager ok:") print(y_eager) except Exception as e: print("eager error:") print(type(e).name) print(e)

try: compiled_fn = torch.compile(fn, backend="inductor", fullgraph=True) y_compiled = compiled_fn(A) print("compiled ok:") print(y_compiled) except Exception as e: print("compiled error:") print(type(e).name) print(e)

Root Cause

try: compiled_fn = torch.compile(fn, backend="inductor", fullgraph=True) y_compiled = compiled_fn(A) print("compiled ok:") print(y_compiled) except Exception as e: print("compiled error:") print(type(e).name) print(e)

Output:

eager error: _LinAlgError linalg.cholesky: The factorization could not be completed because the input is not positive-definite (the leading minor of order 2 is not positive-definite). compiled ok: tensor([[ 1.0000, 0.0000], [ 2.0000, -3.0000]])

Code Example

import torch

A = torch.tensor(
    [
        [1.0, 2.0],
        [2.0, 1.0],
    ],
    dtype=torch.float32,
)

def fn(x):
    return torch.linalg.cholesky(x)

try:
    y_eager = fn(A)
    print("eager ok:")
    print(y_eager)
except Exception as e:
    print("eager error:")
    print(type(e).__name__)
    print(e)

try:
    compiled_fn = torch.compile(fn, backend="inductor", fullgraph=True)
    y_compiled = compiled_fn(A)
    print("compiled ok:")
    print(y_compiled)
except Exception as e:
    print("compiled error:")
    print(type(e).__name__)
    print(e)

---

eager error:
_LinAlgError
linalg.cholesky: The factorization could not be completed because the input is not positive-definite (the leading minor of order 2 is not positive-definite).
compiled ok:
tensor([[ 1.0000,  0.0000],
        [ 2.0000, -3.0000]])
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

Describe the bug

torch.linalg.cholesky correctly raises an error in eager mode when the input matrix is not positive-definite. However, when the same function is compiled with torch.compile(..., backend="inductor", fullgraph=True), the compiled function silently returns a tensor instead of raising an error.

Reproducer

import torch

A = torch.tensor(
    [
        [1.0, 2.0],
        [2.0, 1.0],
    ],
    dtype=torch.float32,
)

def fn(x):
    return torch.linalg.cholesky(x)

try:
    y_eager = fn(A)
    print("eager ok:")
    print(y_eager)
except Exception as e:
    print("eager error:")
    print(type(e).__name__)
    print(e)

try:
    compiled_fn = torch.compile(fn, backend="inductor", fullgraph=True)
    y_compiled = compiled_fn(A)
    print("compiled ok:")
    print(y_compiled)
except Exception as e:
    print("compiled error:")
    print(type(e).__name__)
    print(e)

Output:

eager error:
_LinAlgError
linalg.cholesky: The factorization could not be completed because the input is not positive-definite (the leading minor of order 2 is not positive-definite).
compiled ok:
tensor([[ 1.0000,  0.0000],
        [ 2.0000, -3.0000]])

Versions

PyTorch version: 2.10.0+cpu

cc @malfet @jianyuh @nikitaved @mruberry @walterddr @xwang233 @Lezcano @chauhang @penguinwu @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 `torch.compile` silently returns a result for `torch.linalg.cholesky` on non-positive-definite input