Home

Awesome

* LEGAL NOTICE: Your use of this software and any required dependent software (the "Software Package") is subject to the terms and conditions of the software license agreements for the Software Package, which may also include notices, disclaimers, or license terms for third party or open source software included in or with the Software Package, and your use indicates your acceptance of all such terms. Please refer to the "TPP.txt" or other similarly-named text file included with the Software Package for additional details.
* Optimized Analytics Package for Spark* Platform is under Apache 2.0 (https://www.apache.org/licenses/LICENSE-2.0).

OpenSSF Scorecard OpenSSF Best Practices

Introduction

The Problem

Apache Spark MLlib is a scalable machine learning library based on Spark unified platform. It seamlessly integrates with Spark SQL, Spark Streaming and other machine learning and deep learning frameworks without additional glue code for the entire pipeline.

However, JVM-based MLlib only has limited use of BLAS acceleration and Spark shuffle is also slow for communication during distributed training. Spark's original design is CPU-centric that can't leverage GPU acceleration. It doesn't fully utilize modern CPU and GPU capabilities to achieve best performance.

OAP MLlib Solution

OAP MLlib is a platform optimized package to accelerate machine learning algorithms in Apache Spark MLlib. It is compatible with Spark MLlib and leverages open source Intel® oneAPI Data Analytics Library (oneDAL) to provide highly optimized algorithms and get most out of CPU and GPU capabilities. It also take advantage of open source Intel® oneAPI Collective Communications Library (oneCCL) to provide efficient communication patterns in multi-node multi-GPU clusters.

Who will use OAP MLlib

This solution is intended for researchers, data scientists and enterprise users to accelerate their Spark MLlib algorithms with minimum configuration changes.

Architecture

The following diagram shows the high-level architecture of OAP MLlib.

OAP MLlib Architecture

OAP MLlib maintains the same API interfaces with Spark MLlib. Both Python and Scala languages are supported. That means the application built with Spark MLlib can be running directly with minimum configuration.

Most of the algorithms can produce the same results that are identical with Spark MLlib. However due to the nature of distributed float point operations, there may be some small deviation from the original result, we will make sure the error is within acceptable range and the accuracy is on par with Spark MLlib.

For those algorithms that are not accelerated by OAP MLlib, the original Spark MLlib one will be used.

Online Documentation

You can find the all the OAP MLlib documents on the project web page.

Getting Started

Python/PySpark Users Preferred

Use a pre-built JAR to get started. If you have finished OAP Installation Guide, you can find compiled OAP MLlib JAR oap-mllib-x.x.x.jar in $HOME/miniconda2/envs/oapenv/oap_jars/.

Then you can refer to the following Running section to try out.

Java/Scala Users Preferred

Use a pre-built OAP MLlib JAR to get started, you can download OAP MLlib JAR from Release Page.

Then you can refer to the following Running section to try out.

Building From Scratch

You can also build the package from source code, please refer to Building Code section.

Running

Prerequisites

Supported Spark Versions

Supported Intel® oneAPI Toolkits

Spark Configuration

General Configuration

Standalone Cluster Manager

For using standalone cluster manager, you need to upload the jar to every node or use shared network folder and then specify absolute paths for extraClassPath.

# absolute path of the jar for driver class path
spark.driver.extraClassPath       /path/to/oap-mllib-x.x.x.jar
# absolute path of the jar for executor class path
spark.executor.extraClassPath     /path/to/oap-mllib-x.x.x.jar
YARN Cluster Manager

For users running Spark application on YARN with client mode, you only need to add the following configurations in spark-defaults.conf or in spark-submit command line before running.

# absolute path of the jar for uploading
spark.files                       /path/to/oap-mllib-x.x.x.jar
# absolute path of the jar for driver class path
spark.driver.extraClassPath       /path/to/oap-mllib-x.x.x.jar
# relative path of the jar for executor class path
spark.executor.extraClassPath     ./oap-mllib-x.x.x.jar

Note: Intel GPUs are not fully supported in YARN Cluster Manager, please use Standalone mode.

OAP MLlib Specific Configuration

spark.oap.mllib.device is used to select compute device, you can set it as CPU or GPU. Default value is CPU if it's not specified. Please check List of Accelerated Algorithms for supported algorithms of each compute device.

OAP MLlib adopted oneDAL as implementation backend. oneDAL requires enough native memory allocated for each executor. For large dataset, depending on algorithms, you may need to tune spark.executor.memoryOverhead to allocate enough native memory. Setting this value to larger than dataset size / executor number is a good starting point.

OAP MLlib expects 1 executor acts as 1 oneCCL rank for compute. As spark.shuffle.reduceLocality.enabled option is true by default, when the dataset is not evenly distributed accross executors, this option may result in assigning more than 1 rank to single executor and task failing. The error could be fixed by setting spark.shuffle.reduceLocality.enabled to false.

Sanity Check

Setup env.sh

    $ cd conf
    $ cp env.sh.template env.sh

Edit related variables in "Minimun Settings" of env.sh

Run K-means

    $ cd examples/python/kmeans-pyspark
    $ ./run-cpu.sh

Building Code

Prerequisites

We use Apache Maven to manage and build source code. The following tools and libraries are also needed to build OAP MLlib:

Generally you only need to install Intel® oneAPI Base Toolkit for Linux with all or selected components mentioned above. Intel® oneAPI Base Toolkit can be downloaded and installed from here. Installation process for oneAPI using Package Managers (YUM (DNF), APT, and ZYPPER) is also available. More details about oneAPI can be found here.

Scala and Java dependency descriptions are already included in Maven POM file.

Note: You can refer to this script to install correct dependencies.

Build

To clone and checkout source code, run the following commands:

    $ git clone https://github.com/oap-project/oap-mllib.git

Optional to checkout specific release branch:

    $ cd oap-mllib && git checkout ${version}

We rely on environment variables to find required toolchains and libraries. Please make sure the following environment variables are set for building:

EnvironmentDescription
JAVA_HOMEPath to JDK home directory
DAALROOTPath to oneDAL home directory
TBB_ROOTPath to oneTBB home directory
CCL_ROOTPath to oneCCL home directory

We suggest you to source setvars.sh script into current shell to setup building environments as following:

    $ source /opt/intel/oneapi/setvars.sh

You can also refer to this CI script to setup the building environments.

If you prefer to buid your own open source oneDAL, oneTBB, oneCCL versions rather than use the ones included in oneAPI Base Toolkit, you can refer to the related build instructions and manually source setvars.sh accordingly.

To build, run the following commands:

    $ cd mllib-dal
    $ ../dev/prepare-build-deps.sh
    $ ./build.sh

The built JAR package will be placed in target directory with the name oap-mllib-x.x.x.jar.

Examples

Python Examples

ExampleDescription
kmeans-pysparkK-means example for PySpark
pca-pysparkPCA example for PySpark
als-pysparkALS example for PySpark
random-forest-classifier-pysparkRandom Forest Classifier example for PySpark
random-forest-regressor-pysparkRandom Forest Regressor example for PySpark
correlation-pysparkCorrelation example for PySpark
summarizer-pysparkSummarizer example for PySpark

Scala Examples

ExampleDescription
kmeans-scalaK-means example for Scala
pca-scalaPCA example for Scala
als-scalaALS example for Scala
naive-bayesNaive Bayes example for Scala
linear-regression-scalaLinear Regression example for Scala
correlation-scalaCorrelation example for Scala
summarizer-scalaSummarizer example for Scala

Note: Not all examples have both CPU or GPU version, please check List of Accelerated Algorithms section.

List of Accelerated Algorithms

AlgorithmCPUGPU
K-MeansXX
PCAXX
ALSX
Naive BayesX
Linear RegressionXX
Ridge RegressionX
Random Forest ClassifierX
Random Forest RegressorX
CorrelationXX
SummarizerXX