Skip to content

Commit 58bff92

Browse files
committed
Add workflows for torchtune X Ascend
1 parent 752c495 commit 58bff92

File tree

2 files changed

+145
-0
lines changed

2 files changed

+145
-0
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
name: "_ascend_npu_torchtune"
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
runner:
7+
required: true
8+
type: string
9+
description: "The runner selected to run on"
10+
image:
11+
required: true
12+
type: string
13+
description: "The docker image which will be loaded"
14+
torch-artifact:
15+
required: false
16+
type: string
17+
description: "The distribution artifact name of torch"
18+
torch-npu-artifact:
19+
required: true
20+
type: string
21+
description: "The distribution artifact name of torch_npu"
22+
secrets:
23+
hf-token:
24+
required: true
25+
description: "The Hugging Face token for downloading models"
26+
27+
jobs:
28+
torchtune:
29+
name: run torchtune for torch_npu
30+
runs-on: ${{ inputs.runner }}
31+
container:
32+
image: ${{ inputs.image }}
33+
env:
34+
HF_ENDPOINT: https://hf-mirror.com
35+
36+
steps:
37+
- name: Show NPU info
38+
run: |
39+
npu-smi info
40+
41+
- name: Config mirrors
42+
run: |
43+
sed -i 's|ports.ubuntu.com|mirrors.tuna.tsinghua.edu.cn|g' /etc/apt/sources.list
44+
pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
45+
46+
- name: Install system dependencies
47+
run: |
48+
apt-get update
49+
apt-get install -y \
50+
git gcc g++ make cmake ninja-build curl \
51+
libgl1 libglib2.0-0 libsndfile1
52+
53+
# See: https://github.com/actions/checkout/issues/363#issuecomment-1915075699
54+
# See: https://github.com/hunshcn/gh-proxy/issues/28#issuecomment-773769630
55+
- name: Config git
56+
run: |
57+
git config --global --add safe.directory "$GITHUB_WORKSPACE"
58+
git config --global url."https://gh-proxy.test.osinfra.cn/https://github.com/".insteadOf https://github.com/
59+
60+
- name: Checkout
61+
uses: actions/checkout@v4
62+
63+
- name: Checkout torchtune
64+
uses: actions/checkout@v4
65+
with:
66+
repository: pytorch/torchtune
67+
path: torchtune
68+
69+
- name: Install torchtune
70+
working-directory: torchtune
71+
run: |
72+
pip install -e .
73+
74+
- name: Download torch artifact
75+
if: ${{ inputs.torch-artifact }}
76+
uses: actions/download-artifact@v4
77+
with:
78+
name: ${{ inputs.torch-artifact }}
79+
80+
- name: Install torch
81+
if: ${{ inputs.torch-artifact }}
82+
run: |
83+
pip install ${{ inputs.torch-artifact }}
84+
85+
- name: Install torch_npu dependencies
86+
if: ${{ !inputs.torch-artifact }}
87+
run: |
88+
pip install -r https://raw.githubusercontent.com/Ascend/pytorch/refs/heads/master/requirements.txt
89+
90+
- name: List torch version
91+
id: list-torch-version
92+
shell: bash
93+
run: |
94+
torch_version=$(python -c "import torch; print(torch.__version__)")
95+
echo "torch-version=${torch_version}" >> $GITHUB_OUTPUT
96+
97+
- name: Download torch_npu artifact
98+
uses: actions/download-artifact@v4
99+
with:
100+
name: ${{ inputs.torch-npu-artifact }}
101+
path: ascend_npu
102+
103+
- name: Install torch_npu
104+
working-directory: ascend_npu
105+
run: |
106+
pip install ${{ inputs.torch-npu-artifact }}
107+
108+
- name: Show environment info
109+
run: |
110+
pip list
111+
112+
- name: Download Qwen2.5 model
113+
env:
114+
HF_ENDPOINT: https://hf-mirror.com
115+
hf-token: ${{ secrets.hf-token }}
116+
run: |
117+
huggingface-cli download Qwen/Qwen2.5-0.5B-Instruct \
118+
--local-dir /tmp/Qwen2.5-0.5B-Instruct \
119+
--token hf-token
120+
121+
- name: Run torchtune with lora finetune
122+
run: |
123+
tune run lora_finetune_single_device --config qwen2_5/0.5B_lora_single_device
124+
125+
- name: Run torchtune with full finetune
126+
run: |
127+
tune run full_finetune_single_device --config qwen2_5/0.5B_full_single_device

.github/workflows/ascend_npu_test.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,21 @@ jobs:
150150
# torch-npu-artifact: ${{ needs.build.outputs.torch-npu-artifact }}
151151
# secrets:
152152
# pr-token: ${{ secrets.ASCEND_RUNNER_TOKEN }}
153+
154+
torchtune:
155+
name: Run benchmarks
156+
needs:
157+
- prepare
158+
- build-torch
159+
- build
160+
if: |
161+
!cancelled() && github.event_name != 'repository_dispatch' &&
162+
(success() || (needs.build-torch.result == 'skipped' && needs.build.result == 'success'))
163+
uses: ./.github/workflows/_ascend_npu_torchtune.yml
164+
with:
165+
runner: ${{ needs.prepare.outputs.runner }}
166+
image: ${{ needs.prepare.outputs.image }}
167+
torch-artifact: ${{ needs.build-torch.outputs.torch-artifact }}
168+
torch-npu-artifact: ${{ needs.build.outputs.torch-npu-artifact }}
169+
secrets:
170+
hf-token: ${{ secrets.HF_TOKEN }}

0 commit comments

Comments
 (0)