Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

A way to specify policies for a specific backend

オープン
#274 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
機能追加
明瞭さ
説明が足りない
活発さ
活発
技術スタック
python
領域
api, backend

調査の方向性

Read the existing controller API and the OpenBLASController implementation, then review how set_num_threads applies limits. The issue presents alternative policy hooks but does not choose a design; first determine which extension point fits the stated backend policies. Done means a selected design supports the intended policies, with tests covering the behavior.

索引モデルが issue の本文から書いたものです。

説明

We have discussed multiple potential examples of having specific policies for specific libraries' backends, mostly OpenBLAS+pthreads:

  • Limit to just 1 core (i.e. inline in current thread) or all cores, don't set any other limits but those two. These are really the most common ones you'd want for a shared process-level thread pool. "All cores" is a concept outside of threadpoolctl's scope, though!
  • Only allow setting limits on the main thread, basically: https://github.com/joblib/joblib/pull/1871#discussion_r4340880131

The current API doesn't have great ergonomics for this though.

One approach is to push policies down into threadpoolctl. But that seems difficult, e.g. "all cores" example above (until Python grows a cpu count API that knows about cgroups, at least).

Another approach is to allow libraries (really, joblib) to hook in and define their own policies.

Potential designs

Replace default controller class with custom controller class

from joblib import cpu_count

from threadpoolctl import OpenBLASController, replace_controller

class JoblibOpenBLASController(OpenBLASController):
    def set_num_threads(self, num_cores):
         if self.threading_layer == "openmp":
             return super().set_num_threads(num_cores)

         cpus = cpu_count()
         if num_cores >= 0.75 * cpus:
             num_cores = cpus
         else
             num_cores = 1
         return super().set_num_threads(num_cores)

replace_controller(OpenBLASController, JoblibOpenBLASController)

Register custom policy just for set_num_threads

from joblib import cpu_count

from threadpoolctl import OpenBLASController

def transform_num_threads(controller, num_cores):
         if controller.threading_layer == "openmp":
             return num_cores

         cpus = cpu_count()
         if num_cores >= 0.75 * cpus:
             return cpus
         else
             return 1
         return super().set_num_threads(num_cores)

OpenBLASController.set_transform_num_threads_before_setting_hook(transform_num_threads)
... other ideas?
主要言語
Python
スター
434
フォーク
38
平均マージ
2日 14時間
マージ済み PR(30日)
8

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

joblib/threadpoolctl のほかの issue

joblib/threadpoolctl の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。