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 joblibsparkVerified import paths — ran on the pinned version, not inferred.
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.
Upgrade scikit-learn: `pip install -U scikit-learn`
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.
Verify parallel execution for specific estimator's inference paths. For certain cases, manual parallelization or alternative distributed ML libraries might be necessary.
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.
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.
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.
Run `pip install -U scikit-learn` to upgrade your `scikit-learn` package to version 0.21 or newer.
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.