Skip to content

Commit 807d1b7

Browse files
committed
Update to d2l==1.0.0-alpha1.post0
1 parent f84fb22 commit 807d1b7

File tree

146 files changed

+24822
-16283
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+24822
-16283
lines changed

chapter_appendix-tools-for-deep-learning/aws.md

+57-93
Large diffs are not rendered by default.

chapter_appendix-tools-for-deep-learning/aws_origin.md

+65-92
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Using AWS EC2 Instances
22
:label:`sec_aws`
33

4-
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:
4+
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:
55

66
1. Request for a GPU Linux instance from AWS EC2.
7-
1. Optionally: install CUDA or use an AMI with CUDA preinstalled.
8-
1. Set up the corresponding MXNet GPU version.
7+
1. Install CUDA (or use an Amazon Machine Image with preinstalled CUDA).
8+
1. Install the deep learning framework and other libraries for running the code of the book.
99

1010
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.
1111

@@ -29,30 +29,38 @@ Select a nearby data center to reduce latency, e.g., "Oregon" (marked by the red
2929
you can select a nearby Asia Pacific region, such as Seoul or Tokyo. Please note
3030
that some data centers may not have GPU instances.
3131

32+
3233
### Increasing Limits
34+
3335
Before choosing an instance, check if there are quantity
3436
restrictions by clicking the "Limits" label in the bar on the left as shown in
35-
:numref:`fig_ec2`. :numref:`fig_limits` shows an example of such a
37+
:numref:`fig_ec2`.
38+
:numref:`fig_limits` shows an example of such a
3639
limitation. The account currently cannot open "p2.xlarge" instance per region. If
3740
you need to open one or more instances, click on the "Request limit increase" link to
38-
apply for a higher instance quota. Generally, it takes one business day to
41+
apply for a higher instance quota.
42+
Generally, it takes one business day to
3943
process an application.
4044

4145
![Instance quantity restrictions.](../img/limits.png)
4246
:width:`700px`
4347
:label:`fig_limits`
4448

45-
### Launching Instance
49+
50+
### Launching an Instance
51+
4652
Next, click the "Launch Instance" button marked by the red box in :numref:`fig_ec2` to launch your instance.
4753

48-
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`).
54+
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`).
4955

5056

51-
![Choose an operating system.](../img/ubuntu-new.png)
57+
![Choose an AMI.](../img/ubuntu-new.png)
5258
:width:`700px`
5359
:label:`fig_ubuntu`
5460

55-
EC2 provides many different instance configurations to choose from. This can sometimes feel overwhelming to a beginner. Here's a table of suitable machines:
61+
EC2 provides many different instance configurations to choose from. This can sometimes feel overwhelming to a beginner. :numref:`tab_ec2` lists different suitable machines.
62+
63+
:Different EC2 instance types
5664

5765
| Name | GPU | Notes |
5866
|------|-------------|-------------------------------|
@@ -61,21 +69,24 @@ EC2 provides many different instance configurations to choose from. This can som
6169
| g3 | Maxwell M60 | good trade-off |
6270
| p3 | Volta V100 | high performance for FP16 |
6371
| g4 | Turing T4 | inference optimized FP16/INT8 |
72+
:label:`tab_ec2`
6473

65-
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`).
66-
67-
**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.
74+
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`).
6875

6976
![Choose an instance.](../img/p2x.png)
7077
:width:`700px`
7178
:label:`fig_p2x`
7279

73-
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.
80+
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.
7481

75-
![Modify instance hard disk size.](../img/disk.png)
82+
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.
83+
84+
![Modify the hard disk size.](../img/disk.png)
7685
:width:`700px`
7786
:label:`fig_disk`
7887

88+
89+
7990
Finally, go to "7. Review" and click "Launch" to launch the configured
8091
instance. The system will now prompt you to select the key pair used to access
8192
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
100111

101112
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.
102113

103-
![View instance access and startup method.](../img/connect.png)
114+
![View instance access method.](../img/connect.png)
104115
:width:`700px`
105116
:label:`fig_connect`
106117

107-
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.
118+
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
119+
execute the following command
120+
to make the key not publicly viewable:
108121

109122
```bash
110-
cd /Downloads ## if D2L_key.pem is stored in Downloads folder
111123
chmod 400 D2L_key.pem
112124
```
113125

