Skip to content

Commit 2b85b1b

Browse files
committed
Add workflow for torchtune
1 parent cff188a commit 2b85b1b

File tree

2 files changed

+142
-0
lines changed

2 files changed

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

.github/workflows/ascend_npu_test.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,20 @@ jobs:
170170
torch-npu-artifact: ${{ needs.build.outputs.torch-npu-artifact }}
171171
secrets:
172172
pr-token: ${{ secrets.COSDT_BOT_TOKEN }}
173+
174+
torchtune:
175+
name: Run torchtune for torch_npu
176+
needs:
177+
- prepare
178+
- build-torch
179+
- build
180+
if: |
181+
!cancelled() && github.event_name != 'repository_dispatch' &&
182+
(success() || (needs.build-torch.result == 'skipped' && needs.build.result == 'success'))
183+
uses: ./.github/workflows/_ascend_npu_torchtune.yml
184+
with:
185+
runner: ${{ needs.prepare.outputs.runner }}
186+
image: ${{ needs.prepare.outputs.image }}
187+
device: ${{ needs.prepare.outputs.device }}
188+
torch-artifact: ${{ needs.build-torch.outputs.torch-artifact }}
189+
torch-npu-artifact: ${{ needs.build.outputs.torch-npu-artifact }}

0 commit comments

Comments
 (0)