• 沒有找到結果。

Test Your DLAMI

在文檔中 Deep Learning AMI (頁 23-153)

• Clean Up (p. 22)

• Set up a Jupyter Notebook Server (p. 22)

Step 1: Launch a DLAMI

Note

For this walkthrough, we might make references specific to the Deep Learning AMI (Ubuntu 16.04). Even if you select a different DLAMI, you should be able to follow this guide.

Launch the instance

1. You have a couple routes for launching DLAMI. Choose one:

• EC2 Console (p. 20)

• Marketplace Search (p. 21)

TipCLI Option: If you choose to spin up a DLAMI using the AWS CLI, you will need the AMI's ID, the region and instance type, and your security token information. Be sure you have your AMI and instance IDs ready. If you haven't set up the AWS CLI yet, do that first using the guide for Installing the AWS Command Line Interface.

2. After you have completed the steps of one of those options, wait for the instance to be ready. This usually takes only a few minutes. You can verify the status of the instance in the EC2 Console.

DLAMI ID

DLAMI ID

Find the ID for the DLAMI of your choice with the AWS Command Line Interface (AWS CLI). If you do not already have the AWS CLI installed, see Getting started with the AWS CLI.

1. Make sure that your AWS credentials are configured.

aws configure

2. Choose a DLAMI and check the details in the release notes. Use the following command to get the ID for the DLAMI of your choice:

aws ec2 describe-images --region us-east-1 --owners amazon \

--filters 'Name=name,Values=Deep Learning AMI (Ubuntu 18.04) Version ??.?' 'Name=state,Values=available' \

--query 'reverse(sort_by(Images, &CreationDate))[:1].ImageId' --output text

NoteYou can specify a release version for a given framework or get the latest release by replacing the version number with a question mark.

3. The output should look similar to the following:

ami-094c089c38ed069f2

Copy this DLAMI ID and press q to exit the prompt.

Next Step

EC2 Console (p. 20)

EC2 Console

Note

To launch an instance with Elastic Fabric Adapter (EFA), refer to these steps.

1. Open the EC2 Console.

2. Note your current region in the top-most navigation. If this isn't your desired AWS Region, change this option before proceeding. For more information, see EC2 Regions.

3. Choose Launch Instance.

4. Search for the desired instance by name:

a. Select the DLAMI that is right for you. Find the DLAMI name as listed in the release notes or find the DLAMI ID using the AWS CLI.

b. Choose Community AMIs.

i. To view a selection of the latest DLAMIs, choose Quick Start.

ii. Choose AWS Marketplace to browse additional DLAMIs. Only a subset of available DLAMIs will be listed here.

c. Enter the DLAMI name or search the DLAMI ID. Browse the options and then click Select on your choice.

5. Review the details, and then choose Continue.

6. Choose an instance type. For recommendations on DLAMI instance types, see Instance Selection.

Marketplace Search

NoteIf you want to use Elastic Inference (EI), click Configure Instance Details, select Add an Amazon EI accelerator, then select the size of the Amazon EI accelerator.

7. Choose Review and Launch.

8. Review the details and pricing. Choose Launch.

TipCheck out Get Started with Deep Learning Using the AWS Deep Learning AMI for a walk-through with screenshots!

Next Step

Step 2: Connect to the DLAMI (p. 21)

Marketplace Search

1. Browse the AWS Marketplace and search for AWS Deep Learning AMI.

2. Browse the options, and then click Select on your choice.

3. Review the details, and then choose Continue.

4. Review the details and make note of the Region. If this isn't your desired AWS Region, change this option before proceeding. For more information, see EC2 Regions.

5. Choose an instance type.

6. Choose a key pair, use your default one, or create a new one.

7. Review the details and pricing.

8. Choose Launch with 1-Click.

Next Step

Step 2: Connect to the DLAMI (p. 21)

Step 2: Connect to the DLAMI

Connect to the DLAMI that you launched from a client (Windows, MacOS, or Linux). For more information, see Connect to Your Linux Instance in the Amazon EC2 User Guide for Linux Instances.

Keep a copy of the SSH login command handy if you want to do the Jupyter setup after logging in. You will use a variation of it to connect to the Jupyter webpage.

