pytorch - 💡(How to fix) Fix insert_deferred_runtime_asserts shall not prune all torch checks on inputs [1 participants]

Official PRs (…)
ON THIS PAGE

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#182703Fetched 2026-05-07 03:30:35
View on GitHub
Comments
0
Participants
1
Timeline
14
Reactions
0
Participants
Timeline (top)
mentioned ×5subscribed ×5labeled ×4

Root Cause

insert_deferred_runtime_asserts (in torch/fx/passes/runtime_assert.py) currently prunes the inline _assert_scalar for input-bound checks because the ShapeEnv range info is considered to already cover them. This is wrong: user-written torch._check calls should never be dropped from the graph body — they're part of the model's semantics, not just hints to the tracer. The pruning is especially harmful under torch.compile (no ep.module() wrapper) where the check then has no runtime effect at all.

RAW_BUFFERClick to expand / collapse

insert_deferred_runtime_asserts (in torch/fx/passes/runtime_assert.py) currently prunes the inline _assert_scalar for input-bound checks because the ShapeEnv range info is considered to already cover them. This is wrong: user-written torch._check calls should never be dropped from the graph body — they're part of the model's semantics, not just hints to the tracer. The pruning is especially harmful under torch.compile (no ep.module() wrapper) where the check then has no runtime effect at all.

Fix should ensure user-emitted asserts are preserved while still allowing dedup of compiler-internal redundant ones.

at least do not prone ones that checks more than >=0?

cc @chauhang @penguinwu @ezyang @bobrenjc93 @aditvenk

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 insert_deferred_runtime_asserts shall not prune all torch checks on inputs [1 participants]