Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

A way to specify policies for a specific backend

未关闭
#274 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
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 小时
30 天内合并 PR
8

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

joblib/threadpoolctl 的其他 Issue

查看 joblib/threadpoolctl 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。