Registry / data / joblibspark

joblibspark

JSON →
library0.6.0pypypi✓ verified 84d ago

Joblibspark provides an Apache Spark backend for the popular joblib library, enabling the distribution of parallel tasks across an Apache Spark cluster. This allows scikit-learn and other joblib-dependent libraries to leverage the distributed computing capabilities of Spark. The current version is 0.6.0, released on April 7, 2025, and the project shows active development and maintenance.

pip install joblibspark
INSTALL
IMPORT
SIG · JOBLIBSPARK
J
joblibspark
datapythonv0.6.0
Install
16.5s avg
Import
Disk
503MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.6.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.940 runs
installs and imports cleanly · install 0.0s · import 0.000s · 507.5MB
glibc
py 3.103.940 runs
installs and imports cleanly · install 16.5s · import 0.000s · 508MB
503MB installed
● package 503MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

register_spark
from joblibspark import register_spark
Registers the Spark backend with joblib.
parallel_backend
from joblib import parallel_backend
Used as a context manager to specify the parallel backend.

This quickstart demonstrates how to register the joblibspark backend and use it with both scikit-learn estimators and custom parallel functions. It assumes a SparkSession is available, either pre-configured in environments like Databricks or initialized locally.

from joblibspark import register_spark from joblib import parallel_backend, Parallel, delayed from pyspark.sql import SparkSession from sklearn.ensemble import RandomForestClassifier from sklearn.datasets import make_classification # Initialize SparkSession (if not already running, e.g., in a Databricks notebook) # In a Databricks notebook, spark variable is usually pre-defined. # For local testing, uncomment and run: # spark = SparkSession.builder.appName("JoblibSparkTest").master("local[*]").getOrCreate() # 1. Register the Spark backend register_spark() # 2. Example with scikit-learn (using a dummy model) X, y = make_classification(n_samples=100, n_features=4, random_state=42) model = RandomForestClassifier(n_estimators=10, random_state=42) print("Fitting model using Spark backend...") with parallel_backend('spark', n_jobs=-1): model.fit(X, y) print("Model fitted successfully.") # 3. Example with a custom parallel function def process_item(item): return item * 2 items = list(range(10)) print(f"Processing items: {items}") with parallel_backend('spark', n_jobs=-1): results = Parallel()(delayed(process_item)(i) for i in items) print(f"Processed results: {results}") # If SparkSession was created manually, stop it # if 'spark' in locals() and isinstance(spark, SparkSession) and spark.sparkContext._jsc.sc().master().startswith('local'): # spark.stop()
Debug
Known issues
gotchaWhen using `joblibspark` with `scikit-learn`, ensure `scikit-learn>=0.21` is installed. Older versions may not correctly leverage the Spark backend for parallel computations.
fix
Upgrade scikit-learn: `pip install -U scikit-learn`
affects: <0.21
gotchaLarge return sizes for individual tasks, especially with many tasks, can lead to `EOFError` or premature executor termination. This often indicates issues with serialization or Spark's result collection limits.
fix
Review Spark configuration parameters such as `spark.driver.maxResultSize`, `spark.network.timeout`, and `spark.executor.heartbeatInterval`. Consider reducing the size of objects returned by tasks or using shared storage for large outputs.
affects: All versions
gotchaThe `sklearn.ensemble.RandomForestClassifier` (and potentially other specific estimators) might not fully utilize the Spark backend for inference, as their internal implementation may bind to built-in single-machine backends.
fix
Verify parallel execution for specific estimator's inference paths. For certain cases, manual parallelization or alternative distributed ML libraries might be necessary.
affects: All versions
gotchaWhen defining functions or classes interactively (e.g., in a Jupyter notebook or `__main__` scope) that are passed to `joblib.Parallel` with the Spark backend, you may encounter pickling errors. `joblibspark` relies on `cloudpickle` for better serialization, but complex or nested closures can still cause issues.
fix
Define functions and classes in separate modules/files that can be imported, rather than in the main script or interactively. Ensure custom classes implement `__reduce__` for robust serialization.
affects: All versions
Errors
Common errors & fixes
EOFError: Ran out of input
Spark executors are terminating prematurely or failing to send large results back to the driver.
fix
Increase Spark configuration settings related to network timeouts and maximum result size, e.g., `spark.driver.maxResultSize` and `spark.network.timeout`. Break down tasks into smaller units if possible to reduce individual result size.
PicklingError: Could not pickle the task to send it to the workers.
Objects (functions, classes, or data) being sent to Spark workers are not serializable by Python's `pickle` or `cloudpickle`.
fix
Ensure all functions and classes used in parallel tasks are defined in modules that can be imported, not in the `__main__` scope. If using custom classes, implement `__reduce__` method for custom serialization logic. Avoid closures that capture complex non-picklable state.
UserWarning: Your sklearn version is < 0.21, but joblib-spark only support sklearn >=0.21 . You can upgrade sklearn to version >= 0.21 to make sklearn use spark backend.
An older version of `scikit-learn` is installed, which `joblibspark` cannot fully integrate with.
fix
Run `pip install -U scikit-learn` to upgrade your `scikit-learn` package to version 0.21 or newer.
Nodes are unused or jobs are unevenly distributed in Spark UI despite using n_jobs=-1 or specific batch_size.
Spark's dynamic allocation, resource manager, or internal scheduling can sometimes lead to uneven distribution, especially for tasks with varying execution times or when resource requests are not optimally aligned with cluster configuration.
fix
While `joblibspark` tries to distribute, fine-tuning Spark's own scheduling parameters (`spark.dynamicAllocation.*`, `spark.executor.cores`, `spark.scheduler.mode`) and the `batch_size` parameter of `joblib.Parallel` might help. Ensure sufficient executors are available and can acquire cores.
Upgrade
Version history
0.6.0latest on PyPI · released Apr 7, 2025
Audit
Dependencies
joblibrequiredCore dependency for parallel processing utilities.
pysparkrequiredRequired to interact with Apache Spark clusters.
scikit-learnoptionalRecommended for full compatibility when using scikit-learn estimators with joblibspark.
Agent activity
19 hits · last 30 days
node
18
OpenAI (training)
1
Resources
joblibspark — pip install joblibspark · libregistry