inplace_elemwise retries an input it already rejected, once per Elemwise output

Đang mở
#2,665 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
Nửa ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
compilers, performance

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

compilation graph rewriting performance

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.

Ngôn ngữ chính
Python
Star
655
Fork
266
Merge trung bình
3 ngày 23 giờ
Pull request đã merge (30 ngày)
43

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của pymc-devs/pytensor

Tất cả issue của pymc-devs/pytensor

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.