Skip to content

Commit 7b6f3f8

Browse files
authored
Merge pull request #280 from LxinJ05/LxinJ05-patch-1
2 parents 079613b + d77c8d7 commit 7b6f3f8

File tree

66 files changed

+5347
-4303
lines changed

Some content is hidden

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

66 files changed

+5347
-4303
lines changed

docs/01-getting-started/01-overview.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ Apache TVM 是一个机器学习编译框架,**遵循Python 优先开发和通
1313

1414
## 核心目标
1515
* 优化机器学习任务的性能,组合使用库与代码生成器。
16-
* 部署机器学习任务至多种全新环境,包括新的运行时和新硬件。
16+
* 部署机器学习任务至多种全新环境,包括新的运行时和新硬件。
1717
* 持续改进与定制机器学习部署流程,可通过 Python 快速定制库调度,引入定制算子与代码生成方式。
1818

1919

2020
## 关键流程
2121

22-
以下是使用 TVM 部署机器学习模型的典型流程。可运行示例请参见 [快速开始](https://tvm.apache.org/docs/get_started/tutorials/quick_start.html#quick-start)
22+
以下是使用 TVM 部署机器学习模型的典型流程。可运行示例请参见 [快速开始](/docs/getting-started/quick-start/)
2323

2424

2525
1. **导入 / 构建一个机器学习模型**
@@ -31,7 +31,7 @@ TVM 支持从多种框架导入模型用于通用机器学习模型,如 PyTorc
3131

3232
pipeline 封装了一系列转换,以实现两个目标:
3333
* **图优化:** 如算子融合、布局重写等。
34-
* **张量程序优化:** 将算子映射到底层实现(包括库或代码生成器)。
34+
* **张量程序优化:** 将算子映射到底层实现(包括库或代码生成器)。
3535

3636

3737
:::note

docs/01-getting-started/02-installing-tvm/01-install-from-source.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ title: 从源码安装
99

1010

1111
**目录**
12-
* [步骤 1:安装依赖项](https://tvm.apache.org/docs/install/from_source.html#step-1-install-dependencies)
13-
* [步骤 2:从 GitHub 获取源码](https://tvm.apache.org/docs/install/from_source.html#step-2-get-source-from-github)
14-
* [步骤 3:配置与构建](https://tvm.apache.org/docs/install/from_source.html#step-3-configure-and-build)
15-
* [步骤 4:验证安装](https://tvm.apache.org/docs/install/from_source.html#step-4-validate-installation)
16-
* [步骤 5:额外 Python 依赖项](https://tvm.apache.org/docs/install/from_source.html#step-5-extra-python-dependencies)
17-
* [高级构建配置](https://tvm.apache.org/docs/install/from_source.html#advanced-build-configuration)
18-
* [Ccache](https://tvm.apache.org/docs/install/from_source.html#ccache)
19-
* [在 Windows 上构建](https://tvm.apache.org/docs/install/from_source.html#building-on-windows)
20-
* [构建 ROCm 支持](https://tvm.apache.org/docs/install/from_source.html#building-rocm-support)
21-
* [启用 C++ 测试](https://tvm.apache.org/docs/install/from_source.html#enable-c-tests)
12+
* [步骤 1:安装依赖项](/docs/getting-started/installing-tvm/install-from-source#%E6%AD%A5%E9%AA%A4-1%E5%AE%89%E8%A3%85%E4%BE%9D%E8%B5%96%E9%A1%B9)
13+
* [步骤 2:从 GitHub 获取源码](/docs/getting-started/installing-tvm/install-from-source#%E6%AD%A5%E9%AA%A4-2%E4%BB%8E-github-%E8%8E%B7%E5%8F%96%E6%BA%90%E7%A0%81)
14+
* [步骤 3:配置与构建](/docs/getting-started/installing-tvm/install-from-source#%E6%AD%A5%E9%AA%A4-3%E9%85%8D%E7%BD%AE%E4%B8%8E%E6%9E%84%E5%BB%BA)
15+
* [步骤 4:验证安装](/docs/getting-started/installing-tvm/install-from-source#%E6%AD%A5%E9%AA%A4-4%E9%AA%8C%E8%AF%81%E5%AE%89%E8%A3%85)
16+
* [步骤 5:额外 Python 依赖项](/docs/getting-started/installing-tvm/install-from-source#%E6%AD%A5%E9%AA%A4-5-%E9%A2%9D%E5%A4%96-python-%E4%BE%9D%E8%B5%96%E9%A1%B9)
17+
* [高级构建配置](/docs/getting-started/installing-tvm/install-from-source#%E9%AB%98%E7%BA%A7%E6%9E%84%E5%BB%BA%E9%85%8D%E7%BD%AE)
18+
* [Ccache](/docs/getting-started/installing-tvm/install-from-source#ccache)
19+
* [在 Windows 上构建](/docs/getting-started/installing-tvm/install-from-source#%E5%9C%A8-windows-%E4%B8%8A%E6%9E%84%E5%BB%BA)
20+
* [构建 ROCm 支持](/docs/getting-started/installing-tvm/install-from-source#%E6%9E%84%E5%BB%BA-rocm-%E6%94%AF%E6%8C%81)
21+
* [启用 C++ 测试](/docs/getting-started/installing-tvm/install-from-source#%E5%90%AF%E7%94%A8-c-%E6%B5%8B%E8%AF%95)
2222

2323

24-
## [步骤 1:安装依赖项](https://tvm.apache.org/docs/install/from_source.html#id2)
24+
## 步骤 1:安装依赖项
2525

2626
Apache TVM 需要以下依赖项:
2727
* CMake (>= 3.24.0)
@@ -62,7 +62,7 @@ conda activate tvm-build-venv
6262
```
6363

6464

65-
## [步骤 2:从 GitHub 获取源码](https://tvm.apache.org/docs/install/from_source.html#id3)
65+
## 步骤 2:从 GitHub 获取源码
6666

6767
你也可以选择从 GitHub 克隆源码仓库:
6868

@@ -80,7 +80,7 @@ git clone --recursive https://github.com/apache/tvm tvm
8080
:::
8181

8282

83-
## [步骤 3:配置与构建](https://tvm.apache.org/docs/install/from_source.html#id4)
83+
## 步骤 3:配置与构建
8484

8585
创建一个构建目录并运行 CMake 进行配置。以下示例展示了如何构建:
8686

@@ -162,7 +162,7 @@ pip install -e /path-to-tvm/python
162162
```
163163

164164

165-
## [步骤 4:验证安装](https://tvm.apache.org/docs/install/from_source.html#id5)
165+
## 步骤 4:验证安装
166166

167167

168168
由于 TVM 是一个支持多语言绑定的编译器基础设施,安装过程中容易出错。因此,强烈建议在使用前验证安装。
@@ -225,7 +225,7 @@ False # or True
225225
请注意,上述命令验证的是本地机器上实际设备的存在情况,供 TVM 运行时(而非编译器)正确执行。然而,TVM 编译器可以在不需要物理设备的情况下执行编译任务。只要具备必要的工具链(如 NVCC),TVM 就支持在没有实际设备的情况下进行交叉编译。
226226

227227

228-
## [步骤 5. 额外 Python 依赖项](https://tvm.apache.org/docs/install/from_source.html#id6)
228+
## 步骤 5. 额外 Python 依赖项
229229

230230
从源代码构建不会自动安装所有必要的 Python 依赖项。可以使用以下命令安装额外的 Python 依赖项:
231231
* 必要依赖项:
@@ -243,9 +243,9 @@ pip3 install tornado
243243
```plain
244244
pip3 install tornado psutil 'xgboost>=1.1.0' cloudpickle
245245
```
246-
## [高级构建配置](https://tvm.apache.org/docs/install/from_source.html#id7)
246+
## 高级构建配置
247247

248-
### [Ccache](https://tvm.apache.org/docs/install/from_source.html#id8)
248+
### Ccache
249249

250250

251251
在支持的平台上,[Ccache 编译器包装器](https://ccache.dev/) 可以显著减少 TVM 的构建时间(尤其是构建 [cutlass](https://github.com/NVIDIA/cutlass) 或 [flashinfer](https://github.com/flashinfer-ai/flashinfer) 时)。启用 Ccache 的方式如下:
@@ -255,12 +255,12 @@ pip3 install tornado psutil 'xgboost>=1.1.0' cloudpickle
255255
* 将 Ccache 作为 CMake 的 C++ 编译器前缀。配置时设置 `CMAKE_CXX_COMPILER_LAUNCHER`,例如:`cmake -DCMAKE_CXX_COMPILER_LAUNCHER=ccache ...`
256256

257257

258-
### [在 Windows 上构建](https://tvm.apache.org/docs/install/from_source.html#id9)
258+
### 在 Windows 上构建
259259

260260

261261
TVM 支持通过 MSVC 和 CMake 在 Windows 上构建。你需要安装 Visual Studio 编译器(最低要求:**Visual Studio Enterprise 2019**)。我们测试了 [GitHub Actions 的 Windows 2019 Runner](https://github.com/actions/virtual-environments/blob/main/images/win/Windows2019-Readme.md) 的配置,可访问该页面获取全部细节。
262262

263-
推荐按照 [步骤 1:安装依赖项](https://tvm.apache.org/docs/install/from_source.html#install-dependencies) 获取依赖项并激活 tvm-build 环境后,运行以下命令构建:
263+
推荐按照 [步骤 1:安装依赖项](/docs/getting-started/installing-tvm/install-from-source#%E6%AD%A5%E9%AA%A4-1%E5%AE%89%E8%A3%85%E4%BE%9D%E8%B5%96%E9%A1%B9) 获取依赖项并激活 tvm-build 环境后,运行以下命令构建:
264264

265265
```plain
266266
mkdir build
@@ -277,14 +277,14 @@ cmake --build build --config Release -- /m
277277
```
278278

279279

280-
### [构建 ROCm 支持](https://tvm.apache.org/docs/install/from_source.html#id10)
280+
### 构建 ROCm 支持
281281

282282
目前,ROCm 仅支持 Linux 平台。以下是配置步骤:
283283
* 设置 `set(USE_ROCM ON)`,并将 ROCM_PATH 设置为正确的路径。
284284
* 安装 ROCm 的 HIP 运行时,确保系统已正确安装 ROCm。
285285
* 安装最新稳定版的 LLVM(如 v6.0.1)和 LLD,确保 `ld.lld` 可通过命令行调用。
286286

287-
### [启用 C++ 测试](https://tvm.apache.org/docs/install/from_source.html#id11)
287+
### 启用 C++ 测试
288288

289289
TVM 使用 [Google Test](https://github.com/google/googletest) 驱动 C++ 测试,最简单的安装方式是从源码构建:
290290

docs/01-getting-started/02-installing-tvm/index.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ title: 安装 TVM
44

55
---
66

7-
* [从源码安装](https://tvm.apache.org/docs/install/from_source.html)
8-
* [Docker 镜像](https://tvm.apache.org/docs/install/docker.html)
7+
* [从源码安装](/docs/getting-started/installing-tvm/install-from-source)
8+
* [Docker 镜像](/docs/getting-started/installing-tvm/docker-images)
99

1010

11-
访问 [从源码安装 TVM](https://tvm.apache.org/docs/install/from_source.html#install-from-source) 页面,以从源代码安装 TVM。从源码安装可以让你最大程度地灵活配置构建选项,并确保使用官方发布的源代码。如果你希望在移动设备或嵌入式设备上部署 TVM,你不需要在设备上安装完整的 TVM 框架,而只需安装运行时环境即可。
11+
访问 [从源码安装](/docs/getting-started/installing-tvm/install-from-source) 页面,以从源代码安装 TVM。从源码安装可以让你最大程度地灵活配置构建选项,并确保使用官方发布的源代码。如果你希望在移动设备或嵌入式设备上部署 TVM,你不需要在设备上安装完整的 TVM 框架,而只需安装运行时环境即可。
1212

1313

14-
如果你想快速体验 TVM 或运行一些示例和教程,可以 [通过 Docker 安装](https://tvm.apache.org/docs/install/docker.html#docker-images)。你也可以通过 `pip` 在本地安装 TVM。
14+
如果你想快速体验 TVM 或运行一些示例和教程,可以 [通过 Docker 安装](/docs/getting-started/installing-tvm/docker-images)。你也可以通过 `pip` 在本地安装 TVM。
1515

1616

1717
```plain

docs/01-getting-started/03-quick-start/index.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ title: 快速入门
77

88
:::note
99

10-
本教程可通过 Google Colab 交互运行!也可点击[此处](https://tvm.apache.org/docs/get_started/tutorials/quick_start.html#sphx-glr-download-get-started-tutorials-quick-start-py)在本地运行 Jupyter Notebook。
10+
本教程可通过 Google Colab 交互运行!也可点击[此处](/docs/getting-started/quick-start/#%E5%90%8E%E7%BB%AD%E9%98%85%E8%AF%BB)在本地运行 Jupyter Notebook。
1111

1212
[在 Google Colab 中打开](https://colab.research.google.com/github/apache/tvm-site/blob/asf-site/docs/_downloads/eceb05a9badb601d2def02240aa869e9/quick_start.ipynb)
1313

@@ -19,12 +19,12 @@ title: 快速入门
1919

2020

2121
**目录**
22-
* [概览](https://tvm.apache.org/docs/get_started/tutorials/quick_start.html#overview)
23-
* [完整流程](https://tvm.apache.org/docs/get_started/tutorials/quick_start.html#overall-flow)
24-
* [构建或导入模型](https://tvm.apache.org/docs/get_started/tutorials/quick_start.html#construct-or-import-a-model)
25-
* [执行优化转换](https://tvm.apache.org/docs/get_started/tutorials/quick_start.html#perform-optimization-transformations)
26-
* [构建和通用部署](https://tvm.apache.org/docs/get_started/tutorials/quick_start.html#build-and-universal-deployment)
27-
* [阅读下文](https://tvm.apache.org/docs/get_started/tutorials/quick_start.html#read-next)
22+
* [概览](/docs/getting-started/quick-start/#%E6%A6%82%E8%BF%B0)
23+
* [完整流程](/docs/getting-started/quick-start/#%E5%AE%8C%E6%95%B4%E6%B5%81%E7%A8%8B)
24+
* [构建或导入模型](/docs/getting-started/quick-start/#%E6%9E%84%E5%BB%BA%E6%88%96%E5%AF%BC%E5%85%A5%E6%A8%A1%E5%9E%8B)
25+
* [执行优化转换](/docs/getting-started/quick-start/#%E6%89%A7%E8%A1%8C%E4%BC%98%E5%8C%96%E8%BD%AC%E6%8D%A2)
26+
* [构建和通用部署](/docs/getting-started/quick-start/#%E6%9E%84%E5%BB%BA%E5%92%8C%E9%80%9A%E7%94%A8%E9%83%A8%E7%BD%B2)
27+
* [阅读下文](/docs/getting-started/quick-start/#%E5%90%8E%E7%BB%AD%E9%98%85%E8%AF%BB)
2828

2929

3030
## 概述
@@ -201,7 +201,8 @@ Tensor out = vm.getFunction("prefill").pushArg(data).pushArg(weight).pushArg(kv_
201201
## 后续阅读
202202

203203

204-
本教程演示了使用 Apache TVM 编译神经网络模型的整体流程。如需了解更高级或具体的主题,请参考以下教程:
204+
本教程演示了使用 Apache TVM 编译神经网络模型的整体流程。如需了解更高级或具体的主题,请参考以下教程(可右键另存为下载)
205205
* [下载 Jupyter notebook: quick_start.ipynb](https://tvm.apache.org/docs/_downloads/eceb05a9badb601d2def02240aa869e9/quick_start.ipynb)
206206
* [下载 Python 源代码: quick_start.py](https://tvm.apache.org/docs/_downloads/baf675793174f2e9b3d5da483e35ef27/quick_start.py)
207207
* [下载压缩包: quick_start.zip](https://tvm.apache.org/docs/_downloads/bb7db6678496193ed0c55d3b95fa6778/quick_start.zip)
208+

docs/01-getting-started/04-irmodule/index.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ title: IRModule
77

88
:::note
99

10-
本教程可通过 Google Colab 交互式运行!也可点击[此处](https://tvm.apache.org/docs/get_started/tutorials/ir_module.html#sphx-glr-download-get-started-tutorials-ir-module-py)在本地运行 Jupyter Notebook。
10+
本教程可通过 Google Colab 交互式运行!也可点击[此处](/docs/getting-started/irmodule/#%E9%83%A8%E7%BD%B2%E5%88%B0%E5%85%B6%E4%BB%96%E5%90%8E%E7%AB%AF)在本地运行 Jupyter Notebook。
1111

1212
[在 Google Colab 中打开](https://colab.research.google.com/github/apache/tvm-site/blob/asf-site/docs/_downloads/a6d7947451d373bc811080cffa18dc7c/ir_module.ipynb)
1313

@@ -18,10 +18,10 @@ title: IRModule
1818

1919

2020
**目录**
21-
* [创建 IRModule](https://tvm.apache.org/docs/get_started/tutorials/ir_module.html#create-irmodule)
22-
* [IRModule 的属性](https://tvm.apache.org/docs/get_started/tutorials/ir_module.html#attributes-of-an-irmodule)
23-
* [对 IRModule 进行转换](https://tvm.apache.org/docs/get_started/tutorials/ir_module.html#transformations-on-irmodules)
24-
* [通用部署 IRModule](https://tvm.apache.org/docs/get_started/tutorials/ir_module.html#deploy-the-irmodule-universally)
21+
* [创建 IRModule](/docs/getting-started/irmodule/#%E5%88%9B%E5%BB%BA-irmodule)
22+
* [IRModule 的属性](/docs/getting-started/irmodule/#irmodule-%E7%9A%84%E5%B1%9E%E6%80%A7)
23+
* [对 IRModule 进行转换](/docs/getting-started/irmodule/#%E5%AF%B9-irmodule-%E8%BF%9B%E8%A1%8C%E8%BD%AC%E6%8D%A2)
24+
* [通用部署 IRModule](/docs/getting-started/irmodule/#%E9%80%9A%E7%94%A8%E9%83%A8%E7%BD%B2-irmodule)
2525

2626

2727
```plain
@@ -194,6 +194,7 @@ class TVMScriptModule:
194194
mod_from_script = TVMScriptModule
195195
mod_from_script.show()
196196
197+
197198
```
198199

199200

@@ -412,10 +413,10 @@ print(mod.get_global_vars())
412413

413414

414415
接着,Apache TVM Unity 提供了一套默认的转换流水线,以简化转换过程。我们可以将默认的转换流水线应用到模块上。其中默认的 zero 流水线包含以下基本转换步骤:
415-
* **LegalizeOps:**将 Relax 操作转换为 call_tir 调用,配合相应的 TensorIR 函数。此转换会让 IRModule 同时包含 Relax 函数与 TensorIR 函数。
416-
* **AnnotateTIROpPattern:**为 TensorIR 函数打上模式标签,为后续的算子融合做好准备。
417-
* **FoldConstant:**进行常量折叠优化,简化涉及常量的运算。
418-
* **FuseOps 和 FuseTIR:**根据上一阶段 AnnotateTIROpPattern 所打的标签对 Relax 和 TensorIR 函数进行融合优化。
416+
* **LegalizeOps:** 将 Relax 操作转换为 call_tir 调用,配合相应的 TensorIR 函数。此转换会让 IRModule 同时包含 Relax 函数与 TensorIR 函数。
417+
* **AnnotateTIROpPattern:** 为 TensorIR 函数打上模式标签,为后续的算子融合做好准备。
418+
* **FoldConstant:** 进行常量折叠优化,简化涉及常量的运算。
419+
* **FuseOps 和 FuseTIR:** 根据上一阶段 AnnotateTIROpPattern 所打的标签对 Relax 和 TensorIR 函数进行融合优化。
419420

420421

421422
:::note
@@ -550,8 +551,9 @@ print(cpu_out)
550551
输出:
551552

552553
```plain
553-
[[ 0.13505758 -0.29273182 0.04422678 -0.06554039 0.02372958 0.00591143
554-
-0.11505812 -0.11465105 -0.08466949 0.1232063 ]]
554+
[[ 6.4867303e-02 1.6763064e-01 9.3035400e-05 1.8091209e-01
555+
8.0412276e-02 -1.4292052e-01 -3.2873321e-02 -7.4184828e-02
556+
-6.7507513e-02 1.5245053e-01]]
555557
```
556558

557559

@@ -593,14 +595,15 @@ assert np.allclose(cpu_out, gpu_out, atol=1e-3)
593595
输出:
594596

595597
```plain
596-
[[ 0.13505754 -0.29273173 0.04422677 -0.06554036 0.02372959 0.00591139
597-
-0.115058 -0.11465096 -0.08466944 0.12320635]]
598+
[[ 6.4867347e-02 1.6763058e-01 9.3113631e-05 1.8091221e-01
599+
8.0412284e-02 -1.4292067e-01 -3.2873336e-02 -7.4184842e-02
600+
-6.7507453e-02 1.5245046e-01]]
598601
```
599602

600603

601604
### 部署到其他后端
602605

603-
Apache TVM Unity 也支持部署到其他后端,包括不同类型的 GPU(如 Metal、ROCm、Vulkan 和 OpenCL)、不同类型的 CPU(如 x86 和 ARM),以及其他新兴平台(例如 WebAssembly)。部署流程与 GPU 后端类似。
606+
Apache TVM Unity 也支持部署到其他后端,包括不同类型的 GPU(如 Metal、ROCm、Vulkan 和 OpenCL)、不同类型的 CPU(如 x86 和 ARM),以及其他新兴平台(例如 WebAssembly)。部署流程与 GPU 后端类似(可右键另存为下载)
604607
* [下载 Jupyter Notebook: ir_module.ipynb](https://tvm.apache.org/docs/_downloads/a6d7947451d373bc811080cffa18dc7c/ir_module.ipynb)
605608
* [下载 Python 源代码: ir_module.py](https://tvm.apache.org/docs/_downloads/0b64717d4cc6027368b96fad40119738/ir_module.py)
606609
* [下载压缩包: ir_module.zip](https://tvm.apache.org/docs/_downloads/11c11e53c7dace51a8be968ee169ed0d/ir_module.zip)

docs/02-how-to/01-end-to-end-optimize-model.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ title: 端到端优化模型
77

88
:::note
99

10-
本教程可通过 Google Colab 交互式运行!也可点击[此处](https://tvm.apache.org/docs/get_started/tutorials/quick_start.html#sphx-glr-download-get-started-tutorials-quick-start-py)在本地运行 Jupyter Notebook。
10+
本教程可通过 Google Colab 交互式运行!也可点击[此处](/docs/how-to/end-to-end-optimize-model#%E6%9E%84%E5%BB%BA%E4%B8%8E%E9%83%A8%E7%BD%B2)在本地运行 Jupyter Notebook。
1111

1212
[在 Google Colab 中打开](https://colab.research.google.com/github/apache/tvm-site/blob/asf-site/docs/_downloads/317a8cc53139718b9a36a16ba052e44b/e2e_opt_model.ipynb)
1313

@@ -106,7 +106,7 @@ if not IS_IN_CI:
106106

107107
## 构建与部署
108108

109-
最后,我们构建优化后的模型,并将其部署到目标设备。在 CI 环境中会跳过此步骤。
109+
最后,我们构建优化后的模型,并将其部署到目标设备。在 CI 环境中会跳过此步骤。可右键另存为下载。
110110

111111

112112
```plain
@@ -126,3 +126,5 @@ if not IS_IN_CI:
126126
* [下载压缩包:e2e_opt_model.zip](https://tvm.apache.org/docs/_downloads/a7dd7652b2ad50f82d7b739ce3645799/e2e_opt_model.zip)
127127

128128

129+
130+

0 commit comments

Comments
 (0)