Notebooks
A
Amazon Web Services
Parameterize Spark Config Pysparkprocessor Pipeline

Parameterize Spark Config Pysparkprocessor Pipeline

data-scienceinferencearchivedamazon-sagemaker-examplesreinforcement-learningparameterize-spark-config-pysparkprocessor-pipelinemachine-learningawsexamplesdeep-learningsagemakerjupyter-notebooktrainingmlops

Parameterize spark configuration in pipeline PySparkProcessor execution


This notebook's CI test result for us-west-2 is as follows. CI test results in other regions can be found at the end of the notebook.

This us-west-2 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable


Overview

In this example, we demonstrate how we can parameterize spark-configuration in different pipeline PySparkProcessor executions. This example is an extended version of Specifying additional Spark configuration example in Distributed Data Processing using Apache Spark and SageMaker Processing. Here we are creating a simple pipeline with one processing step to demonstrate spark-configuration parameterization capabilities in sagemaker pipeline PySparkProcessor. This could be useful to pipeline users who want to define different spark-configuraitons for different pipeline PySparkProcessor executions.

Prerequisites

To learn about how we can create pipeline, follow this tutorial

Pipeline Creation

The following is the step-by-step process to demonstrate parameterization capabilities in pipeline PySparkProcessor

Step-1: Install the latest SageMaker Python SDK

[ ]

Restart your notebook kernel after upgrading the SDK

Step-2: Setup Environment

[2]

Create prefix for parametrize-spark-config-pysparkprocessor-demo

[3]

Step-3: Prepare Input Data

In this example, we process Abalone Data Set using PySpark script. We download the data locally and upload it to our Amazon S3 bucket for data processing.

[ ]

Step-4: Upload default spark-configuraiton

Upload default spark-configuration to Amazon S3

[5]

Step-5: Define Pipeline Parameters

If no SparkConfigS3Uri is provided to the pipeline execution, the pipeline uses the pre-uploaded default_spark_configuration as a default spark-config.

[6]

Step-6: Write the PySpark script

We create a PySpark script similar to this example. The source for a preprocessing script is in the cell below. This script does some basic feature engineering on a raw input dataset. In this example, the dataset is the Abalone Data Set and the code below performs string indexing, one hot encoding, vector assembly, and combines them into a pipeline to perform these transformations in order. The script then does an 80-20 split to produce training and validation datasets as output.

[7]
[ ]

Step-7: Create PySparkProcessor

Create an instance of an PySparkProcessor to pass in to the processing step.

[ ]

Step-8: Create ProcessingStep and Pipeline

Create a processing step. This step takes in the PySparkProcessor, the input and output channels, and the ./code/preprocess.py script that we created.

[ ]

Now, we have successfully created a sagemaker pipeline with a PySparkProcessor.

Pipeline Executions

Execute pipeline with default spark-configuration

If no SparkConfigS3Uri parameter value is provided, pipeline execution uses default_spark_configuration_object_s3_uri as a default spark-configuration. In the following execution example, we execute PySparkProcessor with default spark-configuration.

[11]
[ ]

We can verify that PySparkProcessor is using the default spark-configuration by looking into the CloudWatch logs.

default configuration

Execute pipeline with a new spark-configuraiton

We upload a new spark-configuration to Amazon S3 and use it in the next pipeline execution

[12]
[13]
[ ]

We can verify that PySparkProcessor is using the newly provided spark-configuration by looking into the CloudWatch logs.

default configuration

Notebook CI Test Results

This notebook was tested in multiple regions. The test results are as follows, except for us-west-2 which is shown at the top of the notebook.

This us-east-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable

This us-east-2 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable

This us-west-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable

This ca-central-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable

This sa-east-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable

This eu-west-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable

This eu-west-2 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable

This eu-west-3 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable

This eu-central-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable

This eu-north-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable

This ap-southeast-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable

This ap-southeast-2 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable

This ap-northeast-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable

This ap-northeast-2 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable

This ap-south-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable