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
+
0 commit comments