pytorch - ✅(Solved) Fix explore using gmpy2 to accelerate expression eval in sympy [1 pull requests, 1 participants]

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…
GitHub stats
pytorch/pytorch#181525Fetched 2026-04-27 05:28:48
View on GitHub
Comments
0
Participants
1
Timeline
18
Reactions
0
Participants
Timeline (top)
labeled ×6mentioned ×6subscribed ×6

PR fix notes

PR #181277: Preserve symbolic relationships in after-aot repro scripts

Description (problem / solution / changelog)

Stack from ghstack (oldest at bottom):

  • -> #181277
  • #181276
  • #181275
  • #179091
  • #179090
  • #176927

When an after-aot repro script serializes symint inputs, it previously stored only the concrete hint value (e.g., reader.symint(160)), discarding the symbolic expression. When run_repro retraces with tracing_mode='symbolic', each symint becomes an independent symbol, losing algebraic relationships like sym_size_int_65 = (s0 + s3 + ... + s97) // 160 + 866. This causes make_fx to produce a graph with many independent symbols instead of a few related ones, which prevents reproducing compile-time pathologies caused by wide symbolic expressions (e.g., 50+ min compiles from 64-variable polynomial GCD).

Changes:

  • InputWriter.symint now emits the expression alongside the hint: reader.symint(160, expr='s0') for free symbols, and reader.symint(930, expr='((...sum...)//160) + 866') for derived.
  • InputReader.symint accepts the optional expr kwarg and stores the index-to-expression mapping in symint_exprs.
  • repro_common, when tracing_mode='symbolic' and expressions are available, calls _build_symbolic_wrapper() to build a wrapper module that takes carrier tensors for free symbols, extracts SymInts via .size(0), computes derived expressions via Python arithmetic, and delegates to the inner Repro. make_fx then traces the wrapper, preserving the algebraic structure.
  • Backward-compatible: old repro scripts without expr= still work (fall back to independent-symbol behavior).

Authored with Claude.

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @kadeng @chauhang @amjames @Lucaskabela @jataylo @azahed98

Changed files

  • torch/_dynamo/debug_utils.py (modified, +10/-3)
  • torch/_dynamo/repro/after_aot.py (modified, +94/-0)
RAW_BUFFERClick to expand / collapse

sympy is all python, some libraries exists to accelerate it using c++ binding gmpy2 try them out in examples such that those addressed in https://github.com/pytorch/pytorch/pull/181277

cc @jerryzh168 @chauhang @penguinwu @ezyang @bobrenjc93 @aditvenk

extent analysis

TL;DR

Explore using libraries like gmpy2 to accelerate SymPy with C++ bindings for improved performance.

Guidance

  • Investigate gmpy2 documentation and tutorial to understand its capabilities and integration with SymPy.
  • Review the examples addressed in the PyTorch pull request (#181277) to see how gmpy2 is utilized.
  • Consider testing gmpy2 with SymPy in relevant examples to evaluate potential performance enhancements.
  • Collaborate with mentioned team members (@jerryzh168, @chauhang, @penguinwu, @ezyang, @bobrenjc93, @aditvenk) to discuss implementation and potential challenges.

Notes

The effectiveness of using gmpy2 with SymPy may depend on specific use cases and performance requirements.

Recommendation

Apply workaround: Explore gmpy2 integration with SymPy to potentially improve performance, as it offers C++ bindings that could accelerate certain computations.

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 - ✅(Solved) Fix explore using gmpy2 to accelerate expression eval in sympy [1 pull requests, 1 participants]