Using NeuronCore Pipeline with PyTorch Tutorial

Overview

In this tutorial we will benchmark latency of a Hugging Face Transformers model deployed in model pipeline paralle mode using the NeuronCore Pipeline feature. We will compare the results with the usual data parallel (multi-worker) deployment. We compile a pretrained BERT base model and run the benchmarking locally.

To enable faster enviroment setup, We will run both compilation and deployment (inference) on an single inf1.6xlarge instance. You can take similar steps to recreate the benchmark on other instance sizes, such as inf1.xlarge.

If you already have an Inf1 instance environment ready, this tutorial is availabe as a Jupyter notebook at neuroncore_pipeline_pytorch.ipynb and instructions can be viewed at:

Instructions of how to setup the environment and run the tutorial are available in the next sections.

Setup The Environment

Launch an Inf1 instance by following the below steps, please make sure to choose an inf1.6xlarge instance.

  • Please follow the instructions at launch an Amazon EC2 Instance to Launch an Inf1 instance, when choosing the instance type at the EC2 console. Please make sure to select the correct instance type. To get more information about Inf1 instances sizes and pricing see Inf1 web page.

  • When choosing an Amazon Machine Image (AMI) make sure to select Deep Learning AMI with Conda Options. Please note that Neuron Conda packages are supported only in Ubuntu 16 DLAMI, Ubuntu 18 DLAMI and Amazon Linux2 DLAMI, Neuron Conda packages are not supported in Amazon Linux DLAMI.

  • After launching the instance, follow the instructions in Connect to your instance to connect to the instance

Note

You can also launch the instance from AWS CLI, please see AWS CLI commands to launch inf1 instances.

Run The Tutorial

After connecting to the instance from the terminal, clone the Neuron Github repository to the EC2 instance and then change the working directory to the tutorial directory:

git clone https://github.com/aws/aws-neuron-sdk.git
cd aws-neuron-sdk/src/examples/pytorch

The Jupyter notebook is available as a file with the name neuroncore_pipeline_pytorch.ipynb, you can either run the Jupyter notebook from a browser or run it as a script from terminal:

  • Running tutorial from browser

    • First setup and launch the Jupyter notebook on your local browser by following instructions at Jupyter Notebook QuickStart

    • Open the Jupyter notebook from the menu and follow the instructions

You can also view the Jupyter notebook at:

Clean up your instance/s

After you’ve finished with the instance/s that you created for this tutorial, you should clean up by terminating the instance/s, please follow instructions at Clean up your instance.