Next Step

Step 3: Secure Your DLAMI Instance (p. 21)

Step 3: Secure Your DLAMI Instance

Always keep your operating system and other installed software up to date by applying patches and updates as soon as they become available.

If you are using Amazon Linux or Ubuntu, when you login to your DLAMI, you are notified if updates are available and see instructions for updating. For further information on Amazon Linux maintenance, see Updating Instance Software. For Ubuntu instances, refer to the official Ubuntu documentation.

Step 4: Test Your DLAMI

On Windows, check Windows Update regularly for software and security updates. If you prefer, have updates applied automatically.

Important

For information about the Meltdown and Spectre vulnerabilities and how to patch your operating system to address them, see Security Bulletin AWS-2018-013.

Step 4: Test Your DLAMI

Depending on your DLAMI version, you have different testing options:

• Deep Learning AMI with Conda (p. 6) – go to Using the Deep Learning AMI with Conda (p. 29).

• Deep Learning Base AMI (p. 6) – refer to your desired framework's installation documentation.

You can also create a Jupyter notebook, try out tutorials, or start coding in Python. For more information, see Set up a Jupyter Notebook Server (p. 22).

Clean Up

When you no longer need the DLAMI, you can stop it or terminate it to avoid incurring continuing charges. Stopping an instance will keep it around so you can resume it later. Your configurations, files, and other non-volatile information is being stored in a volume on Amazon S3. You will be charged the small S3 fee to retain the volume while the instance is stopped, but you will no longer be charged for the compute resources while it is in the stopped state. When your start the instance again, it will mount that volume and your data will be there. If you terminate an instance, it is gone, and you cannot start it again. Your data actually still resides on S3, so to prevent any further charges you need to delete the volume as well. For more instructions, see Terminate Your Instance in the Amazon EC2 User Guide for Linux Instances.

Set up a Jupyter Notebook Server

A Jupyter notebook server enables you to create and run Jupyter notebooks from your DLAMI instance.

With Jupyter notebooks, you can conduct machine learning (ML) experiments for training and inference while using the AWS infrastructure and accessing packages built into the DLAMI. For more information about Jupyter notebooks, see the Jupyter Notebook documentation.

To set up a Jupyter notebook server, you must:

• Configure the Jupyter notebook server on your Amazon EC2 DLAMI instance.

• Configure your client so that you can connect to the Jupyter notebook server. We provide configuration instructions for Windows, macOS, and Linux clients.

• Test the setup by logging in to the Jupyter notebook server.

To complete the steps to set up a Jupyter, follow the instructions in the following topics. Once you've set up a Jupyter notebook server, see Running Jupyter Notebook Tutorials (p. 33) for information on running the example notebooks that ship in the DLAMI.

Topics

• Secure Your Jupyter Server (p. 23)

• Start the Jupyter notebook server (p. 23)

• Configure the Client to Connect to the Jupyter Server (p. 24)

Secure Jupyter

• Test by Logging in to the Jupyter notebook server (p. 25)

Secure Your Jupyter Server

Here we set up Jupyter with SSL and a custom password.

Connect to the Amazon EC2 instance, and then complete the following procedure.

Configure the Jupyter server

1. Jupyter provides a password utility. Run the following command and enter your preferred password at the prompt.

$ jupyter notebook password

The output will look something like this:

Enter password:

Verify password:

[NotebookPasswordApp] Wrote hashed password to /home/ubuntu/.jupyter/

jupyter_notebook_config.json

2. Create a self-signed SSL certificate. Follow the prompts to fill out your locality as you see fit. You must enter . if you wish to leave a prompt blank. Your answers will not impact the functionality of the certificate.

$ cd ~

$ mkdir ssl

$ cd ssl

$ openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout mykey.key -out mycert.pem

Note

You might be interested in creating a regular SSL certificate that is third party signed and does not cause the browser to give you a security warning. This process is much more involved. Visit Jupyter's documention for more information.

Next Step

Start the Jupyter notebook server (p. 23)

Start the Jupyter notebook server

Now you can fire up the Jupyter server by logging in to the instance and running the following command that uses the SSL certificate you created in the previous step.