@@ -138,17 +150,16 @@ sudo apt-get update && sudo apt-get install -y build-essential git libgfortran3
138150
```
139151

140152

141-
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`.
153+
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`.
142154

143155
![Find the CUDA 10.1 download address.](../img/cuda101.png)
144156
:width:`500px`
145157
:label:`fig_cuda`
146158

147-
Copy the instructions and paste them into the terminal to install
148-
CUDA 10.1.
159+
Copy the instructions and paste them onto the terminal to install CUDA 10.1.
149160

150161
```bash
151-
## Paste the copied link from CUDA website
162+
# The link and file name are subject to changes
152163
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin
153164
sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600
154165
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
159170
```
160171

161172

162-
After installing the program, run the following command to view the GPUs.
173+
After installing the program, run the following command to view the GPUs:
163174

164175
```bash
165176
nvidia-smi
@@ -173,103 +184,64 @@ echo "export LD_LIBRARY_PATH=\${LD_LIBRARY_PATH}:/usr/local/cuda/lib64" >> ~/.ba
173184
```
174185

175186

176-
## Installing MXNet and Downloading the D2L Notebooks
177-
178-
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`.
179-
180-
![Download Miniconda.](../img/miniconda.png)
181-
:width:`700px`
182-
:label:`fig_miniconda`
183-
184-
```bash
185-
# The link and file name are subject to changes
186-
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
187-
sh Miniconda3-latest-Linux-x86_64.sh -b
188-
```
187+
## Installing Libraries for Running the Code
189188

189+
To run the code of this book,
190+
just follow steps in :ref:`chap_installation`
191+
for Linux users on the EC2 instance
192+
and use the following tips
193+
for working on a remote Linux server:
190194

