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.
Metadata
Release files for joblib-modal 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| joblib_modal-0.1.1.tar.gz | 31.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| joblib_modal-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 36.9 kB
Release files / joblib_modal-0.1.1.tar.gz
| Download URL | joblib_modal-0.1.1.tar.gz |
|---|---|
| Size | 31.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3b0fa17eae220046e21da65175a432db304f120b934e62fe9f862ecb5ab02d6b
|
|
BLAKE2b-256 checksum How to use checksums |
8bf4d106c290227223fa7742e7fc7111560260c706ea38c027732d705eaca2a8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 15, 2025.
Transparency logRelease files / joblib_modal-0.1.1-py3-none-any.whl
| Download URL | joblib_modal-0.1.1-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b7b0fd25cbecb289c4d4b88e98a22a2c38ab7eb76e44b59677e7c2d91d51e9fe
|
|
BLAKE2b-256 checksum How to use checksums |
d926fa17797652dbf0c5de49229f8ea2983a01d208cdae9769db172bc498d18a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 15, 2025.
Transparency log