Threadpoolctl
The
ThreadPoolCTLPlugin
if useful for parallel training of models. Without limiting with
threadpoolctl, the number of threads used by a given model may
oversubscribe to resources and cause significant slowdowns.
This is the mechanism employed by scikit-learn to limit the number of threads used by a given model.
See threadpoolctl documentation.
Requirements
This requires threadpoolctl which can be installed with:
Usage
from amltk.scheduling import Scheduler
from amltk.scheduling.plugins.threadpoolctl import ThreadPoolCTLPlugin
scheduler = Scheduler.with_processes(1)
def f() -> None:
# ... some task that respects the limits set by threadpoolctl
pass
task = scheduler.task(f, plugins=ThreadPoolCTLPlugin(max_threads=1))
╭─ Task f() -> 'None' ─────────────────────────────────────────────────────────╮
│ ╭────────────────────── Plugin threadpoolctl-plugin ───────────────────────╮ │
│ │ Max Threads User-API │ │
│ │ 1 None │ │
│ ╰──────────────────────────────────────────────────────────────────────────╯ │
│ @on_submitted │
│ @on_done │
│ @on_result │
│ @on_exception │
│ @on_cancelled │
╰─────────────────────────────── Ref: 18aMFtQy ────────────────────────────────╯
class ThreadPoolCTLPlugin(max_threads=None, user_api=None)
#
Bases: Plugin
A plugin that limits the usage of threads in a task.
This plugin is used to make utilize threadpoolctl with tasks, useful for parallel training of models. Without limiting with threadpoolctl, the number of threads used by a given model may oversubscribe to resources and cause significant slowdowns.
| ATTRIBUTE | DESCRIPTION |
|---|---|
max_calls |
The maximum number of calls to the task.
|
max_concurrent |
The maximum number of calls of this task that can be in the queue.
|
| PARAMETER | DESCRIPTION |
|---|---|
max_threads |
The maximum number of threads to use. |
user_api |
The user API to limit.
TYPE:
|
Source code in src/amltk/scheduling/plugins/threadpoolctl.py
name: ClassVar
classvar
attr
#
The name of the plugin.
def attach_task(task)
#
def pre_submit(fn, *args, **kwargs)
#
Pre-submit hook.
Wrap the function in something that will activate threadpoolctl when the function is called.
Source code in src/amltk/scheduling/plugins/threadpoolctl.py
def copy()
#
Return a copy of the plugin.
Please see Plugin.copy().