inplace_elemwise retries an input it already rejected, once per Elemwise output
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- Half a day
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- python
- Domain
- compilers, performance
Research direction
The retry loop is in InplaceGraphOptimizer.try_inplace_on_node, which calls tried_inputs.discard(i) after an InconsistencyError; the inplace_elemwise rewrite in pytensor/tensor/rewriting/elemwise.py drives it. Run the 400-output snippet with the py linker and time it, then compare against the excluded-rewrite run. Done when compile time drops substantially and the in-place node count in the test suite is unchanged.
Written by the indexing model from the issue text.
Description
inplace_elemwise, the rewriter that lets Elemwise nodes overwrite their inputs, takes time close to cubic in the number of outputs of a fused Elemwise whose inputs can't be destroyed. When an attempt raises InconsistencyError, InplaceGraphOptimizer.try_inplace_on_node calls tried_inputs.discard(i) and offers the same input to the next output. Every reason DestroyHandler rejects a destroy depends on the input, not the output, so each retry fails, and each one replaces and reverts all of the node's outputs.
import time
import pytensor
import pytensor.tensor as pt
from pytensor.compile.mode import Mode
x = pt.matrix("x", shape=(7, 7))
X = x @ x
outputs = [pt.exp(X + k) for k in range(400)] # fused into one Elemwise with 400 outputs
y = pt.join(0, X, *outputs) # reads X and every output, so X can't be destroyed
start = time.perf_counter()
pytensor.function([x], y, mode=Mode(linker="py", optimizer="fast_run"))
print(f"{time.perf_counter() - start:.1f} s") # 13.1 s
# workaround: Mode(linker="py", optimizer="fast_run").excluding("inplace_elemwise") compiles in 0.4 s
inplace_elemwise alone takes 0.07, 0.38, 2.15 and 13.8 s at 50, 100, 200 and 400 outputs. In a real graph with a 364-output Elemwise feeding a 1114-input Scan, rewriting took 66 s. With the retry removed it took 30 s, and the compiled graph had the same 1369 nodes and 210 in-place nodes.
- Dominant language
- Python
- Stars
- 655
- Forks
- 266
- Avg merge
- 3d 23h
- Merged PRs (30d)
- 43
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from pymc-devs/pytensor
-
BUG: cumsum and cumprod keep bool and small integer dtypes, so cumsum(x > 0) is wrongPossibly taken @rishabhsai claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Docs of mode still mentions C/CVM as the default with FAST_RUNPossibly taken @ADITYASINGH1206 claimed this 13 days ago. Opendocs
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
pymc-devs/pytensor#2641 · 1 comment ·
Maintainers usually reply within 1 day
-
Update conditions page in docsPossibly taken @caxaxa claimed this 3 days ago. Opendocs
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
BUG: geomspace returns wrong sign for the endpoints when start and stop are negativePossibly taken @mayuriphad claimed this 32 days ago. Open
Difficulty 2/5 Under an hour Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
Reciprocal.impl computes np.float32(1.0) / x: float32 precision for float64 scalars under NEP 50 (Python linker)May be free again A pull request for this issue was closed without being merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
pymc-devs/pytensor#2430 · 1 comment ·
Maintainers usually reply within 1 day
All issues in pymc-devs/pytensor
Similar issues
-
triage
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
kornia/kornia-rs#1416 · 1 comment ·
Maintainers usually reply within 2 days
-
ui
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
PolicyEngine/ai-inequality#64 ·
Maintainers usually reply within 1 day
-
LinearGaussianStateSpace.dist splits states and observations wrongly when the transition varies over timePossibly taken @PabloRoque claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
pymc-devs/pymc-extras#839 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day