-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into yfc/support_stable_diffusion
- Loading branch information
Showing
143 changed files
with
3,815 additions
and
1,904 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,30 @@ | ||
# IMPORTANT: | ||
# This file is ONLY used to merge PRs. Approvals from people in this file are required for merging. | ||
# | ||
# WARNING: The last matching pattern takes the most precedence and OVERWRITES previous rules. | ||
# Please be very careful when adding new patterns. | ||
|
||
/dipu/tests/python @lljbash @mrdanielw | ||
# ---------- base ---------- | ||
|
||
* @mrdanielw @jinminxi104 | ||
/.github/ @mrdanielw @wugeshui | ||
/.github/CODEOWNERS @mrdanielw @jinminxi104 | ||
|
||
# ---------- dipu ---------- | ||
|
||
### directories & files | ||
/dipu/torch_dipu/csrc_dipu/ @mrdanielw @fandaoyi @lljbash | ||
/dipu/tests/python/ @mrdanielw @lljbash | ||
/dipu/scripts/autogen_diopi_wrapper/ @mrdanielw @lljbash | ||
/dipu/scripts/autogen_diopi_wrapper/autogen_diopi_wrapper.py @mrdanielw @zhaoguochun1995 | ||
/dipu/scripts/ci/ @mrdanielw @wugeshui | ||
|
||
### build & linter | ||
/dipu/**/CMakeLists.txt @mrdanielw @lljbash @wiryls @Wrench-Git | ||
/dipu/**/*.cmake @mrdanielw @lljbash @wiryls @Wrench-Git | ||
/dipu/.clang* @mrdanielw @lljbash @wiryls | ||
|
||
# ---------- dicp ---------- | ||
|
||
/dicp/ @jinminxi104 | ||
/dicp/scripts/ci/ @jinminxi104 @wugeshui |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
recursive-include dicp/vendor/TopsGraph/codegen * | ||
recursive-include dicp/vendor/AscendGraph/codegen * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<!-- markdownlint-disable-next-line MD041 MD033 --> | ||
<div align=center> | ||
<!-- markdownlint-disable-next-line MD033 --> | ||
<img src="https://deeplink.readthedocs.io/zh-cn/latest/_static/image/logo.png" alt="DeepLink Logo"> | ||
</div> | ||
|
||
# DICP | ||
|
||
标准编译协议(Device-Independent Compile Protocol, DICP)定义了统一的计算描述(中间表示),通过计算图获取深度学习模型中的计算任务表达为上述中间表示,然后通过计算图优化技术自动生成人工智能芯片设备代码,从而提高研发效率和计算的执行性能。中间表示是介于源语言和目标语言之间的程序表示,能够极大程度地提高编译流程的可拓展性,同时也能降低优化流程对前端和后端的破坏。多层次中间表示包含从应用到芯片端的多种表示层次,不同层次旨在解决不同尺度的问题。 | ||
|
||
DICP 主要的核心功能如下: | ||
|
||
1. 通过接入编译路线带来性能优势,在大模型场景最大限度释放芯片能力。 | ||
2. 作为训练框架与国产硬件芯片之间的通用桥梁,支持多种前后端,带来使用易用性。 | ||
3. 提供易用、高效的一站式编译适配流程,灵活支持国产硬件图编译器的特性,提高芯片适配效率。 | ||
|
||
下图描述了 DICP 在编译链路中的位置: | ||
|
||
 | ||
|
||
1. 训练框架通过图获取模块将用户的模型代码转换成统一的中间表达。此处的中间表达完全与芯片无关。所以在之后的编译协议部分中,需要建立起与后端芯片的联系。这样才能高效的完成接入。 | ||
2. 编译协议完成了衔接框架与芯片编译器的工作,其中包含硬件相关的切图,统一中间表达与芯片所支持的算子之间的映射关系以及数据格式的转换模块。 | ||
3. 在编译协议吸收了芯片特点之后,由代码生成模块生成最终的代码,并通过芯片的编译器生成二进制可执行文件之后由框架调用。 | ||
|
||
## 基于 DICP 的国产硬件接入 PyTorch 2 实践 | ||
|
||
<!-- ### DICP vs 纯 Dynamo --> | ||
|
||
基于上述 DICP,国产硬件可快速接入 PyTorch 2 的编译路线。此路线中的 TorchDynamo 组件,可使国产硬件在运行时的 overhead 大幅缩小。 | ||
并且针对国产硬件实现了以下特性: | ||
|
||
- 灵活支持国产硬件图编译器的特性 | ||
- 支持多种国产硬件数据格式 | ||
- 支持动态 shape | ||
|
||
### 运行逻辑 | ||
|
||
DICP 的运行逻辑如下图所示: | ||
|
||
<!-- (**这张图有问题,需要讨论 by jinminxi**) --> | ||
 | ||
|
||
其中: | ||
|
||
1. **算子映射**:主要解决框架层算子与后端图编译器的算子之间的语义差别,包括 1 对 1 和 1 对多的转换。 | ||
2. **Shape & Dtype 推导**:进行 Shape & data_type 的推导,补全整张静态图上的信息,便于之后在代码生成模块能生成代码。 | ||
3. **子图改写**:将多个小算子融合成为一个或多个适合图编译器的算子,配合后端图编译器将计算效率最大化。 | ||
4. **数据格式调整**:是根据后端芯片与其图编译器的特性,针对特定的算子调整其输入输出的数据格式,使得最大程度的发挥芯片性能。 | ||
|
||
### 目录结构 | ||
|
||
- `dicp/dynamo_bridge`:多后端通用的接入代码,包含了 | ||
1. 接收从 AOTAutograd 下发而来的 FX Graph | ||
2. 启动各个厂商的 IR 转换与优化 | ||
3. 启动 CodeGen 以及 JIT 缓存的逻辑。 | ||
- `dicp/vender`: 主要包含了各个厂商 IR 的定义,AtenIR 到厂商 IR 的转换,厂商 IR 上的优化以及最后的代码生成模块。 | ||
- `test`: 包含了 model 测试与 op 测试 | ||
|
||
### Demo | ||
|
||
#### 安装 DICP | ||
|
||
```bash | ||
cd /path_to_dicp | ||
pip install . | ||
``` | ||
|
||
#### 在华为 910 上执行 llama7B 前向推理 | ||
|
||
```bash | ||
export DIPU_MOCK_CUDA = false | ||
export DICP_TOPS_DIPU = True | ||
export TEST_DIR = /path_to_dicp/test/ | ||
export LLAMA_MODEL_DIR=/path_to_llama_model | ||
bash /path_to_dicp/test/model/run_test_model.sh llama ascendgraph false | ||
``` | ||
|
||
#### 在燧原 T20 上执行 resnet50 训练 | ||
|
||
```bash | ||
export DIPU_MOCK_CUDA = false | ||
export DICP_TOPS_DIPU = True | ||
export TEST_DIR = /path_to_dicp/test/ | ||
bash /path_to_dicp/test/model/run_test_model.sh resnet50 topsgraph false | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.