$ jupyter notebook --certfile=~/ssl/mycert.pem --keyfile ~/ssl/mykey.key

With the server started, you can now connect to it via an SSH tunnel from your client computer. When the server runs, you will see some output from Jupyter confirming that the server is running. At this point, ignore the callout that you can access the server via a localhost URL, because that won't work until you create the tunnel.

NoteJupyter will handle switching environments for you when you switch frameworks using the Jupyter web interface. More info on this can be found in Switching Environments with Jupyter (p. 34).

Configure Client

Next Step

Configure the Client to Connect to the Jupyter Server (p. 24)

Configure the Client to Connect to the Jupyter Server

After configuring your client to connect to the Jupyter notebook server, you can create and access notebooks on the server in your workspace and run your deep learning code on the server.

For configuration information, choose one of the following links.

Topics

• Configure a Windows Client (p. 24)

• Configure a Linux or macOS Client (p. 24)

Configure a Windows Client

Prepare

Be sure you have the following information, which you need to set up the SSH tunnel:

• The public DNS name of your Amazon EC2 instance. You can find the public DNS name in the EC2 console.

• The key pair for the private key file. For more information about accessing your key pair, see Amazon EC2 Key Pairs in the Amazon EC2 User Guide for Linux Instances.

Using Jupyter Notebooks from a Windows Client

Refer to these guides on connecting to your Amazon EC2 instance from a Windows client.

1.Troubleshooting Connecting to Your Instance

2.Connecting to Your Linux Instance from Windows Using PuTTY

To create a tunnel to a running Jupyter server, a recommended approach is to install Git Bash on your Windows client, then follow the Linux/macOS client instructions. However, you may use whatever approach you want for opening an SSH tunnel with port mapping. Refer to Jupyter's documentation for further information.

Next Step

Configure a Linux or macOS Client (p. 24)

Configure a Linux or macOS Client

1. Open a terminal.

2. Run the following command to forward all requests on local port 8888 to port 8888 on your remote Amazon EC2 instance. Update the command by replacing the location of your key to access the Amazon EC2 instance and the public DNS name of your Amazon EC2 instance. Note, for an Amazon Linux AMI, the user name is ec2-user instead of ubuntu.

$ ssh -i ~/mykeypair.pem -N -f -L 8888:localhost:8888

ubuntu@ec2-###-##-##-###.compute-1.amazonaws.com

Log in to the Jupyter notebook server

This command opens a tunnel between your client and the remote Amazon EC2 instance that is running the Jupyter notebook server.

Next Step

Test by Logging in to the Jupyter notebook server (p. 25)

Test by Logging in to the Jupyter notebook server

Now you are ready to log in to the Jupyter notebook server.

Your next step is to test the connection to the server through your browser.

1. In the address bar of your browser, type the following URL, or click on this link: https://

localhost:8888

2. With a self signed SSL certificate, your browser will warn you and prompt you to avoid continuing to visit the website.

Log in to the Jupyter notebook server

Since you set this up yourself, it is safe to continue. Depending your browser you will get an

"advanced", "show details", or similar button.

Log in to the Jupyter notebook server

Log in to the Jupyter notebook server

Click on this, then click on the "proceed to localhost" link. If the connection is successful, you see the Jupyter notebook server webpage. At this point, you will be asked for the password you previously setup.

Now you have access to the Jupyter notebook server that is running on the DLAMI. You can create new notebooks or run the provided Tutorials (p. 34).

Conda DLAMI

Using a DLAMI

Topics

• Using the Deep Learning AMI with Conda (p. 29)

• Using the Deep Learning Base AMI (p. 32)

• Running Jupyter Notebook Tutorials (p. 33)

• Tutorials (p. 34)

The following sections describe how the Deep Learning AMI with Conda can be used to switch environments, run sample code from each of the frameworks, and run Jupyter so you can try out different notebook tutorials.

Using the Deep Learning AMI with Conda

Topics

• Introduction to the Deep Learning AMI with Conda (p. 29)

• Log in to Your DLAMI (p. 29)

• Start the TensorFlow Environment (p. 30)

• Switch to the PyTorch Python 3 Environment (p. 31)

