Building `pt.diag` is 50x slower than building an Elemwise

Đang mở
#2,631 3 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ó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
48/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
performance

Hướng nghiên cứu

Start by tracing pt.diag(x) through SymbolicOp.__call__ and the AllocDiag construction described in the issue; compare that path with reusing the existing op. Run the included timing snippet to reproduce the slowdown. Done means repeated calls avoid the reported construction cost while preserving correct behavior; the issue leaves open whether to memoize AllocDiag or make OpFromGraph construction cheaper.

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

Mô tả

OpFromGraph performance

pt.diag(x) takes about 1.2 ms to build on 3.3.8. pt.exp(x) takes 0.024 ms. Most of the time goes to SymbolicOp.__call__ making a brand new AllocDiag on every call. Each new one reruns build_inner_graph and the whole OpFromGraph constructor, even when the props and input types match one that already exists.

Reusing an existing AllocDiag takes 0.008 ms, so memoizing the specialized op seems like an obvious thing to try. Maybe that's a hack and the real fix is making OpFromGraph construction cheaper in general? Not sure.

import timeit

import pytensor.tensor as pt

x = pt.vector("x")
diag_op = pt.diag(x).owner.op

# seconds per 1000 calls == ms per call
print(timeit.timeit(lambda: pt.diag(x), number=1000))   # 1.20
print(timeit.timeit(lambda: diag_op(x), number=1000))   # 0.008
print(timeit.timeit(lambda: pt.exp(x), number=1000))    # 0.024
print(pt.diag(x).owner.op is pt.diag(x).owner.op)       # False
Ngôn ngữ chính
Python
Star
654
Fork
258
Merge trung bình
3 ngày 41 phút
Pull request đã merge (30 ngày)
42

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.