forked from flashinfer-ai/flashinfer
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJenkinsfile
More file actions
351 lines (323 loc) · 12.2 KB
/
Jenkinsfile
File metadata and controls
351 lines (323 loc) · 12.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
// Jenkins pipeline
// See documents at https://jenkins.io/doc/book/pipeline/jenkinsfile/
// Docker env used for testing
// Different image may have different version tag
// because some of them are more stable than anoter.
//
// Docker images are maintained by PMC, cached in dockerhub
// and remains relatively stable over the time.
// Flow for upgrading docker env(need commiter)
//
// - Send PR to upgrade build script in the repo
// - Build the new docker image
// - Tag the docker image with a new version and push to a binary cache.
// - Update the version in the Jenkinsfile, send a PR
// - Fix any issues wrt to the new image version in the PR
// - Merge the PR and now we are in new version
// - Tag the new version as the lates
// - Periodically cleanup the old versions on local workers
//
import org.jenkinsci.plugins.pipeline.modeldefinition.Utils
def getDockerRun(cuda_version, dockerTags) {
def image_name = "flashinfer/flashinfer-ci-${cuda_version}"
return "bash ci/bash.sh ${image_name}:${dockerTags[image_name]}"
}
def per_exec_ws(folder) {
return "workspace/exec_${env.EXECUTOR_NUMBER}/" + folder
}
def pack_lib(name, libs) {
sh """
echo "Packing ${libs} into ${name}"
echo ${libs} | sed -e 's/,/ /g' | xargs md5sum
"""
stash includes: libs, name: name
}
def unpack_lib(name, libs) {
unstash name
sh """
echo "Unpacked ${libs} from ${name}"
echo ${libs} | sed -e 's/,/ /g' | xargs md5sum
"""
}
def should_skip_build() {
// Skip build if changes are only in documentation/config directories
def skip_patterns = [
'README.md',
'.github/',
'docs/',
'docker/',
'licenses/',
'LICENSE',
'NOTICE',
'version.txt'
]
if (env.CHANGE_ID) {
// This is a PR build, check changed files
def changedFiles = []
try {
changedFiles = sh(
script: 'git diff --name-only origin/${CHANGE_TARGET}...HEAD',
returnStdout: true
).trim().split('\n')
} catch (Exception e) {
echo "Could not determine changed files: ${e.toString()}"
return false
}
if (changedFiles.size() == 0) {
return false
}
// Check if all changed files match skip patterns
def allSkippable = changedFiles.every { file ->
skip_patterns.any { pattern ->
if (pattern.endsWith('/')) {
file.startsWith(pattern)
} else {
file == pattern
}
}
}
if (allSkippable) {
echo "Skipping build - all changes are in documentation/config files: ${changedFiles}"
return true
}
}
return false
}
def cancel_previous_build() {
// cancel previous build if it is not on main.
if (env.BRANCH_NAME != 'main') {
def buildNumber = env.BUILD_NUMBER as int
// Milestone API allows us to cancel previous build
// with the same milestone number
if (buildNumber > 1) milestone(buildNumber - 1)
milestone(buildNumber)
}
}
def is_last_build() {
// check whether it is last build
try {
return currentBuild.number == currentBuild.rawBuild.project.getLastBuild().number
} catch (Throwable ex) {
echo 'Error during check is_last_build ' + ex.toString()
return false
}
}
def init_git(submodule = false) {
cleanWs()
// add retry in case checkout timeouts
retry(5) {
checkout scm
}
if (submodule) {
retry(5) {
timeout(time: 10, unit: 'MINUTES') {
sh(script: 'git submodule update --init --recursive -f', label: 'Update git submodules')
}
}
}
}
def run_with_spot_retry(spot_node_type, on_demand_node_type, test_name, test_closure) {
try {
test_closure(spot_node_type)
} catch (hudson.AbortException abortEx) {
echo "Received normal AbortException, exit now: " + abortEx.toString()
throw abortEx
} catch (Throwable ex) {
echo "Exception during SPOT run for ${test_name}: " + ex.toString()
if (is_last_build()) {
echo "Exception during SPOT run for ${test_name}: " + ex.toString() + " retry on-demand"
currentBuild.result = 'SUCCESS'
test_closure(on_demand_node_type)
} else {
echo 'Exit since it is not last build'
throw ex
}
}
}
// stage('Lint') {
// node('CPU-SPOT') {
// ws(per_exec_ws('flashinfer-lint')) {
// init_git(false)
// }
// }
// }
def run_unittest_CPU_JIT_CACHE_PACKAGE_BUILD_IMPORT(node_type, cuda_version) {
echo "Running CPU JIT Cache Package Build and Import Unittest with CUDA ${cuda_version}"
if (node_type.contains('SPOT')) {
// Add timeout only for spot instances - node allocation only
def node_allocated = false
try {
timeout(time: 15, unit: 'MINUTES') {
// Only timeout the node allocation, not the test execution
node(node_type) {
node_allocated = true
// Just mark that we got the node, don't run tests here
}
}
// If we reach here, node allocation was successful
// Now run the tests without any timeout
node(node_type) {
ws(per_exec_ws('flashinfer-jit-cache')) {
init_git(true)
def dockerTags = readYaml file: 'ci/docker-tags.yml'
def docker_run = getDockerRun(cuda_version, dockerTags)
sh(script: "ls -alh", label: 'Show work directory')
sh(script: "./scripts/task_show_node_info.sh", label: 'Show node info')
sh(script: "${docker_run} --no-gpu ./scripts/task_test_jit_cache_package_build_import.sh", label: 'Test JIT Cache Package Build and Import')
}
}
} catch (Exception e) {
if (!node_allocated) {
echo "Node allocation timeout or failure after 15 minutes for ${node_type}: ${e.toString()}"
}
throw e
}
} else {
// No timeout for non-spot instances
node(node_type) {
ws(per_exec_ws('flashinfer-jit-cache')) {
init_git(true)
def dockerTags = readYaml file: 'ci/docker-tags.yml'
def docker_run = getDockerRun(cuda_version, dockerTags)
sh(script: "ls -alh", label: 'Show work directory')
sh(script: "./scripts/task_show_node_info.sh", label: 'Show node info')
sh(script: "${docker_run} --no-gpu ./scripts/task_test_jit_cache_package_build_import.sh", label: 'Test JIT Cache Package Build and Import')
}
}
}
}
def shard_run_unittest_GPU(node_type, shard_id, cuda_version) {
echo "Running unittest on ${node_type}, shard ${shard_id}, CUDA ${cuda_version}"
if (node_type.contains('SPOT')) {
// Add timeout only for spot instances - node allocation only
def node_allocated = false
try {
timeout(time: 15, unit: 'MINUTES') {
// Only timeout the node allocation, not the test execution
node(node_type) {
node_allocated = true
// Just mark that we got the node, don't run tests here
}
}
// If we reach here, node allocation was successful
// Now run the tests without any timeout
node(node_type) {
ws(per_exec_ws('flashinfer-unittest')) {
init_git(true) // we need cutlass submodule
def dockerTags = readYaml file: 'ci/docker-tags.yml'
def docker_run = getDockerRun(cuda_version, dockerTags)
sh(script: "ls -alh", label: 'Show work directory')
sh(script: "./scripts/task_show_node_info.sh", label: 'Show node info')
sh(script: "${docker_run} ./scripts/task_jit_run_tests_part${shard_id}.sh", label: 'JIT Unittest Part ${shard_id}')
}
}
} catch (Exception e) {
if (!node_allocated) {
echo "Node allocation timeout or failure after 15 minutes for ${node_type}: ${e.toString()}"
}
throw e
}
} else {
// No timeout for non-spot instances
node(node_type) {
ws(per_exec_ws('flashinfer-unittest')) {
init_git(true) // we need cutlass submodule
def dockerTags = readYaml file: 'ci/docker-tags.yml'
def docker_run = getDockerRun(cuda_version, dockerTags)
sh(script: "ls -alh", label: 'Show work directory')
sh(script: "./scripts/task_show_node_info.sh", label: 'Show node info')
sh(script: "${docker_run} ./scripts/task_jit_run_tests_part${shard_id}.sh", label: 'JIT Unittest Part ${shard_id}')
}
}
}
}
stage('Unittest') {
if (should_skip_build()) {
echo "Skipping tests - only documentation/config files changed"
Utils.markStageSkippedForConditional('Unittest')
return
}
cancel_previous_build()
parallel(
failFast: true,
// CUDA 12.6 AOT Tests
'AOT-Build-Import-x86-64-cu126': {
run_with_spot_retry('CPU-LARGE-SPOT', 'CPU-LARGE', 'AOT-Build-Import-x86-64-cu126',
{ node_type -> run_unittest_CPU_JIT_CACHE_PACKAGE_BUILD_IMPORT(node_type, 'cu126') })
},
'AOT-Build-Import-aarch64-cu126': {
run_with_spot_retry('ARM-LARGE-SPOT', 'ARM-LARGE', 'AOT-Build-Import-aarch64-cu126',
{ node_type -> run_unittest_CPU_JIT_CACHE_PACKAGE_BUILD_IMPORT(node_type, 'cu126') })
},
// CUDA 12.8 AOT Tests
'AOT-Build-Import-x86-64-cu128': {
run_with_spot_retry('CPU-LARGE-SPOT', 'CPU-LARGE', 'AOT-Build-Import-x86-64-cu128',
{ node_type -> run_unittest_CPU_JIT_CACHE_PACKAGE_BUILD_IMPORT(node_type, 'cu128') })
},
'AOT-Build-Import-aarch64-cu128': {
run_with_spot_retry('ARM-LARGE-SPOT', 'ARM-LARGE', 'AOT-Build-Import-aarch64-cu128',
{ node_type -> run_unittest_CPU_JIT_CACHE_PACKAGE_BUILD_IMPORT(node_type, 'cu128') })
},
// CUDA 12.9 AOT Tests
'AOT-Build-Import-x86-64-cu129': {
run_with_spot_retry('CPU-LARGE-SPOT', 'CPU-LARGE', 'AOT-Build-Import-x86-64-cu129',
{ node_type -> run_unittest_CPU_JIT_CACHE_PACKAGE_BUILD_IMPORT(node_type, 'cu129') })
},
'AOT-Build-Import-aarch64-cu129': {
run_with_spot_retry('ARM-LARGE-SPOT', 'ARM-LARGE', 'AOT-Build-Import-aarch64-cu129',
{ node_type -> run_unittest_CPU_JIT_CACHE_PACKAGE_BUILD_IMPORT(node_type, 'cu129') })
},
// CUDA 13.0 AOT Tests
'AOT-Build-Import-x86-64-cu130': {
run_with_spot_retry('CPU-LARGE-SPOT', 'CPU-LARGE', 'AOT-Build-Import-x86-64-cu130',
{ node_type -> run_unittest_CPU_JIT_CACHE_PACKAGE_BUILD_IMPORT(node_type, 'cu130') })
},
'AOT-Build-Import-aarch64-cu130': {
run_with_spot_retry('ARM-LARGE-SPOT', 'ARM-LARGE', 'AOT-Build-Import-aarch64-cu130',
{ node_type -> run_unittest_CPU_JIT_CACHE_PACKAGE_BUILD_IMPORT(node_type, 'cu130') })
},
// JIT unittest only for cu129
'JIT-Unittest-1-cu129': {
run_with_spot_retry('GPU-G5-SPOT', 'GPU-G5', 'JIT-Unittest-1-cu129',
{ node_type -> shard_run_unittest_GPU(node_type, 1, 'cu129') })
},
'JIT-Unittest-2-cu129': {
run_with_spot_retry('GPU-G5-SPOT', 'GPU-G5', 'JIT-Unittest-2-cu129',
{ node_type -> shard_run_unittest_GPU(node_type, 2, 'cu129') })
},
'JIT-Unittest-3-cu129': {
run_with_spot_retry('GPU-G5-SPOT', 'GPU-G5', 'JIT-Unittest-3-cu129',
{ node_type -> shard_run_unittest_GPU(node_type, 3, 'cu129') })
},
'JIT-Unittest-4-cu129': {
run_with_spot_retry('GPU-G5-SPOT', 'GPU-G5', 'JIT-Unittest-4-cu129',
{ node_type -> shard_run_unittest_GPU(node_type, 4, 'cu129') })
},
'JIT-Unittest-5-cu129': {
run_with_spot_retry('GPU-G5-SPOT', 'GPU-G5', 'JIT-Unittest-5-cu129',
{ node_type -> shard_run_unittest_GPU(node_type, 5, 'cu129') })
},
// JIT unit test for CUDA 12.9 with SM75 (AWS G4)
// For now, we only enable sampling test for SM75
'JIT-Unittest-G4-cu129': {
run_with_spot_retry('GPU-G4-SPOT', 'GPU-G4', 'JIT-Unittest-G4-cu129',
{ node_type -> shard_run_unittest_GPU(node_type, 3, 'cu129') })
},
)
}