Install Neuron TensorFlow

Note

  • Instructions in this page only apply to setting up Neuron components on Linux host running Ubuntu or Amazon Linux AMI.

  • For an example of how to install Neuron components in a container, see Docker environment setup and our Containers documentation for more details.

Develop on AWS ML accelerator instance

The simplest environment setup for model development installs all Neuron SDK components directly on an AWS ML accelerator instance: the Neuron framework extensions, compiler, runtime, and tools. This will allow you to compile, execute, and performance tune your model, all in the same instance. This is the recommended workflow when first starting to work with Neuron device or when optimizing a model.

Important

For successful installation or update to Neuron 1.16.0 and newer from previous releases:
  • Stop Neuron Runtime 1.x daemon (neuron-rtd) by running: sudo systemctl stop neuron-rtd

  • Uninstall neuron-rtd by running: sudo apt remove aws-neuron-runtime or sudo yum remove aws-neuron-runtime

  • Install or upgrade to latest Neuron driver (aws-neuron-dkms) by following the “Setup Guide” instructions.

  • Visit Introducing Neuron Runtime 2.x (libnrt.so) for more information.

Note

For a successful installation or update, execute each line of the instructions below separately or copy the contents of the code block into a script file and source its contents.

# Configure Linux for Neuron repository updates
. /etc/os-release
sudo tee /etc/apt/sources.list.d/neuron.list > /dev/null <<EOF
deb https://apt.repos.neuron.amazonaws.com ${VERSION_CODENAME} main
EOF
wget -qO - https://apt.repos.neuron.amazonaws.com/GPG-PUB-KEY-AMAZON-AWS-NEURON.PUB | sudo apt-key add -

# Update OS packages
sudo apt-get update -y

###############################################################################################################
# Before installing or updating aws-neuron-dkms:
# - Stop any existing Neuron runtime 1.0 daemon (neuron-rtd) by calling: 'sudo systemctl stop neuron-rtd'
###############################################################################################################

################################################################################################################
# To install or update to Neuron versions 1.16.0 and newer from previous releases:
# - DO NOT skip 'aws-neuron-dkms' install or upgrade step, you MUST install or upgrade to latest Neuron driver
################################################################################################################

# Install OS headers
sudo apt-get install linux-headers-$(uname -r) -y

# Install Neuron Driver
sudo apt-get install aws-neuron-dkms -y

####################################################################################
# Warning: If Linux kernel is updated as a result of OS package update
#          Neuron driver (aws-neuron-dkms) should be re-installed after reboot
####################################################################################

# Install Neuron Tools
sudo apt-get install aws-neuron-tools -y

# Install Neuron TensorBoard
pip install tensorboard-plugin-neuron

export PATH=/opt/aws/neuron/bin:$PATH

# Install Python venv and activate Python virtual environment to install    
# Neuron pip packages.
sudo apt-get install -y python3-venv g++
python3 -m venv tensorflow_venv
source tensorflow_venv/bin/activate
pip install -U pip


# Instal Jupyter notebook kernel 
pip install ipykernel 
python -m ipykernel install --user --name tensorflow_venv --display-name "Python (Neuron TensorFlow)"
pip install jupyter notebook
pip install environment_kernels


# Set Pip repository  to point to the Neuron repository
pip config set global.extra-index-url https://pip.repos.neuron.amazonaws.com

#Install Neuron TensorFlow
pip install tensorflow-neuron[cc]

# Optional: Install Neuron TensorFlow model server
sudo apt-get install tensorflow-model-server-neuron -y

Compile on compute instance

If model compilation occurs outside the model deployment environment, you can install only the Neuron framework extensions and the compiler on any compute instance. This setup is helpful when compiling large complex models that require large amount of memory or during a CICD process where models are compiled in a separate step, prior to deployment.

Note

For a successful installation or update, execute each line of the instructions below separately or copy the contents of the code block into a script file and source its contents.

# Install Python venv and activate Python virtual environment to install    
# Neuron pip packages.
sudo apt-get install -y python3-venv g++
python3 -m venv tensorflow_venv
source tensorflow_venv/bin/activate
pip install -U pip


# Set Pip repository  to point to the Neuron repository
pip config set global.extra-index-url https://pip.repos.neuron.amazonaws.com

#Install Neuron TensorFlow
pip install tensorflow-neuron[cc]

Deploy on AWS ML accelerator instance

During deployment it can be beneficial to reduce the number of components installed in the system. For use-cases where only inference is necessary (compilation is already complete), only the framework and runtime should be installed.

Important

For successful installation or update to Neuron 1.16.0 and newer from previous releases:
  • Stop Neuron Runtime 1.x daemon (neuron-rtd) by running: sudo systemctl stop neuron-rtd

  • Uninstall neuron-rtd by running: sudo apt remove aws-neuron-runtime or sudo yum remove aws-neuron-runtime

  • Install or upgrade to latest Neuron driver (aws-neuron-dkms) by following the “Setup Guide” instructions.

  • Visit Introducing Neuron Runtime 2.x (libnrt.so) for more information.

Note

For a successful installation or update, execute each line of the instructions below separately or copy the contents of the code block into a script file and source its contents.

# Configure Linux for Neuron repository updates
. /etc/os-release
sudo tee /etc/apt/sources.list.d/neuron.list > /dev/null <<EOF
deb https://apt.repos.neuron.amazonaws.com ${VERSION_CODENAME} main
EOF
wget -qO - https://apt.repos.neuron.amazonaws.com/GPG-PUB-KEY-AMAZON-AWS-NEURON.PUB | sudo apt-key add -

# Update OS packages
sudo apt-get update -y

###############################################################################################################
# Before installing or updating aws-neuron-dkms:
# - Stop any existing Neuron runtime 1.0 daemon (neuron-rtd) by calling: 'sudo systemctl stop neuron-rtd'
###############################################################################################################

################################################################################################################
# To install or update to Neuron versions 1.16.0 and newer from previous releases:
# - DO NOT skip 'aws-neuron-dkms' install or upgrade step, you MUST install or upgrade to latest Neuron driver
################################################################################################################

# Install OS headers
sudo apt-get install linux-headers-$(uname -r) -y

# Install Neuron Driver
sudo apt-get install aws-neuron-dkms -y

####################################################################################
# Warning: If Linux kernel is updated as a result of OS package update
#          Neuron driver (aws-neuron-dkms) should be re-installed after reboot
####################################################################################

export PATH=/opt/aws/neuron/bin:$PATH

# Install Python venv and activate Python virtual environment to install    
# Neuron pip packages.
sudo apt-get install -y python3-venv g++
python3 -m venv tensorflow_venv
source tensorflow_venv/bin/activate
pip install -U pip


# Set Pip repository  to point to the Neuron repository
pip config set global.extra-index-url https://pip.repos.neuron.amazonaws.com

#Install Neuron TensorFlow
pip install tensorflow-neuron

# Optional: Install Neuron TensorFlow model server
sudo apt-get install tensorflow-model-server-neuron -y