• Switch to the MXNet Python 3 Environment (p. 31)

• Removing Environments (p. 32)

Introduction to the Deep Learning AMI with Conda

Conda is an open source package management system and environment management system that runs on Windows, macOS, and Linux. Conda quickly installs, runs, and updates packages and their dependencies. Conda easily creates, saves, loads and switches between environments on your local computer.

The Deep Learning AMI with Conda has been configured for you to easily switch between deep learning environments. The following instructions guide you on some basic commands with conda. They also help you verify that the basic import of the framework is functioning, and that you can run a couple simple operations with the framework. You can then move on to more thorough tutorials provided with the DLAMI or the frameworks' examples found on each frameworks' project site.

Log in to Your DLAMI

After you log in to your server, you will see a server "message of the day" (MOTD) describing various Conda commands that you can use to switch between the different deep learning frameworks. Below is an example MOTD. Your specific MOTD may vary as new versions of the DLAMI are released.

Note

We no longer include the CNTK, Caffe, Caffe2 and Theano Conda environments in the AWS Deep Learning AMI starting with the v28 release. Previous releases of the AWS Deep Learning AMI that contain these environments will continue to be available. However, we will only provide updates to these environments if there are security fixes published by the open source community for these frameworks.

=============================================================================

__| __|_ )

Start the TensorFlow Environment