191-
After the Miniconda installation, run the following command to activate CUDA and conda.
195+
* 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]`.
196+
* After running `~/miniconda3/bin/conda init`, you may execute `source ~/.bashrc` instead of closing and reopening your current shell.
192197

193-
```bash
194-
~/miniconda3/bin/conda init
195-
source ~/.bashrc
196-
```
197198

199+
## Running the Jupyter Notebook remotely
198200

199-
Next, download the code for this book.
201+
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:
200202

201-
```bash
202-
sudo apt-get install unzip
203-
mkdir d2l-en && cd d2l-en
204-
curl https://d2l.ai/d2l-en.zip -o d2l-en.zip
205-
unzip d2l-en.zip && rm d2l-en.zip
206203
```
207-
208-
209-
Then create the conda `d2l` environment and enter `y` to proceed with the installation.
210-
211-
```bash
212-
conda create --name d2l -y
213-
```
214-
215-
216-
After creating the `d2l` environment, activate it and install `pip`.
217-
218-
```bash
219-
conda activate d2l
220-
conda install python=3.7 pip -y
221-
```
222-
223-
224-
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.
225-
226-
```bash
227-
pip install mxnet-cu101==1.7.0
228-
pip install git+https://github.com/d2l-ai/d2l-en
229-
230-
```
231-
232-
233-
You can quickly test whether everything went well as follows:
234-
235-
```
236-
$ python
237-
>>> from mxnet import np, npx
238-
>>> np.zeros((1024, 1024), ctx=npx.gpu())
204+
# This command must be run in the local command line
205+
ssh -i "/path/to/key.pem" [email protected] -L 8889:localhost:8888
239206
```
240207

241208

242-
## Running Jupyter
243-
244-
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.
209+
Next, go to the location
210+
of the downloaded code of this book
211+
on the EC2 instance,
212+
then run:
245213

246214
```
247-
# This command must be run in the local command line
248-
ssh -i "/path/to/key.pem" [email protected] -L 8889:localhost:8888
249215
conda activate d2l
250216
jupyter notebook
251217
```
252218

253219

254-
:numref:`fig_jupyter` shows the possible output after you run Jupyter Notebook. The last row is the URL for port 8888.
220+
:numref:`fig_jupyter` shows the possible output after you run the Jupyter Notebook. The last row is the URL for port 8888.
255221

256-
![Output after running Jupyter Notebook. The last row is the URL for port 8888.](../img/jupyter.png)
222+
![Output after running the Jupyter Notebook. The last row is the URL for port 8888.](../img/jupyter.png)
257223
:width:`700px`
258224
:label:`fig_jupyter`
259225

260-
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.
226+
Since you used port forwarding to port 8889,
227+
copy the last row in the red box of :numref:`fig_jupyter`,
228+
replace "8888" with "8889" in the URL,
229+
and open it in your local browser.
261230

262231

263232
## Closing Unused Instances
264233

265-
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.
234+
As cloud services are billed by the time of use, you should close instances that are not being used. Note that there are alternatives:
235+
236+
* "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.
237+
* "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.
266238

267239
If you want to use the instance as a template for many more instances,
268240
right-click on the example in :numref:`fig_connect` and select "Image" $\rightarrow$
269241
"Create" to create an image of the instance. Once this is complete, select
270242
"Instance State" $\rightarrow$ "Terminate" to terminate the instance. The next
271-
time you want to use this instance, you can follow the steps for creating and
272-
running an EC2 instance described in this section to create an instance based on
243+
time you want to use this instance, you can follow the steps in this section
244+
to create an instance based on
273245
the saved image. The only difference is that, in "1. Choose AMI" shown in
274246
:numref:`fig_ubuntu`, you must use the "My AMIs" option on the left to select your saved
275247
image. The created instance will retain the information stored on the image hard
@@ -279,13 +251,14 @@ environments.
279251

280252
## Summary
281253

282-
* You can launch and stop instances on demand without having to buy and build your own computer.
283-
* You need to install suitable GPU drivers before you can use them.
254+
* We can launch and stop instances on demand without having to buy and build our own computer.
255+
* We need to install CUDA before using the GPU-enabled deep learning framework.
256+
* We can use port forwarding to run the Jupyter Notebook on a remote server.
284257

285258

286259
## Exercises
287260

288-
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.
261+
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.
289262
1. Experiment with different GPU servers. How fast are they?
290263
1. Experiment with multi-GPU servers. How well can you scale things up?
291264

Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
1-
# グーグル・コラボレーションを使う
1+
# グーグル・コラボを使う
22
:label:`sec_colab`
33

4-
:numref:`sec_sagemaker` と :numref:`sec_aws` で AWS でこの本を実行する方法を紹介しました。もう 1 つの選択肢として、この本を [Google Colab](https://colab.research.google.com/) で実行する方法があります。Google アカウントをお持ちの場合は、無料の GPU が提供されます
4+
:numref:`sec_sagemaker` と :numref:`sec_aws` で AWS でこの本を実行する方法を紹介しました。別のオプションは、Googleアカウントを持っている場合、この本を[Google Colab](https://colab.research.google.com/)で実行することです
55

6-
Colab でセクションを実行するには、:numref:`fig_colab` のように、そのセクションのタイトルの右側にある `Colab` ボタンをクリックするだけです
6+
Colabでセクションのコードを実行するには、:numref:`fig_colab`に示すように、`Colab`ボタンをクリックします
77

8-
![Open a section on Colab](../img/colab.png)
8+
![Run the code of a section on Colab](../img/colab.png)
99
:width:`300px`
1010
:label:`fig_colab`
1111

12-
コードセルを初めて実行すると、:numref:`fig_colab2` に示すような警告メッセージが表示されます。「RUN ANYWAY」をクリックして無視してもかまいません
12+
コードセルを初めて実行する場合は、:numref:`fig_colab2`に示すような警告メッセージが表示されます。無視するには、「実行する」をクリックするだけです
1313

14-
![The warning message for running a section on Colab](../img/colab-2.png)
14+
![Ignore the warning message by clicking "RUN ANYWAY".](../img/colab-2.png)
1515
:width:`300px`
1616
:label:`fig_colab2`
1717

18-
次に、Colab がこのノートブックを実行するインスタンスに接続します。具体的には、`d2l.try_gpu()` 関数を呼び出すときなど、GPU が必要な場合、GPU インスタンスに自動的に接続するように Colab にリクエストします
18+
次に、Colab は、このセクションのコードを実行するインスタンスに接続します。具体的には、GPUが必要な場合、ColabはGPUインスタンスへの接続を自動的に要求されます
1919

20-
## [概要
20+
## まとめ
2121

22-
* Google Colab を使用して、この本の各セクションを GPU で実行できます。
22+
* Google Colab を使用して、この本の各セクションのコードを実行できます。
23+
* 本書のいずれかのセクションでGPUが必要な場合、ColabはGPUインスタンスへの接続を要求されます。
2324

2425
## 演習
2526

26-
1. Google Colab を使用して、この本のコードを編集して実行してみてください。
27+
1. Google Colab を使用して、この本の任意のセクションを開きます。
28+
1. Google Colab を使用して GPU を必要とするセクションを編集して実行します。
2729

2830
[Discussions](https://discuss.d2l.ai/t/424)

0 commit comments

Comments
 (0)