Skip to main content

A Modal backend for Joblib

Project description

Installation

pip install joblib-modal

Usage

This library allows you to use modal as a joblib backend.

It is particularly useful if you’re running a GridSearchCV or similar with scikit-learn.

For direct joblib usage you can do:

# This is needed to register the modal backend
import joblib_modal  # noqa
from joblib import parallel_config, Parallel, delayed

with parallel_config(backend="modal", name="my-test-job",modal_output=True):
    out = Parallel(n_jobs=2)(delayed(lambda x: x * x)(i) for i in range(10))
    assert out == [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]

And for a scikit-learn usage, you can do like the following:

import joblib_modal  # noqa
import modal
import numpy
import joblib
import scipy
import sklearn
from joblib import parallel_config
from sklearn.model_selection import GridSearchCV
from sklearn.ensemble import HistGradientBoostingClassifier
from sklearn.datasets import make_classification

image = (
    modal.Image.debian_slim()
    .pip_install(f"scikit-learn=={sklearn.__version__}")
    .pip_install(f"numpy=={numpy.__version__}")
    .pip_install(f"joblib=={joblib.__version__}")
    .pip_install(f"scipy=={scipy.__version__}")
)

param_grid = {'learning_rate': [0.01, 0.05, 0.1], 'max_depth': [3, 5, 7]}

clf = HistGradientBoostingClassifier()
grid_search = GridSearchCV(clf, param_grid, cv=5, n_jobs=2)
X, y = make_classification()

with parallel_config(
    backend="modal",
    n_jobs=-1,
    name="test-joblib",
    image=image,
    modal_output=True,
):
    grid_search.fit(X, y)

API

The backend is used via the joblib.parallel_config context manager, and in the case of this backend, the signature is:

with parallel_config(
    backend="modal",
    n_jobs: int = 1,
    name: str = None,
    modal_output: bool = False,
    image: modal.Image = None,
    modal_function_kwargs: dict = None,
):
    ...
  • n_jobs: The number of jobs to run in parallel. This specifies the maximum number of concurrent jobs submitted to modal. Note that you’re limited by your maximum number of concurrent jobs in your modal account, and if that is exceeded, the jobs will be queued up and run in order.

  • name: The name of the modal app. If not provided, f"modal-joblib-{uuid.uuid4()}" is used.

  • modal_output: Whether to enable modal output. If enabled, the output of the jobs will be captured and returned. This is equivalent to using the modal.enable_output() context manager.

  • image: The modal image to use for the jobs. If not provided, a debian slim image with joblib installed is used. Your image should always have joblib installed and you should ideally replicate your local environment as closely as possible. See modal.Image for more details.

  • modal_function_kwargs: The kwargs to pass to the modal app.function() decorator. See modal.App.function() for more details.

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

joblib_modal-0.1.1.tar.gz (31.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

joblib_modal-0.1.1-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: joblib_modal-0.1.1.tar.gz
  • Upload date:
  • Size: 31.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for joblib_modal-0.1.1.tar.gz
Algorithm Hash digest
SHA256 3b0fa17eae220046e21da65175a432db304f120b934e62fe9f862ecb5ab02d6b
MD5 c01a499c09afc9e29c64e788ff11ee6d
BLAKE2b-256 8bf4d106c290227223fa7742e7fc7111560260c706ea38c027732d705eaca2a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for joblib_modal-0.1.1.tar.gz:

Publisher: publish.yml on adrinjalali/joblib-modal

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: joblib_modal-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for joblib_modal-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b7b0fd25cbecb289c4d4b88e98a22a2c38ab7eb76e44b59677e7c2d91d51e9fe
MD5 feb569079674ea72cff822b7263019d2
BLAKE2b-256 d926fa17797652dbf0c5de49229f8ea2983a01d208cdae9769db172bc498d18a

See more details on using hashes here.

Provenance

The following attestation bundles were made for joblib_modal-0.1.1-py3-none-any.whl:

Publisher: publish.yml on adrinjalali/joblib-modal

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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