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: chapter_appendix-tools-for-deep-learning/aws_origin.md
+65-92
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,11 @@
1
1
# Using AWS EC2 Instances
2
2
:label:`sec_aws`
3
3
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:
5
5
6
6
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.
9
9
10
10
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.
11
11
@@ -29,30 +29,38 @@ Select a nearby data center to reduce latency, e.g., "Oregon" (marked by the red
29
29
you can select a nearby Asia Pacific region, such as Seoul or Tokyo. Please note
30
30
that some data centers may not have GPU instances.
31
31
32
+
32
33
### Increasing Limits
34
+
33
35
Before choosing an instance, check if there are quantity
34
36
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
36
39
limitation. The account currently cannot open "p2.xlarge" instance per region. If
37
40
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
Next, click the "Launch Instance" button marked by the red box in :numref:`fig_ec2` to launch your instance.
47
53
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`).
49
55
50
56
51
-

57
+

52
58
:width:`700px`
53
59
:label:`fig_ubuntu`
54
60
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.
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`).
68
75
69
76

70
77
:width:`700px`
71
78
:label:`fig_p2x`
72
79
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.
74
81
75
-

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
+

76
85
:width:`700px`
77
86
:label:`fig_disk`
78
87
88
+
89
+
79
90
Finally, go to "7. Review" and click "Launch" to launch the configured
80
91
instance. The system will now prompt you to select the key pair used to access
81
92
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
100
111
101
112
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.
102
113
103
-

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:
108
121
109
122
```bash
110
-
cd /Downloads ## if D2L_key.pem is stored in Downloads folder
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`.
142
154
143
155

144
156
:width:`500px`
145
157
:label:`fig_cuda`
146
158
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.
## 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`.
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.
192
197
193
-
```bash
194
-
~/miniconda3/bin/conda init
195
-
source~/.bashrc
196
-
```
197
198
199
+
## Running the Jupyter Notebook remotely
198
200
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:
200
202
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
206
203
```
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
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:
245
213
246
214
```
247
-
# This command must be run in the local command line
: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.
255
221
256
-

222
+

257
223
:width:`700px`
258
224
:label:`fig_jupyter`
259
225
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.
261
230
262
231
263
232
## Closing Unused Instances
264
233
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.
266
238
267
239
If you want to use the instance as a template for many more instances,
268
240
right-click on the example in :numref:`fig_connect` and select "Image" $\rightarrow$
269
241
"Create" to create an image of the instance. Once this is complete, select
270
242
"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
273
245
the saved image. The only difference is that, in "1. Choose AMI" shown in
274
246
:numref:`fig_ubuntu`, you must use the "My AMIs" option on the left to select your saved
275
247
image. The created instance will retain the information stored on the image hard
@@ -279,13 +251,14 @@ environments.
279
251
280
252
## Summary
281
253
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.
284
257
285
258
286
259
## Exercises
287
260
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.
289
262
1. Experiment with different GPU servers. How fast are they?
290
263
1. Experiment with multi-GPU servers. How well can you scale things up?
0 commit comments