BUG: `config.change_flags` is not thread-safe: concurrent graph construction can permanently clear `config.cxx`
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
- 52/100
Hướng nghiên cứu
Start by reading _ChangeFlagsDecorator in pytensor/configparser.py, then inspect the config.change_flags uses in pytensor/tensor/basic.py and the concurrent reproduction in the issue. Identify how overlapping or recursive scopes affect restoration, and add regression coverage for both cases. Done means concurrent graph construction leaves config.cxx and optdb__max_use_ratio at their original values.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the issue:
config.change_flags saves the current global values on entry and writes them back on exit (pytensor/configparser.py, _ChangeFlagsDecorator). When two threads' scopes over the same flag interleave, the scope that exits last restores the temporary value that the other scope had set:
A enters: saves "g++", sets cxx=""
B enters: saves "", sets cxx=""
A exits: restores "g++"
B exits: restores "" <- process-wide, permanently
Every later scope then saves and restores the corrupted value.
Graph construction enters such a scope. Static-shape inference (pytensor/tensor/basic.py, with config.change_flags(optdb__max_use_ratio=10, cxx="")) runs whenever a shape is symbolic, for example in pt.zeros((n,)). PyMC's resolve_shapes (pymc/pytensorf.py) does the same. Building graphs on several threads at once therefore leaves cxx == "" and optdb__max_use_ratio == 10 for the rest of the process.
A shared decorator instance has the same problem without threads. For example, @config.change_flags(warn_float64="ignore") in pytensor/tensor/basic.py is a single object, and a recursive or concurrent call overwrites the values it saved.
Reproducible code example:
from concurrent.futures import ThreadPoolExecutor
import pytensor
import pytensor.tensor as pt
before = pytensor.config.cxx, pytensor.config.optdb__max_use_ratio
def build(_):
n = pt.lscalar("n")
for _ in range(500):
pt.zeros((n + 1,)) # static-shape inference enters change_flags(cxx="")
with ThreadPoolExecutor(8) as executor:
list(executor.map(build, range(8)))
print(before, (pytensor.config.cxx, pytensor.config.optdb__max_use_ratio))
# ('/usr/bin/g++', 8.0) ('', 10.0)
xs = pt.dvectors(*(f"x{i}" for i in range(33)))
f = pytensor.function(xs, pt.exp(sum(xs)), mode="CVM")
f(*[[0.0]] * 33)
Error message:
NotImplementedError: Elemwise.perform (Python mode) does not support more than 32 operands. Use the C backend or disable Elemwise fusion.
PyTensor version information:
PyTensor 3.3.1 (pip), Python 3.14, Linux x86_64, with g++ as cxx. The same code is on main (332ea8fb7).
Context for the issue:
- Every C-linked function compiled afterwards in the process silently falls back to Python implementations. Already compiled functions are unaffected.
- Fused elemwise graphs with more than 32 operands then raise the error above.
- Python and C implementations differ at rounding level, so seeded results can change without an error, depending on thread timing earlier in the process. I measured differences of about 1e-14 in a downstream PyMC model.
I hit this in a library that fits independent models on worker threads with PyMC. A long-running process lost C compilation after one threaded fit, and an unrelated later computation failed with the error above.
- Ngôn ngữ chính
- Python
- Star
- 654
- Fork
- 258
- Merge trung bình
- 2 ngày 7 giờ
- Pull request đã merge (30 ngày)
- 39
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của pymc-devs/pytensor
-
Docs of mode still mentions C/CVM as the default with FAST_RUNCó thể đã có người làm @ADITYASINGH1206 đã nhận 8 ngày trước. Đang mởdocs
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
pymc-devs/pytensor#2641 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Update conditions page in docsĐang mởdocs
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
BUG: geomspace returns wrong sign for the endpoints when start and stop are negativeCó thể đã có người làm @mayuriphad đã nhận 27 ngày trước. Đang mở
Độ khó 2/5 Dưới một giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Reciprocal.impl computes np.float32(1.0) / x: float32 precision for float64 scalars under NEP 50 (Python linker)Có thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
pymc-devs/pytensor#2430 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
pymc-devs/pytensor#2428 · 5 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của pymc-devs/pytensor
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
dgunning/edgartools#2019 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
topoteretes/cognee#6818 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
source_verification_agent: no outcome when the publisher confirms a work but its DOI resolves to a different recordCó thể đã có người làm @pinjun99 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Imbad0202/academic-research-skills#1159 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: DoubleMLData.from_arrays checks the treatment d with force_all_x_finite instead of force_all_d_finiteCó thể đã có người làm @leninworld đã nhận hôm nay. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
DoubleML/doubleml-for-py#471 ·
Maintainer thường phản hồi trong vòng 1 ngày