Skip to main content

Patch joblib to allow nested parallelism

Project description

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!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nest_joblib-0.1.1.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

nest_joblib-0.1.1-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file nest_joblib-0.1.1.tar.gz.

File metadata

  • Download URL: nest_joblib-0.1.1.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/42.0 requests/2.31.0 requests-toolbelt/1.0.0 urllib3/2.0.6 tqdm/4.66.1 importlib-metadata/6.8.0 keyring/24.2.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.13

File hashes

Hashes for nest_joblib-0.1.1.tar.gz
Algorithm Hash digest
SHA256 3c9aed71ce289c7e7b84a2f12c940e87f25bca6c3cf1800d6c1532c3358b9a2d
MD5 e9aa455df2811c561b29b2bd831dd56a
BLAKE2b-256 ea5e129f4fafeed9857840afbdbabd3c658d0b25b9bf87a5925315e238b93e8c

See more details on using hashes here.

File details

Details for the file nest_joblib-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: nest_joblib-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/42.0 requests/2.31.0 requests-toolbelt/1.0.0 urllib3/2.0.6 tqdm/4.66.1 importlib-metadata/6.8.0 keyring/24.2.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.13

File hashes

Hashes for nest_joblib-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b75f46e7f80f962d0170f10937291da7bdc5d82ed7dc554be5bde3a9f3868839
MD5 de58c12bdba67c284b0701b442ad31a2
BLAKE2b-256 43f0221de893b26d2725f90f5f23dce74d69bdaf8dc22690eded1fecdf96e22e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page