Skip to main content

nest-joblib

CI Status Documentation Status Test coverage percentage

Poetry black pre-commit

PyPI Version Supported Python versions License

Patch joblib to allow nested parallelism.

Installation

Install this via pip (or your favourite package manager):

pip install nest-joblib

Usage

from nest_joblib import apply

apply()

With the above code, LokyBackend supports nested-parallelism.

Advanced Usage

The following joblib specification of not doing nested-parallelism may be inefficient in an environment with sufficient memory.

joblib/_parallel_backends.py:

    def get_nested_backend(self):
        """Backend instance to be used by nested Parallel calls.

        By default a thread-based backend is used for the first level of
        nesting. Beyond, switch to sequential backend to avoid spawning too
        many threads on the host.
        """
        nesting_level = getattr(self, 'nesting_level', 0) + 1
        if nesting_level > 1:
            return SequentialBackend(nesting_level=nesting_level), None
        else:
            return ThreadingBackend(nesting_level=nesting_level), None

After calling nest_joblib.apply(), when joblib.parallel.register_parallel_backend(name, backend) is called, a subclass of backend with modified get_nested_backend is dynamically generated and registered with the name f"nested-{name}".

from joblib.parallel import parallel_backend
from nest_joblib import apply
from ray.util.joblib import register_ray

# use LokyBackend
apply()

# use DaskDistributedBackend
apply()
parallel_backend("nested-dask")

# use RayBackend
apply()
register_ray()
parallel_backend("nested-ray")

# use custom backend
from joblib.parallel import LokyBackend
apply()
class MyBackend(LokyBackend):
    pass
register_parallel_backend("custom", MyBackend)
parallel_backend("nested-custom")

Contributors ✨

Thanks goes to these wonderful people (emoji key):

34j
34j

💻 🤔 📖

This project follows the all-contributors specification. Contributions of any kind welcome!

Metadata

Release files for nest-joblib 0.1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nest-joblib 0.1.7
File Size Uploaded
nest_joblib-0.1.7.tar.gz 6.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nest-joblib 0.1.7
File Interpreter ABI Platform
nest_joblib-0.1.7-py3-none-any.whl Python 3 none any Details

Total release size: 12.8 kB

Release files / nest_joblib-0.1.7.tar.gz

Download URL nest_joblib-0.1.7.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
f4418292857b94e7c9fe6a19154e965774d4e62357b679f83c33a86eaaf87c51
BLAKE2b-256 checksum
How to use checksums
e01c5eed2ecbe4d52e879ad041517e485404bffe37a822076dddf6d15fb6a9d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.11.2 readme-renderer/44.0 requests/2.32.3 requests-toolbelt/1.0.0 urllib3/2.2.3 tqdm/4.67.0 importlib-metadata/8.5.0 keyring/25.5.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.15

Release files / nest_joblib-0.1.7-py3-none-any.whl

Download URL nest_joblib-0.1.7-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5e33450b5a5a26edfb8a200da345c015bc86d7a67b362830d0999c831420616b
BLAKE2b-256 checksum
How to use checksums
553a829061f4b8b8f84169ce1e4387d161e2babf518bfc3fad8747ceb9d60342
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.11.2 readme-renderer/44.0 requests/2.32.3 requests-toolbelt/1.0.0 urllib3/2.2.3 tqdm/4.67.0 importlib-metadata/8.5.0 keyring/25.5.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.15

Release history Release notifications | RSS feed

This release

0.1.7 This release

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page