`threadpool_limits(1, user_api="blas")` also limits OpenMP to 1 thread with OpenBLAS's OpenMP threading layer (3.7.0)
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
- 35/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 from the OpenBLAS controller's set_num_threads in threadpoolctl, where it now calls omp_set_num_threads for the OpenMP threading layer, and from the reproduction script that prints the OpenMP thread count under threadpool_limits(limits=1, user_api="blas"). Done means the BLAS limit no longer changes the OpenMP count for the current thread, with the 3.6.0 behaviour restored. The maintainer has not settled the fix, so check the comment thread for a decided approach before writing code.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
Since 3.7.0, with OpenBLAS's OpenMP threading layer, limiting BLAS also limits the OpenMP runtime of the current thread: inside threadpool_limits(limits=1, user_api="blas"), omp_get_max_threads() returns 1, so any OpenMP parallel region started from this thread without an explicit num_threads runs on a single thread. With 3.6.0 and the same OpenBLAS (0.3.34), it stays at 8.
It comes from set_num_threads of the OpenBLAS controller, which now calls omp_set_num_threads when the threading layer is OpenMP, to get a limit per thread rather than per process. But OpenBLAS and the caller share the same OpenMP runtime, so the BLAS limit becomes an OpenMP limit too.
In scikit-learn, the usual pattern for nested parallelism is to limit BLAS to 1 thread around Cython code that calls BLAS inside OpenMP prange loops. Any code that reads the number of OpenMP threads inside that limit now gets 1.
For instance, a KMeans fitted under threadpool_limits(1, user_api="blas") now runs its OpenMP code on 1 thread (see below).
I'm not sure what the best fix is, maybe just some documentation?
Steps/Code to Reproduce
import numpy as np # loads OpenBLAS
from threadpoolctl import threadpool_info, threadpool_limits
def openmp_num_threads():
return [i["num_threads"] for i in threadpool_info() if i["user_api"] == "openmp"]
print("openmp num_threads:", openmp_num_threads())
with threadpool_limits(limits=1, user_api="blas"):
print("openmp num_threads under blas limit 1:", openmp_num_threads())
With scikit-learn:
import numpy as np
from threadpoolctl import threadpool_limits
from sklearn.cluster import KMeans
X = np.random.RandomState(0).randn(1000, 5)
with threadpool_limits(limits=1, user_api="blas"):
print(KMeans(3, n_init=1).fit(X)._n_threads)
Expected Results
With OMP_NUM_THREADS=8:
openmp num_threads: [8]
openmp num_threads under blas limit 1: [8]
and 8 for KMeans._n_threads. That's what 3.6.0 gives.
Actual Results
openmp num_threads: [8]
openmp num_threads under blas limit 1: [1]
and 1 for KMeans._n_threads.
Versions
MacBook Pro M2 (macOS 26.6.2), conda-forge packages:
python 3.13.16
numpy 2.5.4
libopenblas 0.3.34 openmp_h5e6e99c_1 (threading_layer: openmp, VORTEX)
llvm-openmp 23.1.3
threadpoolctl 3.7.0
- Ngôn ngữ chính
- Python
- Star
- 434
- Fork
- 38
- Merge trung bình
- 2 ngày 9 giờ
- Pull request đã merge (30 ngày)
- 7
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
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 joblib/threadpoolctl
-
Make it possible to set active/spin wait behavior of LLVM/Intel OpenMP via `kmp_set_blocktime`Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
joblib/threadpoolctl#271 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Make it possible to inspect active/spin wait behavior of LLVM/Intel OpenMP via `kmp_get_blocktime`Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 42/100
joblib/threadpoolctl#270 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 1-2 ngày Mức phù hợp với người mới 32/100
joblib/threadpoolctl#264 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 22/100
joblib/threadpoolctl#261 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Opt-in API that has a cached `ThreadpoolController`Có thể đã có người làm @itamarst đã nhận 26 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
joblib/threadpoolctl#254 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của joblib/threadpoolctl
Issue tương tự
-
wr.dynamodb.read_items returns [{}] for a single partition value that does not existCó thể đã có người làm @auraseb đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
aws/aws-sdk-pandas#3520 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
requires triage typing
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
sqlalchemy/sqlalchemy#13704 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Edit tool converts CRLF files to LFCó thể đã có người làm @RaphaelFakhri đã 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
huggingface/tau#774 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
show ignores the row limit when a column or table name contains "limit"Có thể đã có người làm @RaphaelFakhri đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
What happened to `check.py`?Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
linebender/resvg#1179 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày