You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/tensorflow-neuron/tutorial-compile-infer.md
+51-68
Original file line number
Diff line number
Diff line change
@@ -1,69 +1,73 @@
1
-
# Tutorial: Using Neuron to run Resnet50 inference
1
+
# Tutorial: Getting Started with TensorFlow-Neuron (ResNet-50 Tutorial)
2
2
3
3
## Steps Overview:
4
4
5
-
1. Launch an EC2 instance for compilation and/or Infernence
6
-
2. Install Neuron for Compiler and Runtime execution
7
-
3. Compile on compilation server
8
-
4.Execute inference on Inf1
5
+
1. Launch an EC2 compilation-instance (recommended instance: c5.4xl), and an deployment instance
6
+
2. Install Neuron compiler on the compilation-instace
7
+
3. Compile the compute-graph on the compilation-instance, and copy the compilation artifacts to the deployment-instance
8
+
4.Deploy: run inferences on the deployment-instance
9
9
10
10
## Step 1: Launch EC2 Instance(s)
11
11
12
-
A typical workflow with the Neuron SDK will be to compile trained ML models on a compilation server and then distribute the artifacts to a fleet of Inf1 instances for execution. Neuron enables TensorFlow to be used for all of these steps.
12
+
A typical workflow with the Neuron SDK will be to compile a trained ML model on a compilation-instance and then to distribute the artifacts to Inf1 deployment-instances, for execution.
13
13
14
-
1.1. Select an AMI of your choice, which may be Ubuntu 16.x, Ubuntu 18.x, Amazon Linux 2 based. To use a pre-built Deep Learning AMI, which includes all of the needed packages, see [Launching and Configuring a DLAMI](https://docs.aws.amazon.com/dlami/latest/devguide/launch-config.html)
14
+
1.1. Select an AMI of your choice, which may be Ubuntu 16.x, Ubuntu 18.x, or Amazon Linux 2 based. A pre-built Deep Learning AMI is also available, which includes all of the needed packages (see https://docs.aws.amazon.com/dlami/latest/devguide/launch-config.html).
15
15
16
-
1.2. Select and launch an EC2 instance of your choice to compile. Launch an instance by following [EC2 instructions](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EC2_GetStarted.html#ec2-launch-instance).
17
-
* It is recommended to use c5.4xlarge or larger. For this example we will use a c5.4xlarge.
18
-
* If you would like to compile and infer on the same machine, please select inf1.6xlarge.
16
+
**Note:** If you choose to use Deep Learning AMI (recommended for getting started), you may skip to Step 3 below. Make sure to activate the environment of choice, e.g.
2. Users may choose the compile and deploy on the same instance, in which case we recommend using Inf1.6xlarge or larger
25
+
26
+
1.3. Select and start a deployment-instance of your choice (if not compiling and inferencing on the same instance).
27
+
1. For this example, we will use Inf1.xl
19
28
20
-
1.3. Select and launch an Inf1 instance of your choice if not compiling and inferencing on the same instance. Launch an instance by following [EC2 instructions](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EC2_GetStarted.html#ec2-launch-instance).
29
+
## Step 2: Installations
21
30
22
-
##Step 2: Install Neuron Compiler and TensorFlow-Neuron On Compilation Instance
31
+
### Compilation-Instance: Install Neuron Compiler and TensorFlow-Neuron
23
32
24
-
If using DLAMI, activate aws_neuron_tensorflow_p36 environment and skip this step.
33
+
Note: this step is only required if you are not using Deep Learning AMI.
25
34
26
-
On the instance you are going to use for compilation, install both Neuron Compiler and TensorFlow-Neuron.
35
+
On the compilation-instance, install Neuron-compiler and Tensorflow-Neuron.
36
+
On the deployment-instance, install Neuron-runtime and Tensorflow-Neuron.
27
37
28
-
2.1. Install virtualenv if needed:
38
+
#### Using Virtualenv:
39
+
40
+
1. Install virtualenv if needed:
29
41
```bash
30
-
# Ubuntu
31
42
sudo apt-get update
32
43
sudo apt-get -y install virtualenv
33
44
```
34
-
```bash
35
-
# Amazon Linux 2
36
-
sudo yum update
37
-
sudo yum install -y python3
38
-
pip3 install --user virtualenv
39
-
```
40
-
2.2. Setup a new Python 3.6 environment:
45
+
2. Setup a new Python 3.6 environment:
41
46
```bash
42
47
virtualenv --python=python3.6 test_env_p36
43
48
source test_env_p36/bin/activate
44
49
```
45
-
2.3. Modify Pip repository configurations to point to the Neuron repository.
50
+
3. Modify Pip repository configurations to point to the Neuron repository.
3.2. Run the compilation script, which will take a few minutes on c5.4xlarge. At the end of script execution, the compiled SavedModel is zipped as `resnet50_neuron.zip` in local directory:
102
+
103
+
3.2. Run the compilation script (can take a few minutes). At the end of script execution, the compiled SavedModel is zipped as `resnet50_neuron.zip` in local directory:
105
104
```bash
106
105
python compile_resnet50.py
107
106
```
108
107
```
109
-
...
110
-
INFO:tensorflow:fusing subgraph neuron_op_d6f098c01c780733 with neuron-cc; log file is at /home/ubuntu/ws_resnet50/workdir/neuron_op_d6f098c01c780733/graph_def.neuron-cc.log
111
-
INFO:tensorflow:Number of operations in TensorFlow session: 3978
112
-
INFO:tensorflow:Number of operations after tf.neuron optimizations: 555
108
+
...
109
+
This function will only be available through the v1 compatibility library as tf.compat.v1.saved_model.loader.load or tf.compat.v1.saved_model.load. There will be a new function for importing SavedModels in Tensorflow 2.0.
110
+
INFO:tensorflow:fusing subgraph neuron_op_d6f098c01c780733 with neuron-cc
111
+
INFO:tensorflow:Number of operations in TensorFlow session: 4638
112
+
INFO:tensorflow:Number of operations after tf.neuron optimizations: 556
113
113
INFO:tensorflow:Number of operations placed on Neuron runtime: 554
114
+
INFO:tensorflow:Successfully converted ./ws_resnet50/resnet50 to ./ws_resnet50/resnet50_neuron
114
115
...
115
116
```
117
+
116
118
3.3. If not compiling and inferring on the same instance, copy the artifact to the inference server:
0 commit comments