-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f84fb22
commit 3cc19d2
Showing
146 changed files
with
24,794 additions
and
16,283 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
# Using AWS EC2 Instances | ||
:label:`sec_aws` | ||
|
||
In this section, we will show you how to install all libraries on a raw Linux machine. Remember that in :numref:`sec_sagemaker` we discussed how to use Amazon SageMaker, while building an instance by yourself costs less on AWS. The walkthrough includes a number of steps: | ||
In this section, we will show you how to install all libraries on a raw Linux machine. Recall that in :numref:`sec_sagemaker` we discussed how to use Amazon SageMaker, while building an instance by yourself costs less on AWS. The walkthrough includes three steps: | ||
|
||
1. Request for a GPU Linux instance from AWS EC2. | ||
1. Optionally: install CUDA or use an AMI with CUDA preinstalled. | ||
1. Set up the corresponding MXNet GPU version. | ||
1. Install CUDA (or use an Amazon Machine Image with preinstalled CUDA). | ||
1. Install the deep learning framework and other libraries for running the code of the book. | ||
|
||
This process applies to other instances (and other clouds), too, albeit with some minor modifications. Before going forward, you need to create an AWS account, see :numref:`sec_sagemaker` for more details. | ||
|
||
|
@@ -29,30 +29,38 @@ Select a nearby data center to reduce latency, e.g., "Oregon" (marked by the red | |
you can select a nearby Asia Pacific region, such as Seoul or Tokyo. Please note | ||
that some data centers may not have GPU instances. | ||
|
||
|
||
### Increasing Limits | ||
|
||
Before choosing an instance, check if there are quantity | ||
restrictions by clicking the "Limits" label in the bar on the left as shown in | ||
:numref:`fig_ec2`. :numref:`fig_limits` shows an example of such a | ||
:numref:`fig_ec2`. | ||
:numref:`fig_limits` shows an example of such a | ||
limitation. The account currently cannot open "p2.xlarge" instance per region. If | ||
you need to open one or more instances, click on the "Request limit increase" link to | ||
apply for a higher instance quota. Generally, it takes one business day to | ||
apply for a higher instance quota. | ||
Generally, it takes one business day to | ||
process an application. | ||
|
||
![Instance quantity restrictions.](../img/limits.png) | ||
:width:`700px` | ||
:label:`fig_limits` | ||
|
||
### Launching Instance | ||
|
||
### Launching an Instance | ||
|
||
Next, click the "Launch Instance" button marked by the red box in :numref:`fig_ec2` to launch your instance. | ||
|
||
We begin by selecting a suitable AMI (AWS Machine Image). Enter "Ubuntu" in the search box (marked by the red box in :numref:`fig_ubuntu`). | ||
We begin by selecting a suitable Amazon Machine Image (AMI). Enter "Ubuntu" in the search box (marked by the red box in :numref:`fig_ubuntu`). | ||
|
||
|
||
![Choose an operating system.](../img/ubuntu-new.png) | ||
![Choose an AMI.](../img/ubuntu-new.png) | ||
:width:`700px` | ||
:label:`fig_ubuntu` | ||
|
||
EC2 provides many different instance configurations to choose from. This can sometimes feel overwhelming to a beginner. Here's a table of suitable machines: | ||
EC2 provides many different instance configurations to choose from. This can sometimes feel overwhelming to a beginner. :numref:`tab_ec2` lists different suitable machines. | ||
|
||
:Different EC2 instance types | ||
|
||
| Name | GPU | Notes | | ||
|------|-------------|-------------------------------| | ||
|
@@ -61,21 +69,24 @@ EC2 provides many different instance configurations to choose from. This can som | |
| g3 | Maxwell M60 | good trade-off | | ||
| p3 | Volta V100 | high performance for FP16 | | ||
| g4 | Turing T4 | inference optimized FP16/INT8 | | ||
:label:`tab_ec2` | ||
|
||
All the above servers come in multiple flavors indicating the number of GPUs used. For example, a p2.xlarge has 1 GPU and a p2.16xlarge has 16 GPUs and more memory. For more details, see the [AWS EC2 documentation](https://aws.amazon.com/ec2/instance-types/) or a [summary page](https://www.ec2instances.info). For the purpose of illustration, a p2.xlarge will suffice (marked in red box of :numref:`fig_p2x`). | ||
|
||
**Note:** you must use a GPU enabled instance with suitable drivers and a version of MXNet that is GPU enabled. Otherwise you will not see any benefit from using GPUs. | ||
All these servers come in multiple flavors indicating the number of GPUs used. For example, a p2.xlarge has 1 GPU and a p2.16xlarge has 16 GPUs and more memory. For more details, see the [AWS EC2 documentation](https://aws.amazon.com/ec2/instance-types/) or a [summary page](https://www.ec2instances.info). For the purpose of illustration, a p2.xlarge will suffice (marked in the red box of :numref:`fig_p2x`). | ||
|
||
![Choose an instance.](../img/p2x.png) | ||
:width:`700px` | ||
:label:`fig_p2x` | ||
|
||
So far, we have finished the first two of seven steps for launching an EC2 instance, as shown on the top of :numref:`fig_disk`. In this example, we keep the default configurations for the steps "3. Configure Instance", "5. Add Tags", and "6. Configure Security Group". Tap on "4. Add Storage" and increase the default hard disk size to 64 GB (marked in red box of :numref:`fig_disk`). Note that CUDA by itself already takes up 4 GB. | ||
Note that you should use a GPU-enabled instance with suitable drivers and a GPU-enabled deep learning framework. Otherwise you will not see any benefit from using GPUs. | ||
|
||
![Modify instance hard disk size.](../img/disk.png) | ||
So far, we have finished the first two of seven steps for launching an EC2 instance, as shown on the top of :numref:`fig_disk`. In this example, we keep the default configurations for the steps "3. Configure Instance", "5. Add Tags", and "6. Configure Security Group". Tap on "4. Add Storage" and increase the default hard disk size to 64 GB (marked in the red box of :numref:`fig_disk`). Note that CUDA by itself already takes up 4 GB. | ||
|
||
![Modify the hard disk size.](../img/disk.png) | ||
:width:`700px` | ||
:label:`fig_disk` | ||
|
||
|
||
|
||
Finally, go to "7. Review" and click "Launch" to launch the configured | ||
instance. The system will now prompt you to select the key pair used to access | ||
the instance. If you do not have a key pair, select "Create a new key pair" in | ||
|
@@ -100,14 +111,15 @@ instance ID shown in :numref:`fig_launching` to view the status of this instance | |
|
||
As shown in :numref:`fig_connect`, after the instance state turns green, right-click the instance and select `Connect` to view the instance access method. | ||
|
||
![View instance access and startup method.](../img/connect.png) | ||
![View instance access method.](../img/connect.png) | ||
:width:`700px` | ||
:label:`fig_connect` | ||
|
||
If this is a new key, it must not be publicly viewable for SSH to work. Go to the folder where you store `D2L_key.pem` (e.g., the Downloads folder) and make sure that the key is not publicly viewable. | ||
If this is a new key, it must not be publicly viewable for SSH to work. Go to the folder where you store `D2L_key.pem` and | ||
execute the following command | ||
to make the key not publicly viewable: | ||
|
||
```bash | ||
cd /Downloads ## if D2L_key.pem is stored in Downloads folder | ||
chmod 400 D2L_key.pem | ||
``` | ||
|
||
|
@@ -138,17 +150,16 @@ sudo apt-get update && sudo apt-get install -y build-essential git libgfortran3 | |
``` | ||
|
||
|
||
Here we download CUDA 10.1. Visit NVIDIA's [official repository](https://developer.nvidia.com/cuda-downloads) to find the download link of CUDA 10.1 as shown in :numref:`fig_cuda`. | ||
Here we download CUDA 10.1. Visit NVIDIA's [official repository](https://developer.nvidia.com/cuda-toolkit-archive) to find the download link as shown in :numref:`fig_cuda`. | ||
|
||
![Find the CUDA 10.1 download address.](../img/cuda101.png) | ||
:width:`500px` | ||
:label:`fig_cuda` | ||
|
||
Copy the instructions and paste them into the terminal to install | ||
CUDA 10.1. | ||
Copy the instructions and paste them onto the terminal to install CUDA 10.1. | ||
|
||
```bash | ||
## Paste the copied link from CUDA website | ||
# The link and file name are subject to changes | ||
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin | ||
sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600 | ||
wget http://developer.download.nvidia.com/compute/cuda/10.1/Prod/local_installers/cuda-repo-ubuntu1804-10-1-local-10.1.243-418.87.00_1.0-1_amd64.deb | ||
|
@@ -159,7 +170,7 @@ sudo apt-get -y install cuda | |
``` | ||
|
||
|
||
After installing the program, run the following command to view the GPUs. | ||
After installing the program, run the following command to view the GPUs: | ||
|
||
```bash | ||
nvidia-smi | ||
|
@@ -173,103 +184,64 @@ echo "export LD_LIBRARY_PATH=\${LD_LIBRARY_PATH}:/usr/local/cuda/lib64" >> ~/.ba | |
``` | ||
|
||
|
||
## Installing MXNet and Downloading the D2L Notebooks | ||
|
||
First, to simplify the installation, you need to install [Miniconda](https://conda.io/en/latest/miniconda.html) for Linux. The download link and file name are subject to changes, so please go the Miniconda website and click "Copy Link Address" as shown in :numref:`fig_miniconda`. | ||
|
||
![Download Miniconda.](../img/miniconda.png) | ||
:width:`700px` | ||
:label:`fig_miniconda` | ||
|
||
```bash | ||
# The link and file name are subject to changes | ||
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh | ||
sh Miniconda3-latest-Linux-x86_64.sh -b | ||
``` | ||
## Installing Libraries for Running the Code | ||
|
||
To run the code of this book, | ||
just follow steps in :ref:`chap_installation` | ||
for Linux users on the EC2 instance | ||
and use the following tips | ||
for working on a remote Linux server: | ||
|
||
After the Miniconda installation, run the following command to activate CUDA and conda. | ||
* To download the bash script on the Miniconda installation page, right click the download link and select "Copy Link Address", then execute `wget [copied link address]`. | ||
* After running `~/miniconda3/bin/conda init`, you may execute `source ~/.bashrc` instead of closing and reopening your current shell. | ||
|
||
```bash | ||
~/miniconda3/bin/conda init | ||
source ~/.bashrc | ||
``` | ||
|
||
## Running the Jupyter Notebook remotely | ||
|
||
Next, download the code for this book. | ||
To run the Jupyter Notebook remotely you need to use SSH port forwarding. After all, the server in the cloud does not have a monitor or keyboard. For this, log into your server from your desktop (or laptop) as follows: | ||
|
||
```bash | ||
sudo apt-get install unzip | ||
mkdir d2l-en && cd d2l-en | ||
curl https://d2l.ai/d2l-en.zip -o d2l-en.zip | ||
unzip d2l-en.zip && rm d2l-en.zip | ||
``` | ||
|
||
|
||
Then create the conda `d2l` environment and enter `y` to proceed with the installation. | ||
|
||
```bash | ||
conda create --name d2l -y | ||
``` | ||
|
||
|
||
After creating the `d2l` environment, activate it and install `pip`. | ||
|
||
```bash | ||
conda activate d2l | ||
conda install python=3.7 pip -y | ||
``` | ||
|
||
|
||
Finally, install MXNet and the `d2l` package. The postfix `cu101` means that this is the CUDA 10.1 variant. For different versions, say only CUDA 10.0, you would want to choose `cu100` instead. | ||
|
||
```bash | ||
pip install mxnet-cu101==1.7.0 | ||
pip install git+https://github.com/d2l-ai/d2l-en | ||
|
||
``` | ||
|
||
|
||
You can quickly test whether everything went well as follows: | ||
|
||
``` | ||
$ python | ||
>>> from mxnet import np, npx | ||
>>> np.zeros((1024, 1024), ctx=npx.gpu()) | ||
# This command must be run in the local command line | ||
ssh -i "/path/to/key.pem" [email protected] -L 8889:localhost:8888 | ||
``` | ||
|
||
|
||
## Running Jupyter | ||
|
||
To run Jupyter remotely you need to use SSH port forwarding. After all, the server in the cloud does not have a monitor or keyboard. For this, log into your server from your desktop (or laptop) as follows. | ||
Next, go to the location | ||
of the downloaded code of this book | ||
on the EC2 instance, | ||
then run: | ||
|
||
``` | ||
# This command must be run in the local command line | ||
ssh -i "/path/to/key.pem" [email protected] -L 8889:localhost:8888 | ||
conda activate d2l | ||
jupyter notebook | ||
``` | ||
|
||
|
||
:numref:`fig_jupyter` shows the possible output after you run Jupyter Notebook. The last row is the URL for port 8888. | ||
:numref:`fig_jupyter` shows the possible output after you run the Jupyter Notebook. The last row is the URL for port 8888. | ||
|
||
![Output after running Jupyter Notebook. The last row is the URL for port 8888.](../img/jupyter.png) | ||
![Output after running the Jupyter Notebook. The last row is the URL for port 8888.](../img/jupyter.png) | ||
:width:`700px` | ||
:label:`fig_jupyter` | ||
|
||
Since you used port forwarding to port 8889 you will need to replace the port number and use the secret as given by Jupyter when opening the URL in your local browser. | ||
Since you used port forwarding to port 8889, | ||
copy the last row in the red box of :numref:`fig_jupyter`, | ||
replace "8888" with "8889" in the URL, | ||
and open it in your local browser. | ||
|
||
|
||
## Closing Unused Instances | ||
|
||
As cloud services are billed by the time of use, you should close instances that are not being used. Note that there are alternatives: "stopping" an instance means that you will be able to start it again. This is akin to switching off the power for your regular server. However, stopped instances will still be billed a small amount for the hard disk space retained. "Terminate" deletes all data associated with it. This includes the disk, hence you cannot start it again. Only do this if you know that you will not need it in the future. | ||
As cloud services are billed by the time of use, you should close instances that are not being used. Note that there are alternatives: | ||
|
||
* "Stopping" an instance means that you will be able to start it again. This is akin to switching off the power for your regular server. However, stopped instances will still be billed a small amount for the hard disk space retained. | ||
* "Terminating" an instance will delete all data associated with it. This includes the disk, hence you cannot start it again. Only do this if you know that you will not need it in the future. | ||
|
||
If you want to use the instance as a template for many more instances, | ||
right-click on the example in :numref:`fig_connect` and select "Image" $\rightarrow$ | ||
"Create" to create an image of the instance. Once this is complete, select | ||
"Instance State" $\rightarrow$ "Terminate" to terminate the instance. The next | ||
time you want to use this instance, you can follow the steps for creating and | ||
running an EC2 instance described in this section to create an instance based on | ||
time you want to use this instance, you can follow the steps in this section | ||
to create an instance based on | ||
the saved image. The only difference is that, in "1. Choose AMI" shown in | ||
:numref:`fig_ubuntu`, you must use the "My AMIs" option on the left to select your saved | ||
image. The created instance will retain the information stored on the image hard | ||
|
@@ -279,13 +251,14 @@ environments. | |
|
||
## Summary | ||
|
||
* You can launch and stop instances on demand without having to buy and build your own computer. | ||
* You need to install suitable GPU drivers before you can use them. | ||
* We can launch and stop instances on demand without having to buy and build our own computer. | ||
* We need to install CUDA before using the GPU-enabled deep learning framework. | ||
* We can use port forwarding to run the Jupyter Notebook on a remote server. | ||
|
||
|
||
## Exercises | ||
|
||
1. The cloud offers convenience, but it does not come cheap. Find out how to launch [spot instances](https://aws.amazon.com/ec2/spot/) to see how to reduce prices. | ||
1. The cloud offers convenience, but it does not come cheap. Find out how to launch [spot instances](https://aws.amazon.com/ec2/spot/) to see how to reduce costs. | ||
1. Experiment with different GPU servers. How fast are they? | ||
1. Experiment with multi-GPU servers. How well can you scale things up? | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,30 @@ | ||
# グーグル・コラボレーションを使う | ||
# グーグル・コラボを使う | ||
:label:`sec_colab` | ||
|
||
:numref:`sec_sagemaker` と :numref:`sec_aws` で AWS でこの本を実行する方法を紹介しました。もう 1 つの選択肢として、この本を [Google Colab](https://colab.research.google.com/) で実行する方法があります。Google アカウントをお持ちの場合は、無料の GPU が提供されます。 | ||
:numref:`sec_sagemaker` と :numref:`sec_aws` で AWS でこの本を実行する方法を紹介しました。別のオプションは、Googleアカウントを持っている場合、この本を[Google Colab](https://colab.research.google.com/)で実行することです。 | ||
|
||
Colab でセクションを実行するには、:numref:`fig_colab` のように、そのセクションのタイトルの右側にある `Colab` ボタンをクリックするだけです。 | ||
Colabでセクションのコードを実行するには、:numref:`fig_colab`に示すように、`Colab`ボタンをクリックします。 | ||
|
||
![Open a section on Colab](../img/colab.png) | ||
![Run the code of a section on Colab](../img/colab.png) | ||
:width:`300px` | ||
:label:`fig_colab` | ||
|
||
コードセルを初めて実行すると、:numref:`fig_colab2` に示すような警告メッセージが表示されます。「RUN ANYWAY」をクリックして無視してもかまいません。 | ||
コードセルを初めて実行する場合は、:numref:`fig_colab2`に示すような警告メッセージが表示されます。無視するには、「実行する」をクリックするだけです。 | ||
|
||
![The warning message for running a section on Colab](../img/colab-2.png) | ||
![Ignore the warning message by clicking "RUN ANYWAY".](../img/colab-2.png) | ||
:width:`300px` | ||
:label:`fig_colab2` | ||
|
||
次に、Colab がこのノートブックを実行するインスタンスに接続します。具体的には、`d2l.try_gpu()` 関数を呼び出すときなど、GPU が必要な場合、GPU インスタンスに自動的に接続するように Colab にリクエストします。 | ||
次に、Colab は、このセクションのコードを実行するインスタンスに接続します。具体的には、GPUが必要な場合、ColabはGPUインスタンスへの接続を自動的に要求されます。 | ||
|
||
## [概要 | ||
## まとめ | ||
|
||
* Google Colab を使用して、この本の各セクションを GPU で実行できます。 | ||
* Google Colab を使用して、この本の各セクションのコードを実行できます。 | ||
* 本書のいずれかのセクションでGPUが必要な場合、ColabはGPUインスタンスへの接続を要求されます。 | ||
|
||
## 演習 | ||
|
||
1. Google Colab を使用して、この本のコードを編集して実行してみてください。 | ||
1. Google Colab を使用して、この本の任意のセクションを開きます。 | ||
1. Google Colab を使用して GPU を必要とするセクションを編集して実行します。 | ||
|
||
[Discussions](https://discuss.d2l.ai/t/424) |
Oops, something went wrong.