Skip to content

Commit 7a6f07a

Browse files
authored
Merge pull request #112 from MooreThreads/fmo-update
update(Version): Update to v2.7.0
2 parents cf09ec6 + 14ed48b commit 7a6f07a

303 files changed

Lines changed: 8518 additions & 9692 deletions

File tree

Some content is hidden

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

‎CMakeLists.txt‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,12 @@ target_compile_definitions(${MUSA_KERNELS_LIB}
380380
target_compile_definitions(${PLUGIN_NAME}
381381
PUBLIC -DREAL_MUSA_VERSION=${REAL_MUSA_VERSION})
382382

383+
set(MUSA_COMP_VERSION "10400")
384+
target_compile_definitions(${MUSA_KERNELS_LIB}
385+
PUBLIC -DMUSA_COMP_VERSION=${MUSA_COMP_VERSION})
386+
target_compile_definitions(${PLUGIN_NAME}
387+
PUBLIC -DMUSA_COMP_VERSION=${MUSA_COMP_VERSION})
388+
383389
add_dependencies(${MUSA_KERNELS_LIB} ${CODEGEN_TARGET})
384390

385391
string(REPLACE ";" " " PYTORCH_MUSA_ARCH_readable "${TORCH_MUSA_ARCH_LIST}")

‎README.md‎

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<!-- toc -->
55

66
- [Overview](#overview)
7-
- [Installation](#installation)
7+
- [Installation](#installation)
88
- [Prerequisites](#prerequisites)
99
- [Docker Image](#docker-image)
1010
- [From Python wheels](#from-python-wheels)
@@ -21,12 +21,14 @@
2121

2222
## Overview
2323

24-
**torch_musa** is an extended Python package based on PyTorch. Combined with PyTorch, users can take advantage of the strong power of Moore Threads graphics cards through **torch_musa**.
24+
**torch_musa** is an extended Python package based on PyTorch. Combined with PyTorch, users can take advantage of the strong power of Moore Threads graphics cards through **torch_musa**.
2525

2626
**torch_musa**'s APIs are consistent with PyTorch in format, which allows users accustomed to PyTorch to migrate smoothly to **torch_musa**, so for the usage users can refer to [PyTorch Official Doc](https://docs.pytorch.org/docs/stable/index.html), all you need is just switch the backend string from "cpu" or "cuda" to "musa".
2727

2828
**torch_musa** also provides a bundle of tools for users to conduct cuda-porting, building musa extension and debugging. Please refer to [README.md](torch_musa/utils/README.md).
2929

30+
For some customize optimizations, like **Dynamic Double Casting** and **Unified Memory Management**, please refer to [README.md](torch_musa/README.md).
31+
3032
If you want to write your layers in C/C++, we provide a convenient extension API that is efficient and with minimal boilerplate. No wrapper code needs to be written. You can see [a ResNet50 example here](torch_musa/examples/cpp/README.md).
3133

3234
--------------------------------------------------------------------------------
@@ -94,21 +96,32 @@ USE_MCCL=0 bash build.sh -c
9496

9597
## MUSA Supported Repositories
9698
We provide some widely used PyTorch environment repositories, which have all adapted with our MUSA platform. Besides, many repositories have supported MUSA backend upstream,
97-
like [Transformers](https://github.com/huggingface/transformers.git), [Accelerate](https://github.com/huggingface/accelerate.git), you can install them with `pip install [repo-name]`.
99+
like [Transformers](https://github.com/huggingface/transformers.git), [Accelerate](https://github.com/huggingface/accelerate.git),
100+
you can install them from PyPi with `pip install [repo-name]`.
98101

99-
### torchvision and torchaudio
100-
PyTorch v2.5.0 needs `torchvision==0.20.0` and `torchaudio==2.5.0`, and for torch_musa users we
101-
shouldn't have them installed like `pip install torchvision==0.20.0`, instead, we should build
102-
them from source:
102+
### torchvision
103+
For torch_musa v2.7.0 and later, install torchvision from our musified one:
104+
```shell
105+
git clone https://github.com/MooreThreads/vision -b v0.22.1-musa --depth 1
106+
cd vision && python setup.py install
107+
```
108+
109+
110+
For torch_musa v2.5.0 and earlier, install torchvision from source with:
103111
```shell
104-
# build & install torchvision
105-
git clone https://github.com/pytorch/vision.git -b v0.20.0 --depth 1
106-
cd visoin && python setup.py install
112+
git clone https://github.com/pytorch/vision -b ${version} --depth 1
113+
cd vision && python setup.py install
114+
```
115+
the `version` is depend on torch version, for example you have torch_musa v2.5.0 with torch v2.5.0, install `torchvision==0.20.0`.
107116

108-
# build & install torchaudio
109-
git clone https://github.com/pytorch/audio.git -b v2.5.0 --depth 1
117+
### torchaudio
118+
Install torchaudio from source:
119+
them from source:
120+
```shell
121+
git clone https://github.com/pytorch/audio.git -b ${version} --depth 1
110122
cd audio && python setup.py install
111123
```
124+
the `version` is same as the torch version.
112125

113126
### Other Repositories
114127
There are many widely used pytorch-related repositories, and we musified some of them and put them into our [GitHub](https://github.com/MooreThreads), here's the list:
@@ -117,6 +130,7 @@ There are many widely used pytorch-related repositories, and we musified some of
117130
| pytorch3d | musa-dev | https://github.com/MooreThreads/pytorch3d | python setup.py install |
118131
| pytorch_sparse | master | https://github.com/MooreThreads/pytorch_sparse | python setup.py install |
119132
| pytorch_scatter | master | https://github.com/MooreThreads/pytorch_scatter | python setup.py install |
133+
| torchvision | v0.22.1-musa | https://github.com/MooreThreads/vision | python setup.py install |
120134
| More to come... | | | |
121135

122136
If users find any question about these repos, please file issues in torch_musa, and if anyone musify a repository, you can
@@ -145,7 +159,7 @@ The following two key changes are required when using **torch_musa**:
145159
```
146160
# ensure torchvision is not installed
147161
pip uninstall torchvision
148-
162+
149163
git clone https://github.com/pytorch/vision.git
150164
cd vision
151165
python setup.py install

‎build.sh‎

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ TORCH_MUSA_HOME=$CUR_DIR
1616
PYTORCH_PATH=${PYTORCH_REPO_PATH:-$(realpath ${TORCH_MUSA_HOME}/../pytorch)}
1717
TORCH_PATCHES_DIR=${TORCH_MUSA_HOME}/torch_patches/
1818
KINETO_URL=${KINETO_URL:-https://github.com/MooreThreads/kineto.git}
19-
KINETO_TAG=v2.0.1
19+
KINETO_TAG=v2.7.0
2020

2121
BUILD_WHEEL=0
2222
DEBUG_MODE=0
@@ -27,7 +27,7 @@ USE_KINETO=${USE_KINETO:-1}
2727
ONLY_PATCH=0
2828
CLEAN=0
2929
COMPILE_FP64=1
30-
PYTORCH_TAG=v2.5.0
30+
PYTORCH_TAG=v2.7.1
3131
PYTORCH_BUILD_VERSION="${PYTORCH_TAG:1}"
3232
PYTORCH_BUILD_NUMBER=0 # This is used for official torch distribution.
3333
USE_MCCL=${USE_MCCL:-1}
@@ -119,7 +119,7 @@ done
119119

120120
cmd_check(){
121121
cmd="$1"
122-
if command -v ${cmd} >/dev/null 2>&1; then
122+
if command -v ${cmd} >/dev/null 2>&1; then
123123
echo "- cmd exist : ${cmd}"
124124
else
125125
echo -e "\033[34m- cmd does not exist, automatically install \"${cmd}\"\033[0m"
@@ -132,7 +132,7 @@ precommit_install(){
132132
root_dir="$(dirname "$(realpath "${BASH_SOURCE:-$0}" )")"
133133
if [ ! -f ${root_dir}/.git/hooks/pre-commit ]; then
134134
pushd $root_dir
135-
pre-commit install
135+
pre-commit install
136136
popd
137137
fi
138138
}
@@ -174,7 +174,7 @@ apply_torch_patches() {
174174
popd
175175
fi
176176

177-
for file in $(find ${TORCH_PATCHES_DIR} -type f -print); do
177+
for file in $(find ${TORCH_PATCHES_DIR} -type f -not -path "*/kineto/*" -print); do
178178
if [ "${file##*.}"x = "patch"x ]; then
179179
echo -e "\033[34mapplying patch: $file \033[0m"
180180
pushd $PYTORCH_PATH
@@ -183,13 +183,27 @@ apply_torch_patches() {
183183
popd
184184
fi
185185
done
186+
187+
if [ ${USE_KINETO} -eq 1 ]; then
188+
for file in $(find ${TORCH_PATCHES_DIR}/kineto -type f -print); do
189+
if [ "${file##*.}"x = "patch"x ]; then
190+
echo -e "\033[34mapplying patch: $file \033[0m"
191+
pushd $PYTORCH_PATH
192+
git apply --check $file
193+
git apply $file
194+
popd
195+
fi
196+
done
197+
fi
186198
}
187199

188200
update_kineto_source() {
189201
echo -e "\033[34mUpdating Kineto...\033[0m"
190202
pushd ${PYTORCH_PATH}
203+
# remove the current kineto
191204
rm -rf ${PYTORCH_PATH}/third_party/kineto
192205
git submodule update --init --recursive --depth 1
206+
# remove the official kineto
193207
rm -rf ${PYTORCH_PATH}/third_party/kineto
194208
popd
195209
echo -e "\033[34mUpdating KINETO_URL, might take a while...\033[0m"
@@ -230,7 +244,7 @@ update_submodule() {
230244
pushd ${PYTORCH_PATH}
231245
git submodule update --init --recursive --depth 1
232246
popd
233-
elif [ "${remote_url}" = "${KINETO_URL}" ] && [ "${current_tag}" = "${KINETO_TAG}" ]; then
247+
elif [ "${remote_url}" = "${KINETO_URL}" ]; then
234248
pushd ${PYTORCH_PATH}/third_party/kineto
235249
echo -e "\033[34mUpdating KINETO submodule, might take a while...\033[0m"
236250
git submodule update --init --recursive
@@ -244,6 +258,13 @@ update_submodule() {
244258
popd
245259
rm -rf ${PYTORCH_PATH}/third_party/kineto
246260
mv /tmp/kineto ${PYTORCH_PATH}/third_party
261+
if [ "${current_tag}" != "${KINETO_TAG}" ]; then
262+
echo -e "\033[34mUpdate the kineto to the [${KINETO_TAG}]\033[0m"
263+
pushd ${PYTORCH_PATH}/third_party/kineto
264+
git fetch origin tag ${KINETO_TAG}
265+
git checkout ${KINETO_TAG}
266+
popd
267+
fi
247268
else
248269
update_kineto_source
249270
fi

‎cmake/utils.cmake‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,28 @@ endfunction()
3434

3535
function(parse_real_musa_version outputvar)
3636
find_program(
37-
MUSA_TOOLKIT_VERSION_EXECUTABLE
38-
NAMES musa_toolkits_version
37+
MUSA_RUNTIME_VERSION_EXECUTABLE
38+
NAMES musa_runtime_version
3939
PATHS "$ENV{MUSA_HOME}"
4040
PATH_SUFFIXES bin bin64
4141
NO_DEFAULT_PATH)
42-
mark_as_advanced(MUSA_TOOLKIT_VERSION_EXECUTABLE)
43-
if(MUSA_TOOLKIT_VERSION_EXECUTABLE)
44-
execute_process(COMMAND ${MUSA_TOOLKIT_VERSION_EXECUTABLE}
45-
OUTPUT_VARIABLE MUSA_TOOLKITS_VERSION)
42+
mark_as_advanced(MUSA_RUNTIME_VERSION_EXECUTABLE)
43+
if(MUSA_RUNTIME_VERSION_EXECUTABLE)
44+
execute_process(COMMAND ${MUSA_RUNTIME_VERSION_EXECUTABLE}
45+
OUTPUT_VARIABLE MUSA_RUNTIME_VERSION)
4646
string(REGEX REPLACE ".*\"([0-9]+)\\.([0-9]+)\\.([0-9]+)\".*" "\\1"
47-
MUSA_TOOLKITS_VERSION_MAJOR ${MUSA_TOOLKITS_VERSION})
47+
MUSA_RUNTIME_VERSION_MAJOR ${MUSA_RUNTIME_VERSION})
4848
string(REGEX REPLACE ".*\"([0-9]+)\\.([0-9]+)\\.([0-9]+)\".*" "\\2"
49-
MUSA_TOOLKITS_VERSION_MINOR ${MUSA_TOOLKITS_VERSION})
49+
MUSA_RUNTIME_VERSION_MINOR ${MUSA_RUNTIME_VERSION})
5050
string(REGEX REPLACE ".*\"([0-9]+)\\.([0-9]+)\\.([0-9]+)\".*" "\\3"
51-
MUSA_TOOLKITS_VERSION_PATCH ${MUSA_TOOLKITS_VERSION})
51+
MUSA_RUNTIME_VERSION_PATCH ${MUSA_RUNTIME_VERSION})
5252

5353
math(
5454
EXPR
55-
MUSA_TOOLKITS_VERSION_INT
56-
"${MUSA_TOOLKITS_VERSION_MAJOR} * 1000 + ${MUSA_TOOLKITS_VERSION_MINOR} * 10 + ${MUSA_TOOLKITS_VERSION_PATCH}"
55+
MUSA_RUNTIME_VERSION_INT
56+
"${MUSA_RUNTIME_VERSION_MAJOR} * 1000 + ${MUSA_RUNTIME_VERSION_MINOR} * 10 + ${MUSA_RUNTIME_VERSION_PATCH}"
5757
)
58-
set(${outputvar} "${MUSA_TOOLKITS_VERSION_INT}" PARENT_SCOPE)
58+
set(${outputvar} "${MUSA_RUNTIME_VERSION_INT}" PARENT_SCOPE)
5959
mark_as_advanced(${outputvar})
6060
endif()
6161
endfunction()

‎docs/markdown/README.md‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# torch_musa开发者文档
2+
3+
中文版的开发者文档,请参考:
4+
5+
[前言](source/01_foreword.md)
6+
7+
[简介](source/02_introduction.md)
8+
9+
[torch_musa安装和编译](source/03_compile_and_install.md)
10+
11+
[torch_musa快速入门](source/04_quick_start.md)
12+
13+
[torch_musa算法开发](source/05_ops_dev.md)
14+
15+
[torch_musa第三方扩展支持](source/06_third_party_lib_extension.md)
16+
17+
[torch_musa性能优化](source/07_optimization.md)
18+
19+
[torch_musa调试工具](source/08_debug.md)
20+
21+
[YOLOv5迁移案例](source/09_YOLO_transfer.md)
22+
23+
[FAQ](source/10_FAQ.md)
24+
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
title: 前言
3+
description: torch_musa 前言
4+
hide_table_of_contents: False
5+
---
6+
7+
# 前言
8+
9+
## 版本记录
10+
11+
| 文档名称 | 摩尔线程 Torch_MUSA 开发者手册 |
12+
| ---- | --------------------- |
13+
| 版本号 | V 1.3.0 |
14+
| 作者 | Moore Threads |
15+
| 修改日期 | 2024年11月18日 |
16+
17+
## 更新历史
18+
19+
- **V0.1.0**
20+
21+
**更新时间**:2023.05.29
22+
23+
**更新内容**:
24+
25+
- 完成初版 Torch_MUSA 开发者手册。
26+
27+
- **V1.1.0**
28+
29+
**更新时间**:2024.03.31
30+
31+
**更新内容**:
32+
33+
- 增加调试工具章节。
34+
35+
- 增加 MUSAExtension 章节。
36+
37+
- 增加性能分析章节。
38+
39+
- 快速入门章节增加更多示例代码。
40+
41+
- 完善 FAQ 章节。
42+
43+
- 增加经典模型 YOLOv5 迁移示例章节。
44+
45+
- **V1.2.0**
46+
47+
**更新时间**:2024.07.28
48+
49+
**更新内容**:
50+
51+
- 完善 MUSAExtension 章节。
52+
53+
- 增加算子适配说明,支持更多算子适配的方法。
54+
55+
- **V1.3.0**
56+
57+
**更新时间**:2024.11.18
58+
59+
**更新内容**:
60+
61+
- 版本升级
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
title: 简介
3+
description: torch_musa 简介
4+
hide_table_of_contents: False
5+
---
6+
7+
# 简介
8+
9+
## MUSA概述
10+
11+
MUSA (Metaverse Unified System Architecture) 是摩尔线程公司为摩尔线程GPU推出的一种通用并行计算平台和编程模型。它提供了GPU编程的简易接口,用MUSA编程可以构建基于GPU计算的应用程序,利用GPUs的并行计算引擎来更加高效地解决比较复杂的计算难题。同时摩尔线程还推出了MUSA工具箱(MUSAToolkits),工具箱中包括GPU加速库,运行时库,编译器,调试和优化工具等。MUSAToolkits为开发人员在摩尔线程GPU上开发和部署高性能异构计算程序提供软件环境。
12+
13+
关于MUSA软件栈的更多内容,请参见MUSA官方文档。
14+
15+
## PyTorch概述
16+
17+
PyTorch是一款开源的深度学习编程框架,可以用于计算机视觉,自然语言处理,语音处理等领域。PyTorch使用动态计算,这在构建复杂架构时提供了更大的灵活性。PyTorch使用核心Python概念,如类、结构和条件循环,因此理解起来更直观,编程更容易。此外,PyTorch还具有可以轻松扩展、快速实现、生产部署稳定性强等优点。
18+
19+
关于PyTorch的更多内容,请参见PyTorch官方文档。
20+
21+
## torch_musa概述
22+
23+
为了摩尔线程GPU能支持开源框架PyTorch,摩尔线程公司开发了torch_musa。在PyTorch v2.0.0基础上,torch_musa以插件的形式来支持摩尔线程GPU,最大程度与PyTorch代码解耦,便于代码维护与升级。torch_musa利用PyTorch提供的第三方后端扩展接口,将摩尔线程高性能计算库动态注册到PyTorch上,从而使得PyTorch框架能够利用摩尔线程显卡的高性能计算单元。利用摩尔线程显卡CUDA兼容的特性,torch_musa内部引入了cuda兼容模块,使得PyTorch社区的CUDA kernels经过porting后就可以运行在摩尔线程显卡上,而且CUDA Porting的工作是在编译torch_musa的过程中自动进行,这大幅降低了torch_musa算子适配的成本,提高模型开发效率。同时,torch_musa在Python前端接口与PyTorch社区CUDA接口形式上基本保持一致,这极大地降低了用户的学习成本和模型的迁移成本。
24+
25+
本手册主要介绍了基于MUSA软件栈的torch_musa开发指南。
26+
27+
## torch_musa核心代码目录概述
28+
29+
- torch_musa/tests 测试文件。
30+
- torch_musa/core 主要包含Python module,提供amp/device/memory/stream/event等模块的Python前端接口。
31+
- torch_musa/csrc c++侧实现代码;
32+
- csrc/amp 提供混合精度模块的C++实现。
33+
- csrc/aten 提供C++ Tensor库,包括MUDNN算子适配,CUDA-Porting算子适配等等。
34+
- csrc/core 提供核心功能库,包括设备管理,内存分配管理,Stream管理,Events管理等。
35+
- csrc/distributed 提供分布式模块的C++实现。

0 commit comments

Comments
 (0)