_| ( / Deep Learning AMI (Ubuntu 18.04) Version 40.0 ___|\___|___|

=============================================================================

Welcome to Ubuntu 18.04.5 LTS (GNU/Linux 5.4.0-1037-aws x86_64v)

Please use one of the following commands to start the required environment with the framework of your choice:

for AWS MX 1.7 (+Keras2) with Python3 (CUDA 10.1 and Intel MKL-DNN) _______________________________ source activate mxnet_p36

for AWS MX 1.8 (+Keras2) with Python3 (CUDA + and Intel MKL-DNN) ___________________________ source activate mxnet_latest_p37

for AWS MX(+AWS Neuron) with Python3 ___________________________________________________

source activate aws_neuron_mxnet_p36

for AWS MX(+Amazon Elastic Inference) with Python3 _______________________________________

source activate amazonei_mxnet_p36

for TensorFlow(+Keras2) with Python3 (CUDA + and Intel MKL-DNN) _____________________________ source activate tensorflow_p37

for Tensorflow(+AWS Neuron) with Python3 _________________________________________ source activate aws_neuron_tensorflow_p36

for TensorFlow 2(+Keras2) with Python3 (CUDA 10.1 and Intel MKL-DNN) _______________________ source activate tensorflow2_p36

for TensorFlow 2.3 with Python3.7 (CUDA + and Intel MKL-DNN) ________________________

source activate tensorflow2_latest_p37

for PyTorch 1.4 with Python3 (CUDA 10.1 and Intel MKL)

_________________________________________ source activate pytorch_p36

for PyTorch 1.7.1 with Python3.7 (CUDA 11.0 and Intel MKL) ________________________________

source activate pytorch_latest_p37

for PyTorch (+AWS Neuron) with Python3 ______________________________________________

source activate aws_neuron_pytorch_p36 for base Python3 (CUDA 10.0)

_______________________________________________________________________ source activate python3

Each Conda command has the following pattern:

source activate framework_python-version

For example, you may see for MXNet(+Keras1) with Python3 (CUDA 10.1)

_____________________ source activate mxnet_p36, which signifies that the environment has MXNet, Keras 1, Python 3, and CUDA 10.1. And to activate this environment, the command you would use is:

$ source activate mxnet_p36

Start the TensorFlow Environment

NoteWhen you launch your first Conda environment, please be patient while it loads. The Deep Learning AMI with Conda automatically installs the most optimized version of the framework for your EC2 instance upon the framework's first activation. You should not expect subsequent delays.

1. Activate the TensorFlow virtual environment for Python 3.

$ source activate tensorflow_p37 2. Start the iPython terminal.

(tensorflow_37)$ ipython

Switch to the PyTorch Python 3 Environment

3. Run a quick TensorFlow program.

import tensorflow as tf

hello = tf.constant('Hello, TensorFlow!') sess = tf.Session()

print(sess.run(hello))

You should see "Hello, Tensorflow!"

Next Up

Running Jupyter Notebook Tutorials (p. 33)

Switch to the PyTorch Python 3 Environment

If you're still in the iPython console, use quit(), then get ready to switch environments.

• Activate the PyTorch virtual environment for Python 3.

$ source activate pytorch_p36

Test Some PyTorch Code

To test your installation, use Python to write PyTorch code that creates and prints an array.

1. Start the iPython terminal.

(pytorch_p36)$ ipython 2. Import PyTorch.

import torch

You might see a warning message about a third-party package. You can ignore it.

3. Create a 5x3 matrix with the elements initialized randomly. Print the array.

x = torch.rand(5, 3) print(x)

Verify the result.

tensor([[0.3105, 0.5983, 0.5410], [0.0234, 0.0934, 0.0371], [0.9740, 0.1439, 0.3107], [0.6461, 0.9035, 0.5715], [0.4401, 0.7990, 0.8913]])

Switch to the MXNet Python 3 Environment

If you're still in the iPython console, use quit(), then get ready to switch environments.

Removing Environments

• Activate the MXNet virtual environment for Python 3.

$ source activate mxnet_p36

Test Some MXNet Code

To test your installation, use Python to write MXNet code that creates and prints an array using the NDArray API. For more information, see NDArray API.

1. Start the iPython terminal.

(mxnet_p36)$ ipython 2. Import MXNet.

import mxnet as mx

You might see a warning message about a third-party package. You can ignore it.

3. Create a 5x5 matrix, an instance of the NDArray, with elements initialized to 0. Print the array.

mx.ndarray.zeros((5,5)).asnumpy()

Verify the result.

array([[ 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0.],

[ 0., 0., 0., 0., 0.]], dtype=float32)

You can find more examples of MXNet in the MXNet tutorials section.

Removing Environments

If you run out of space on the DLAMI, you can choose to uninstall Conda packages that you are not using:

conda env list

conda env remove –-name <env_name>

Using the Deep Learning Base AMI

Using the Deep Learning Base AMI

The Base AMI comes with a foundational platform of GPU drivers and acceleration libraries to deploy your own customized deep learning environment. By default the AMI is configured with the NVIDIA CUDA 10.0 environment. You can also switch between different versions of CUDA. Refer to the following instructions for how to do this.

Configuring CUDA Versions

Configuring CUDA Versions

You can select and verify a particular CUDA version with the following bash commands.

TipYou can verify the CUDA version by running NVIDIA's nvcc program.

$ nvcc --version

• CUDA 11.0:

$ sudo rm /usr/local/cuda

$ sudo ln -s /usr/local/cuda-11.0 /usr/local/cuda

• CUDA 10.2:

$ sudo rm /usr/local/cuda

$ sudo ln -s /usr/local/cuda-10.2 /usr/local/cuda

• CUDA 10.1:

$ sudo rm /usr/local/cuda

$ sudo ln -s /usr/local/cuda-10.1 /usr/local/cuda

• CUDA 10.0:

$ sudo rm /usr/local/cuda

$ sudo ln -s /usr/local/cuda-10.0 /usr/local/cuda

Running Jupyter Notebook Tutorials

Tutorials and examples ship with each of the deep learning projects' source and in most cases they will run on any DLAMI. If you chose the Deep Learning AMI with Conda (p. 6), you get the added benefit of a few hand-picked tutorials already set up and ready to try out.

Important

To run the Jupyter notebook tutorials installed on the DLAMI, you will need to Set up a Jupyter Notebook Server (p. 22).

Once the Jupyter server is running, you can run the tutorials through your web browser. If you are running the Deep Learning AMI with Conda or if you have set up Python environments, you can switch Python kernels from the Jupyter notebook interface. Select the appropriate kernel before trying to run

Once the Jupyter server is running, you can run the tutorials through your web browser. If you are running the Deep Learning AMI with Conda or if you have set up Python environments, you can switch Python kernels from the Jupyter notebook interface. Select the appropriate kernel before trying to run

在文檔中 Deep Learning AMI (頁 23-153)

相關文件