Skip to content

Commit

Permalink
第一章
Browse files Browse the repository at this point in the history
  • Loading branch information
jiewong42 committed Feb 23, 2025
1 parent d53fe1e commit 7cc8465
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 18 deletions.
6 changes: 2 additions & 4 deletions source/第一章/1.1 PyTorch简介.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ PyTorch是由Meta AI(Facebook)人工智能研究小组开发的一种基于Lua

**“All in PyTorch”**,对于PyTorch的发展我们只能用一句话来概况了,PyTorch自从推出就获得巨大的关注并受到了很多人的喜欢,而最直观的莫过于下面数据所表现的简明直了。

下图来自[Paper with code](https://paperswithcode.com/trends)网站,**颜色面积代表使用该框架的论文公开代码库的数量**我们可以发现截至2021年6月,PyTorch的代码实现已经是TensorFlow实现的4倍,我们也可以看红色部分的PyTorch正在取代他的老大哥称霸学术圈,PyTorch会借助ONNX所带来的落地能力在工业界逐渐走向主导地位。
下图来自[Paper with code](https://paperswithcode.com/trends)网站,**颜色面积代表使用该框架的论文公开代码库的数量**我们可以发现截至2024年12月,PyTorch的代码实现已经是TensorFlow实现的29.5倍,我们也可以看红色部分的PyTorch正在取代他的老大哥称霸学术圈,PyTorch会借助ONNX所带来的落地能力在工业界逐渐走向主导地位。

总的来说,我们必须承认到现在为止PyTorch 1.x还是有不如别的框架的地方,但是我们相信PyTorch 2.x版本会给我们带来更大的惊喜。

![框架对比图](figures/main_compare.png)
![框架对比图](figures/pytorch_2025.png)

## 1.1.2 PyTorch的优势
+ **更加简洁**,相比于其他的框架,PyTorch的框架更加简洁,易于理解。PyTorch的设计追求最少的封装,避免重复造轮子。
Expand Down
30 changes: 16 additions & 14 deletions source/第一章/1.2 PyTorch的安装.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,30 @@ PyTorch的安装是我们学习PyTorch的第一步,也是经常出错的一步
### Step 2:检验是否安装成功
在开始页找到Anaconda Prompt,一般在Anaconda3的文件夹下,( Linux在终端下就行了)

![prompt](figures/prompt.png)
![prompt](figures/anaconda_windows.png)

### Step 3:创建虚拟环境

Linux在终端(`Ctrl`+`Alt`+`T`)进行,Windows在`Anaconda Prompt`进行

#### 查看现存虚拟环境
查看已经安装好的虚拟环境,可以看到我们这里已经有两个环境存在了
查看已经安装好的虚拟环境,可以看到默认有一个base环境

```bash
conda env list
```

![env_list](figures/env_list.png)
![env_list](figures/conda_env_list.png)

#### 创建虚拟环境
在深度学习和机器学习中,我们经常会创建不同版本的虚拟环境来满足我们的一些需求。下面我们介绍创建虚拟环境的命令。
```bash
conda create -n env_name python==version
# 注:将env_name 替换成你的环境的名称,version替换成对应的版本号,eg:3.8
conda create -n pytorch2.6 python=3.10 -y
```

![](figures/install.png)
![](figures/anaconda新建环境.png)


****
1. 这里忽略我们的warning,因为我们测试的时候已经安了又卸载一遍了,正常时是不会有warning的。
2. 在选择Python版本时,不要选择太高,建议选择3.6-3.8,版本过高会导致相关库不适配。

#### 安装包
```bash
Expand Down Expand Up @@ -168,9 +165,8 @@ vi .condarc

我们可以通过在`cmd/terminal中`输入`nvidia-smi`(Linux和Win命令一样)、使用NVIDIA控制面板和使用任务管理器查看自己是否有NVIDIA的独立显卡及其型号

![查看GPU](figures/gpu.png)
![windows查看cuda.png](figures/windows查看cuda.png)

![查看显卡](figures/Nvidia.png)



Expand All @@ -197,7 +193,7 @@ vi .condarc
### Step 3:选择命令
我们需要结合自己情况选择命令并复制下来,然后使用conda下载或者pip下载(建议conda安装)

打开`Terminal`,输入`conda activate env_name`(env_name 为你对应的环境名称),切换到对应的环境下面,我们就可以进行PyTorch的安装了。
打开`Anaconda Prompt`,输入`conda activate env_name`(env_name 为你对应的环境名称),切换到对应的环境下面,我们就可以进行PyTorch的安装了。

![](figures/choose_envs.png)

Expand All @@ -222,7 +218,13 @@ vi .condarc

如果我们使用的`Anaconda Prompt`进行下载的话,我们需要先通过`conda activate env_name`,激活我们的虚拟环境中去,再输入命令。

****: 我们需要要把下载指令后面的 -c pytorch 去掉以保证使用清华源下载,否则还是默认从官网下载。
值得一提的是,Conda 已经不再被推荐作为 pytorch
安装的工具了,我们用 pip 来下载
```
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124
```

### Step 5:离线下载

#### Windows:
Expand Down Expand Up @@ -254,7 +256,7 @@ import torch
torch.cuda.is_available()
```
```bash
False
Ture
```
这条命令意思是检验是否可以调用cuda,如果我们**安装的是CPU版本的话会返回False,能够调用GPU的会返回True**。一般这个命令不报错的话就证明安装成功。

Expand Down
Binary file added source/第一章/figures/anaconda_windows.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added source/第一章/figures/conda_env_list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added source/第一章/figures/pytorch_2025.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added source/第一章/figures/pytorch_choose.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added source/第一章/figures/windows查看cuda.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7cc8465

Please sign in to comment.