Skip to content

Commit 754139a

Browse files
authored
[Docs] Add user documents for intel AMX. (#828)
Signed-off-by: Duyi-Wang <duyi.wang@intel.com>
1 parent 2888e02 commit 754139a

5 files changed

Lines changed: 127 additions & 0 deletions

File tree

docs/docs_en/AMX.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Intel® AMX
2+
3+
Intel® Advanced Matrix Extensions (Intel® AMX) is the new acclerating technology for Deep Learning, which is supported on the fourth-generation Intel® Xeon® Scalable processor Sappire Rapids [AliCloud g8i specification family](https://help.aliyun.com/document_detail/25378.html#g8i) . It supports two datatypes, BFloat16 and Int8. The details about BFloat16 usage, please refer to [Bfloat16](BFloat16.md).
4+
5+
Intel® Advanced Matrix Extensions (Intel® AMX) is a new 64-bit programming paradigm consisting of two components: a set of 2-dimensional registers (tiles) representing sub-arrays from a larger 2-dimensional memory image and an accelerator able to operate on tiles. The first implementation is called TMUL (tile matrix multiply unit). Below shows the AMX architecture.
6+
7+
![img_1.png](../docs_zh/oneDNN/AMX-Arch.png)
8+
9+
## Requirements and Methods
10+
11+
#### Requirements:
12+
The cloud instance requires to be the fourth-generation Intel® Xeon® Scalable processor Sappire Rapids [AliCloud g8i specification family](https://help.aliyun.com/document_detail/25378.html#g8i). It also requires to use DeepRec which is compiled and optimized by oneDNN in order to provide AMX instruction acceleration, details of which can be found in the oneDNN section. Except for that, there are other software requirements:
13+
- OS or Kernel version: The kernel should be 5.16+. Both of Anolis OS and Ubuntu2204 support AMX.
14+
- Python Version:If python is used, the version should be python3.8+. If C++ is used, then it's fine.
15+
16+
#### Methods:
17+
As the recommendation scenarios are extremely demanding in terms of model accuracy, in order to improve model performance while taking into account model accuracy, AMX BFloat16 can be used in recommendation system. There are two methods to make use of AMX.
18+
19+
##### Enable AMX by the special BFloat16 API(Only for training)
20+
The details are described in [Bfloat16](BFloat16.md) section. The advantage is that, developers can decide which graph will run in BF16 and which graph will keep FP32 in order to meet the accuracy requirement. And the introduced cast overhead can be minimized by operator fusion to achieve the better performance. But if users want to get benefit from AMX more easier, they can try the second method as below.
21+
22+
##### Enable AMX by setting the runtime environment `ONEDNN_DEFAULT_FPMATH_MODE=bf16`(For both training and inference)
23+
The method is supported by the oneDNN library without requiring any code modification from the user. It automatically recognizes matrix multiplication and accelerates computation using the AMX BF16 instruction set. It is very convenient to use, but the performance and precision may be slightly inferior to the first method. The specific effects depend on the actual model.
24+
```
25+
export ONEDNN_DEFAULT_FPMATH_MODE=bf16
26+
```
27+
28+
Besides, users can confirm whether AMX is working by setting the `ONEDNN_VERBOSE` environment variable. If it is working, keywords such as 'AMX' will be printed as output.
29+
```
30+
export ONEDNN_VERBOSE=1
31+
```
32+
## Performance Comparison
33+
34+
The following provides the AMX performance data comparison by using BFloat16 API to freely control the computational graph.
35+
36+
Use models in DeepRec Modelzoo to compare the DeepRec with BF16 and FP32 to see the performance improvement. Models in Modelzoo can enable the BF16 feature by adding `--bf16` parameter.
37+
38+
Use Aliyun ECS cloud server as benchmark machine, Intel 4th Xeon Scalable Processor(Sappire Rapids) specification [AliCloud g8i specification family](https://help.aliyun.com/document_detail/25378.html#g8i)
39+
40+
- Hardware configuration:
41+
- Intel(R) Xeon(R) Platinum 8475B
42+
- CPU(s): 16
43+
- Socket(s): 1
44+
- Core(s) per socket: 8
45+
- Thread(s) per core: 2
46+
- Memory: 64G
47+
48+
49+
- Software configuration:
50+
- kernel: Linux version 5.15.0-58-generic
51+
- OS: Ubuntu 22.04.2 LTS
52+
- GCC: 11.3.0
53+
- Docker: 20.10.21
54+
- Python: 3.8
55+
56+
Performance Result:
57+
58+
| **Throughput** | **WDL** | **MMoE** | **DSSM** |
59+
|----------------|----------|------------|-----------|
60+
| FP32 | 33605.22 | 69538.47 | 102072.3 |
61+
| FP32+BF16 | 85801.28 | 155582 | 209099.7 |
62+
| Speedup | 2.55x | 2.24x | 2.05x |
63+
64+
BF16 has little effect on the AUC metric of model training, more details of the difference can be found in the documentation of each model in the model zoo.
65+

docs/docs_en/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ Arm-Compute-Library
9797
:maxdepth: 2
9898
:caption: Model Quantification
9999
100+
AMX
100101
BFloat16
101102
```
102103

docs/docs_zh/AMX.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Intel® AMX
2+
3+
Intel® Advanced Matrix Extensions (Intel® AMX) 是第四代英特尔® 至强® 可扩展处理器 Sappire Rapids [阿里云通用型实例规格族g8i](https://help.aliyun.com/document_detail/25378.html#g8i) 支持的一种指令集技术,用于加速深度学习的训练和推理,分别支持两种数据类型BFloat16和Int8。有关Bfloat16数据类型的细节和使用方式,请参考[Bfloat16的详细介绍](BFloat16.md)
4+
5+
Intel® AMX是一种新的64位编程范式,由两个组件组成:一组二维寄存器(Tiles)来存储二维矩阵数据,以及一个能够操作这些寄存器的加速器,成为矩阵乘法单元TMUL(Tile Matrix Multiply Unit),每个CPU核心都配有一个AMX加速单元,从而实现对深度学习计算中的矩阵计算和卷积计算等热点进行加速。AMX加速单元的具体架构如下图所示。
6+
7+
![img_1.png](oneDNN/AMX-Arch.png)
8+
9+
## 使用条件与方法
10+
11+
#### 使用条件:
12+
云实例要求第四代英特尔® 至强® 可扩展处理器 Sappire Rapids [阿里云通用型实例规格族g8i](https://help.aliyun.com/document_detail/25378.html#g8i),并且需要采用 oneDNN 编译优化的 DeepRec,才能提供 AMX 指令加速,具体编译可以在 oneDNN 章节了解详情。AMX的使用除了对硬件特殊要求外,软件上也需要满足以下条件。
13+
- OS或者内核版本: 要求内核必须是5.16及以上,阿里云提供的Anolis和Ubuntu2204都是支持的
14+
- Python版本:如果使用的是python API,要求python版本是3.8及以上,否则可能无法启用AMX;如果是C++ API,则没问题
15+
16+
#### 使用方法:
17+
由于推荐场景对模型精度的要求极其严苛,所以为了提升模型性能的同时,兼顾模型精度,用户一般可以使用AMX对BFloat16的加速功能。推荐使用以下两种方式使用AMX.
18+
19+
##### 使用Bfloat16 API自由控制 BF16 计算图(适用于训练场景)
20+
该方法的具体使用步骤请参考[Bfloat16的详细介绍](BFloat16.md)。该方法的好处是,可以由开发者自由地控制哪些图使用BF16,哪些图保持FP32,从而保持较好的模型精度,同时因为默认实现了一些算子融合,避免了一些额外的转换开销,实现较快的运行速度。如果开发者希望更简单地使用AMX,则可以考虑下面这种方式,通过设置环境变量来控制。
21+
##### 通过设置环境变量`ONEDNN_DEFAULT_FPMATH_MODE=bf16`来使用AMX(训练和推理场景均适用)
22+
该方法由oneDNN数据库提供功能支持,不需要用户修改代码,自动识别矩阵乘法,使用AMX的BF16指令集进行计算加速,使用非常便捷,但是性能和精度可能比第一种方法略差一点。具体效果依赖于实际模型。
23+
```
24+
export ONEDNN_DEFAULT_FPMATH_MODE=bf16
25+
```
26+
另外,可以通过打开`ONEDNN_VERBOSE`环境变量来确认AMX是否生效,如果生效,会输出打印AMX等关键字信息。
27+
```
28+
export ONEDNN_VERBOSE=1
29+
```
30+
## 性能对比
31+
32+
以下提供使用BFloat16自由控制计算图的方式来使用AMX进行数据对比。使用 DeepRec Modelzoo 中模型,对比 DeepRec 开启 BF16 后对比 FP32 的性能提升。Modelzoo 中模型通过添加 `--bf16` 参数启用 BF16 特性。
33+
34+
测试机器使用阿里云 ECS 云服务器,Intel Xeon Sappire Rapids CPU,规格为 [ecs.g8i.4xlarge](https://help.aliyun.com/document_detail/25378.html#g8i)
35+
36+
- 硬件配置:
37+
- Intel(R) Xeon(R) Platinum 8475B
38+
- CPU(s): 16
39+
- Socket(s): 1
40+
- Core(s) per socket: 8
41+
- Thread(s) per core: 2
42+
- Memory: 64G
43+
44+
45+
- 软件配置:
46+
- kernel: Linux version 5.15.0-58-generic
47+
- OS: Ubuntu 22.04.2 LTS
48+
- GCC: 11.3.0
49+
- Docker: 20.10.21
50+
- Python: 3.8
51+
52+
性能结果:
53+
| **Throughput** | **WDL** | **MMoE** | **DSSM** |
54+
|----------------|----------|------------|-----------|
55+
| FP32 | 33605.22 | 69538.47 | 102072.3 |
56+
| FP32+BF16 | 85801.28 | 155582 | 209099.7 |
57+
| Speedup | 2.55x | 2.24x | 2.05x |
58+
59+
BF16 对模型训练的 AUC 结果影响很小,具体细节可以从 Modelzoo 中的每个模型的说明文档中找到差异。
60+

docs/docs_zh/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ Arm-Compute-Library
100100
:maxdepth: 2
101101
:caption: 模型量化
102102
103+
AMX
103104
BFloat16
104105
```
105106

docs/docs_zh/oneDNN/AMX-Arch.png

32.4 KB
Loading

0 commit comments

Comments
 (0)