Skip to content

Commit

Permalink
install
Browse files Browse the repository at this point in the history
  • Loading branch information
Mu Li authored and astonzhang committed Feb 17, 2021
1 parent b1ef246 commit d3046f1
Show file tree
Hide file tree
Showing 2 changed files with 376 additions and 0 deletions.
154 changes: 154 additions & 0 deletions chapter_installation/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
# 安装
:label:`chap_installation`

为了让您开始运行并获得动手学习体验,我们需要为您设置一个运行 Python、Jupyter 笔记本电脑、相关库以及运行本书所需的代码的环境。

## 安装米尼康达

最简单的方法就是安装 [Miniconda](https://conda.io/en/latest/miniconda.html)。Python 3.x 版本是必需的。如果已安装 conda,则可以跳过以下步骤。从网站下载相应的 Miniconda sh 文件,然后使用 `sh <FILENAME> -b` 从命令行执行安装。对于 macOS 用户:

```bash
# The file name is subject to changes
sh Miniconda3-latest-MacOSX-x86_64.sh -b
```

对于 Linux 用户:

```bash
# The file name is subject to changes
sh Miniconda3-latest-Linux-x86_64.sh -b
```

接下来,初始化外壳,以便我们可以直接运行 `conda`

```bash
~/miniconda3/bin/conda init
```

现在关闭并重新打开当前的 shell。您应该能够创建一个新的环境,如下所示:

```bash
conda create --name d2l -y
```

## 下载 D2L 笔记本电脑

接下来,我们需要下载这本书的代码。您可以点击任何 HTML 页面顶部的 “所有笔记本” 选项卡下载并解压代码。或者,如果您有 `unzip`(否则运行 `sudo apt install unzip`)可用:

```bash
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
```

现在我们要激活 `d2l` 环境并安装 `pip`。在此命令后面的查询中输入 `y`

```bash
conda activate d2l
conda install python=3.7 pip -y
```

## 安装框架和 `d2l` 软件包

:begin_tab:`mxnet,pytorch`
在安装深度学习框架之前,请先检查您的计算机上是否有正确的 GPU(在标准笔记本电脑上为显示器提供电源的 GPU 不计入我们的目的)。如果要在 GPU 服务器上安装,请继续执行 :ref:`subsec_gpu` 以获取有关安装 GPU 支持版本的说明。

否则,您可以安装 CPU 版本。这将是足够的马力来帮助您完成前几章,但您需要在运行更大的模型之前访问 GPU。
:end_tab:

:begin_tab:`mxnet`
```bash
pip install mxnet==1.6.0
```
:end_tab:

:begin_tab:`pytorch`
```bash
pip install torch==1.5.1 torchvision -f https://download.pytorch.org/whl/torch_stable.html
```
:end_tab:

:begin_tab:`tensorflow`
您可以通过以下方式安装具有 CPU 和 GPU 支持的腾讯流:

```bash
pip install tensorflow==2.2.0 tensorflow-probability==0.10.0
```
:end_tab:

我们还安装了 `d2l` 软件包,它封装了本书中常用的函数和类。

```bash
pip install -U d2l
```

安装完成后,我们现在通过运行以下操作打开 Jupyter 笔记本:

```bash
jupyter notebook
```

此时,您可以在 Web 浏览器中打开 http://localhost:8888(通常会自动打开)。然后我们可以运行这本书的每个部分的代码。在运行书籍代码或更新深度学习框架或 `d2l` 软件包之前,请始终执行 `conda activate d2l` 以激活运行时环境。要退出环境,请运行 `conda deactivate`

## GPU 支持
:label:`subsec_gpu`

:begin_tab:`mxnet,pytorch`
默认情况下,安装深度学习框架时不支持 GPU,以确保它在任何计算机(包括大多数笔记本电脑)上运行。本书的一部分要求或建议使用 GPU 运行。如果您的计算机具有 NVIDIA 显卡并且已安装 [CUDA](https://developer.nvidia.com/cuda-downloads),则应安装启用 GPU 的版本。如果您已经安装了仅 CPU 版本,则可能需要首先通过运行以下操作将其删除:
:end_tab:

:begin_tab:`tensorflow`
默认情况下,TensorFlow 安装了 GPU 支持。如果您的计算机具有 NVIDIA 显卡并且已安装 [CUDA](https://developer.nvidia.com/cuda-downloads),那么您都可以完成。
:end_tab:

:begin_tab:`mxnet`
```bash
pip uninstall mxnet
```
:end_tab:

:begin_tab:`pytorch`
```bash
pip uninstall torch
```
:end_tab:

:begin_tab:`mxnet,pytorch`
然后,我们需要找到您安装的 CUDA 版本。你可以通过 `nvcc --version``cat /usr/local/cuda/version.txt` 查看它。假定您已安装 CUDA 10.1,则可以使用以下命令进行安装:
:end_tab:

:begin_tab:`mxnet`
```bash
# For Windows users
pip install mxnet-cu101==1.6.0b20190926

# For Linux and macOS users
pip install mxnet-cu101==1.6.0
```
:end_tab:

:begin_tab:`pytorch`
```bash
pip install torch==1.5.1+cu101 -f https://download.pytorch.org/whl/torch_stable.html
```
:end_tab:

:begin_tab:`mxnet,pytorch`
您可以根据您的 CUDA 版本更改最后一位数字,例如:CUDA 10.0 的 `cu100` 和 CUDA 9.0 的 `cu90`
:end_tab:

## 练习

1. 下载该书的代码并安装运行时环境。

:begin_tab:`mxnet`
[Discussions](https://discuss.d2l.ai/t/23)
:end_tab:

:begin_tab:`pytorch`
[Discussions](https://discuss.d2l.ai/t/24)
:end_tab:

:begin_tab:`tensorflow`
[Discussions](https://discuss.d2l.ai/t/436)
:end_tab:
222 changes: 222 additions & 0 deletions chapter_installation/index_origin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
# Installation
:label:`chap_installation`

In order to get you up and running for hands-on learning experience,
we need to set you up with an environment for running Python,
Jupyter notebooks, the relevant libraries,
and the code needed to run the book itself.

## Installing Miniconda

The simplest way to get going will be to install
[Miniconda](https://conda.io/en/latest/miniconda.html). The Python 3.x version
is required. You can skip the following steps if conda has already been installed.
Download the corresponding Miniconda sh file from the website
and then execute the installation from the command line
using `sh <FILENAME> -b`. For macOS users:

```bash
# The file name is subject to changes
sh Miniconda3-latest-MacOSX-x86_64.sh -b
```


For Linux users:

```bash
# The file name is subject to changes
sh Miniconda3-latest-Linux-x86_64.sh -b
```


Next, initialize the shell so we can run `conda` directly.

```bash
~/miniconda3/bin/conda init
```


Now close and re-open your current shell. You should be able to create a new
environment as following:

```bash
conda create --name d2l -y
```


## Downloading the D2L Notebooks

Next, we need to download the code of this book. You can click the "All
Notebooks" tab on the top of any HTML page to download and unzip the code.
Alternatively, if you have `unzip` (otherwise run `sudo apt install unzip`) available:

```bash
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
```


Now we will want to activate the `d2l` environment and install `pip`.
Enter `y` for the queries that follow this command.

```bash
conda activate d2l
conda install python=3.7 pip -y
```


## Installing the Framework and the `d2l` Package

:begin_tab:`mxnet,pytorch`
Before installing the deep learning framework, please first check
whether or not you have proper GPUs on your machine
(the GPUs that power the display on a standard laptop
do not count for our purposes).
If you are installing on a GPU server,
proceed to :ref:`subsec_gpu` for instructions
to install a GPU-supported version.

Otherwise, you can install the CPU version.
That will be more than enough horsepower to get you
through the first few chapters but you will want
to access GPUs before running larger models.
:end_tab:


:begin_tab:`mxnet`

```bash
pip install mxnet==1.6.0
```


:end_tab:

:begin_tab:`pytorch`

```bash
pip install torch==1.5.1 torchvision -f https://download.pytorch.org/whl/torch_stable.html
```


:end_tab:

:begin_tab:`tensorflow`
You can install TensorFlow with both CPU and GPU support via the following:

```bash
pip install tensorflow==2.2.0 tensorflow-probability==0.10.0
```


:end_tab:


We also install the `d2l` package that encapsulates frequently used
functions and classes in this book.

```bash
pip install -U d2l
```


Once they are installed, we now open the Jupyter notebook by running:

```bash
jupyter notebook
```


At this point, you can open http://localhost:8888 (it usually opens automatically) in your Web browser. Then we can run the code for each section of the book.
Please always execute `conda activate d2l` to activate the runtime environment
before running the code of the book or updating the deep learning framework or the `d2l` package.
To exit the environment, run `conda deactivate`.


## GPU Support
:label:`subsec_gpu`

:begin_tab:`mxnet,pytorch`
By default, the deep learning framework is installed without GPU support
to ensure that it will run on any computer (including most laptops).
Part of this book requires or recommends running with GPU.
If your computer has NVIDIA graphics cards and has installed [CUDA](https://developer.nvidia.com/cuda-downloads),
then you should install a GPU-enabled version.
If you have installed the CPU-only version,
you may need to remove it first by running:
:end_tab:

:begin_tab:`tensorflow`
By default, TensorFlow is installed with GPU support.
If your computer has NVIDIA graphics cards and has installed [CUDA](https://developer.nvidia.com/cuda-downloads),
then you are all set.
:end_tab:

:begin_tab:`mxnet`

```bash
pip uninstall mxnet
```


:end_tab:

:begin_tab:`pytorch`

```bash
pip uninstall torch
```


:end_tab:

:begin_tab:`mxnet,pytorch`
Then we need to find the CUDA version you installed.
You may check it through `nvcc --version` or `cat /usr/local/cuda/version.txt`.
Assume that you have installed CUDA 10.1,
then you can install with the following command:
:end_tab:

:begin_tab:`mxnet`

```bash
# For Windows users
pip install mxnet-cu101==1.6.0b20190926

# For Linux and macOS users
pip install mxnet-cu101==1.6.0
```


:end_tab:

:begin_tab:`pytorch`

```bash
pip install torch==1.5.1+cu101 -f https://download.pytorch.org/whl/torch_stable.html
```


:end_tab:

:begin_tab:`mxnet,pytorch`
You may change the last digits according to your CUDA version, e.g., `cu100` for
CUDA 10.0 and `cu90` for CUDA 9.0.
:end_tab:

## Exercises

1. Download the code for the book and install the runtime environment.

:begin_tab:`mxnet`
[Discussions](https://discuss.d2l.ai/t/23)
:end_tab:

:begin_tab:`pytorch`
[Discussions](https://discuss.d2l.ai/t/24)
:end_tab:

:begin_tab:`tensorflow`
[Discussions](https://discuss.d2l.ai/t/436)
:end_tab:

0 comments on commit d3046f1

Please sign in to comment.