14
14
https://github.com/pytorch/vision/pull/1321#issuecomment-531033978
15
15
"""
16
16
17
+ import os .path
18
+
17
19
import jinja2
18
- from jinja2 import select_autoescape
19
20
import yaml
20
- import os . path
21
+ from jinja2 import select_autoescape
21
22
22
23
23
24
PYTHON_VERSIONS = ["3.6" , "3.7" , "3.8" , "3.9" ]
24
25
25
26
RC_PATTERN = r"/v[0-9]+(\.[0-9]+)*-rc[0-9]+/"
26
27
27
28
28
- def build_workflows (prefix = '' , filter_branch = None , upload = False , indentation = 6 , windows_latest_only = False ):
29
+ def build_workflows (prefix = "" , filter_branch = None , upload = False , indentation = 6 , windows_latest_only = False ):
29
30
w = []
30
31
for btype in ["wheel" , "conda" ]:
31
32
for os_type in ["linux" , "macos" , "win" ]:
32
33
python_versions = PYTHON_VERSIONS
33
- cu_versions_dict = {"linux" : ["cpu" , "cu102" , "cu111" , "cu113" , "rocm4.1" , "rocm4.2" ],
34
- "win" : ["cpu" , "cu102" , "cu111" , "cu113" ],
35
- "macos" : ["cpu" ]}
34
+ cu_versions_dict = {
35
+ "linux" : ["cpu" , "cu102" , "cu111" , "cu113" , "rocm4.1" , "rocm4.2" ],
36
+ "win" : ["cpu" , "cu102" , "cu111" , "cu113" ],
37
+ "macos" : ["cpu" ],
38
+ }
36
39
cu_versions = cu_versions_dict [os_type ]
37
40
for python_version in python_versions :
38
41
for cu_version in cu_versions :
39
42
# ROCm conda packages not yet supported
40
- if cu_version .startswith (' rocm' ) and btype == "conda" :
43
+ if cu_version .startswith (" rocm" ) and btype == "conda" :
41
44
continue
42
45
for unicode in [False ]:
43
46
fb = filter_branch
44
- if windows_latest_only and os_type == "win" and filter_branch is None and \
45
- (python_version != python_versions [- 1 ] or
46
- (cu_version not in [cu_versions [0 ], cu_versions [- 1 ]])):
47
+ if (
48
+ windows_latest_only
49
+ and os_type == "win"
50
+ and filter_branch is None
51
+ and (
52
+ python_version != python_versions [- 1 ]
53
+ or (cu_version not in [cu_versions [0 ], cu_versions [- 1 ]])
54
+ )
55
+ ):
47
56
fb = "main"
48
- if not fb and (os_type == 'linux' and
49
- cu_version == 'cpu' and
50
- btype == 'wheel' and
51
- python_version == '3.7' ):
57
+ if not fb and (
58
+ os_type == "linux" and cu_version == "cpu" and btype == "wheel" and python_version == "3.7"
59
+ ):
52
60
# the fields must match the build_docs "requires" dependency
53
61
fb = "/.*/"
54
62
w += workflow_pair (
55
- btype , os_type , python_version , cu_version ,
56
- unicode , prefix , upload , filter_branch = fb )
63
+ btype , os_type , python_version , cu_version , unicode , prefix , upload , filter_branch = fb
64
+ )
57
65
58
66
if not filter_branch :
59
67
# Build on every pull request, but upload only on nightly and tags
60
- w += build_doc_job (' /.*/' )
61
- w += upload_doc_job (' nightly' )
68
+ w += build_doc_job (" /.*/" )
69
+ w += upload_doc_job (" nightly" )
62
70
return indent (indentation , w )
63
71
64
72
65
- def workflow_pair (btype , os_type , python_version , cu_version , unicode , prefix = '' , upload = False , * , filter_branch = None ):
73
+ def workflow_pair (btype , os_type , python_version , cu_version , unicode , prefix = "" , upload = False , * , filter_branch = None ):
66
74
67
75
w = []
68
76
unicode_suffix = "u" if unicode else ""
69
77
base_workflow_name = f"{ prefix } binary_{ os_type } _{ btype } _py{ python_version } { unicode_suffix } _{ cu_version } "
70
78
71
- w .append (generate_base_workflow (
72
- base_workflow_name , python_version , cu_version ,
73
- unicode , os_type , btype , filter_branch = filter_branch ))
79
+ w .append (
80
+ generate_base_workflow (
81
+ base_workflow_name , python_version , cu_version , unicode , os_type , btype , filter_branch = filter_branch
82
+ )
83
+ )
74
84
75
85
if upload :
76
86
w .append (generate_upload_workflow (base_workflow_name , os_type , btype , cu_version , filter_branch = filter_branch ))
77
- if filter_branch == ' nightly' and os_type in [' linux' , ' win' ]:
78
- pydistro = ' pip' if btype == ' wheel' else ' conda'
87
+ if filter_branch == " nightly" and os_type in [" linux" , " win" ]:
88
+ pydistro = " pip" if btype == " wheel" else " conda"
79
89
w .append (generate_smoketest_workflow (pydistro , base_workflow_name , filter_branch , python_version , os_type ))
80
90
81
91
return w
@@ -85,12 +95,13 @@ def build_doc_job(filter_branch):
85
95
job = {
86
96
"name" : "build_docs" ,
87
97
"python_version" : "3.7" ,
88
- "requires" : ["binary_linux_wheel_py3.7_cpu" , ],
98
+ "requires" : [
99
+ "binary_linux_wheel_py3.7_cpu" ,
100
+ ],
89
101
}
90
102
91
103
if filter_branch :
92
- job ["filters" ] = gen_filter_branch_tree (filter_branch ,
93
- tags_list = RC_PATTERN )
104
+ job ["filters" ] = gen_filter_branch_tree (filter_branch , tags_list = RC_PATTERN )
94
105
return [{"build_docs" : job }]
95
106
96
107
@@ -99,12 +110,13 @@ def upload_doc_job(filter_branch):
99
110
"name" : "upload_docs" ,
100
111
"context" : "org-member" ,
101
112
"python_version" : "3.7" ,
102
- "requires" : ["build_docs" , ],
113
+ "requires" : [
114
+ "build_docs" ,
115
+ ],
103
116
}
104
117
105
118
if filter_branch :
106
- job ["filters" ] = gen_filter_branch_tree (filter_branch ,
107
- tags_list = RC_PATTERN )
119
+ job ["filters" ] = gen_filter_branch_tree (filter_branch , tags_list = RC_PATTERN )
108
120
return [{"upload_docs" : job }]
109
121
110
122
@@ -122,24 +134,25 @@ def upload_doc_job(filter_branch):
122
134
def get_manylinux_image (cu_version ):
123
135
if cu_version == "cpu" :
124
136
return "pytorch/manylinux-cuda102"
125
- elif cu_version .startswith ('cu' ):
126
- cu_suffix = cu_version [len ('cu' ) :]
137
+ elif cu_version .startswith ("cu" ):
138
+ cu_suffix = cu_version [len ("cu" ) :]
127
139
return f"pytorch/manylinux-cuda{ cu_suffix } "
128
- elif cu_version .startswith (' rocm' ):
129
- rocm_suffix = cu_version [len (' rocm' ) :]
140
+ elif cu_version .startswith (" rocm" ):
141
+ rocm_suffix = cu_version [len (" rocm" ) :]
130
142
return f"pytorch/manylinux-rocm:{ rocm_suffix } "
131
143
132
144
133
145
def get_conda_image (cu_version ):
134
146
if cu_version == "cpu" :
135
147
return "pytorch/conda-builder:cpu"
136
- elif cu_version .startswith ('cu' ):
137
- cu_suffix = cu_version [len ('cu' ) :]
148
+ elif cu_version .startswith ("cu" ):
149
+ cu_suffix = cu_version [len ("cu" ) :]
138
150
return f"pytorch/conda-builder:cuda{ cu_suffix } "
139
151
140
152
141
- def generate_base_workflow (base_workflow_name , python_version , cu_version ,
142
- unicode , os_type , btype , * , filter_branch = None ):
153
+ def generate_base_workflow (
154
+ base_workflow_name , python_version , cu_version , unicode , os_type , btype , * , filter_branch = None
155
+ ):
143
156
144
157
d = {
145
158
"name" : base_workflow_name ,
@@ -148,7 +161,7 @@ def generate_base_workflow(base_workflow_name, python_version, cu_version,
148
161
}
149
162
150
163
if os_type != "win" and unicode :
151
- d ["unicode_abi" ] = '1'
164
+ d ["unicode_abi" ] = "1"
152
165
153
166
if os_type != "win" :
154
167
d ["wheel_docker_image" ] = get_manylinux_image (cu_version )
@@ -158,14 +171,12 @@ def generate_base_workflow(base_workflow_name, python_version, cu_version,
158
171
159
172
if filter_branch is not None :
160
173
d ["filters" ] = {
161
- "branches" : {
162
- "only" : filter_branch
163
- },
174
+ "branches" : {"only" : filter_branch },
164
175
"tags" : {
165
176
# Using a raw string here to avoid having to escape
166
177
# anything
167
178
"only" : r"/v[0-9]+(\.[0-9]+)*-rc[0-9]+/"
168
- }
179
+ },
169
180
}
170
181
171
182
w = f"binary_{ os_type } _{ btype } "
@@ -186,19 +197,17 @@ def generate_upload_workflow(base_workflow_name, os_type, btype, cu_version, *,
186
197
"requires" : [base_workflow_name ],
187
198
}
188
199
189
- if btype == ' wheel' :
190
- d ["subfolder" ] = "" if os_type == ' macos' else cu_version + "/"
200
+ if btype == " wheel" :
201
+ d ["subfolder" ] = "" if os_type == " macos" else cu_version + "/"
191
202
192
203
if filter_branch is not None :
193
204
d ["filters" ] = {
194
- "branches" : {
195
- "only" : filter_branch
196
- },
205
+ "branches" : {"only" : filter_branch },
197
206
"tags" : {
198
207
# Using a raw string here to avoid having to escape
199
208
# anything
200
209
"only" : r"/v[0-9]+(\.[0-9]+)*-rc[0-9]+/"
201
- }
210
+ },
202
211
}
203
212
204
213
return {f"binary_{ btype } _upload" : d }
@@ -223,8 +232,7 @@ def generate_smoketest_workflow(pydistro, base_workflow_name, filter_branch, pyt
223
232
224
233
225
234
def indent (indentation , data_list ):
226
- return ("\n " + " " * indentation ).join (
227
- yaml .dump (data_list , default_flow_style = False ).splitlines ())
235
+ return ("\n " + " " * indentation ).join (yaml .dump (data_list , default_flow_style = False ).splitlines ())
228
236
229
237
230
238
def unittest_workflows (indentation = 6 ):
@@ -239,12 +247,12 @@ def unittest_workflows(indentation=6):
239
247
"python_version" : python_version ,
240
248
}
241
249
242
- if device_type == ' gpu' :
250
+ if device_type == " gpu" :
243
251
if python_version != "3.8" :
244
- job [' filters' ] = gen_filter_branch_tree (' main' , ' nightly' )
245
- job [' cu_version' ] = ' cu102'
252
+ job [" filters" ] = gen_filter_branch_tree (" main" , " nightly" )
253
+ job [" cu_version" ] = " cu102"
246
254
else :
247
- job [' cu_version' ] = ' cpu'
255
+ job [" cu_version" ] = " cpu"
248
256
249
257
jobs .append ({f"unittest_{ os_type } _{ device_type } " : job })
250
258
@@ -253,20 +261,17 @@ def unittest_workflows(indentation=6):
253
261
254
262
def cmake_workflows (indentation = 6 ):
255
263
jobs = []
256
- python_version = ' 3.8'
257
- for os_type in [' linux' , ' windows' , ' macos' ]:
264
+ python_version = " 3.8"
265
+ for os_type in [" linux" , " windows" , " macos" ]:
258
266
# Skip OSX CUDA
259
- device_types = [' cpu' , ' gpu' ] if os_type != ' macos' else [' cpu' ]
267
+ device_types = [" cpu" , " gpu" ] if os_type != " macos" else [" cpu" ]
260
268
for device in device_types :
261
- job = {
262
- 'name' : f'cmake_{ os_type } _{ device } ' ,
263
- 'python_version' : python_version
264
- }
269
+ job = {"name" : f"cmake_{ os_type } _{ device } " , "python_version" : python_version }
265
270
266
- job [' cu_version' ] = ' cu102' if device == ' gpu' else ' cpu'
267
- if device == ' gpu' and os_type == ' linux' :
268
- job [' wheel_docker_image' ] = ' pytorch/manylinux-cuda102'
269
- jobs .append ({f' cmake_{ os_type } _{ device } ' : job })
271
+ job [" cu_version" ] = " cu102" if device == " gpu" else " cpu"
272
+ if device == " gpu" and os_type == " linux" :
273
+ job [" wheel_docker_image" ] = " pytorch/manylinux-cuda102"
274
+ jobs .append ({f" cmake_{ os_type } _{ device } " : job })
270
275
return indent (indentation , jobs )
271
276
272
277
@@ -275,27 +280,27 @@ def ios_workflows(indentation=6, nightly=False):
275
280
build_job_names = []
276
281
name_prefix = "nightly_" if nightly else ""
277
282
env_prefix = "nightly-" if nightly else ""
278
- for arch , platform in [(' x86_64' , ' SIMULATOR' ), (' arm64' , 'OS' )]:
279
- name = f' { name_prefix } binary_libtorchvision_ops_ios_12.0.0_{ arch } '
283
+ for arch , platform in [(" x86_64" , " SIMULATOR" ), (" arm64" , "OS" )]:
284
+ name = f" { name_prefix } binary_libtorchvision_ops_ios_12.0.0_{ arch } "
280
285
build_job_names .append (name )
281
286
build_job = {
282
- ' build_environment' : f' { env_prefix } binary-libtorchvision_ops-ios-12.0.0-{ arch } ' ,
283
- ' ios_arch' : arch ,
284
- ' ios_platform' : platform ,
285
- ' name' : name ,
287
+ " build_environment" : f" { env_prefix } binary-libtorchvision_ops-ios-12.0.0-{ arch } " ,
288
+ " ios_arch" : arch ,
289
+ " ios_platform" : platform ,
290
+ " name" : name ,
286
291
}
287
292
if nightly :
288
- build_job [' filters' ] = gen_filter_branch_tree (' nightly' )
289
- jobs .append ({' binary_ios_build' : build_job })
293
+ build_job [" filters" ] = gen_filter_branch_tree (" nightly" )
294
+ jobs .append ({" binary_ios_build" : build_job })
290
295
291
296
if nightly :
292
297
upload_job = {
293
- ' build_environment' : f' { env_prefix } binary-libtorchvision_ops-ios-12.0.0-upload' ,
294
- ' context' : ' org-member' ,
295
- ' filters' : gen_filter_branch_tree (' nightly' ),
296
- ' requires' : build_job_names ,
298
+ " build_environment" : f" { env_prefix } binary-libtorchvision_ops-ios-12.0.0-upload" ,
299
+ " context" : " org-member" ,
300
+ " filters" : gen_filter_branch_tree (" nightly" ),
301
+ " requires" : build_job_names ,
297
302
}
298
- jobs .append ({' binary_ios_upload' : upload_job })
303
+ jobs .append ({" binary_ios_upload" : upload_job })
299
304
return indent (indentation , jobs )
300
305
301
306
@@ -305,23 +310,23 @@ def android_workflows(indentation=6, nightly=False):
305
310
name_prefix = "nightly_" if nightly else ""
306
311
env_prefix = "nightly-" if nightly else ""
307
312
308
- name = f' { name_prefix } binary_libtorchvision_ops_android'
313
+ name = f" { name_prefix } binary_libtorchvision_ops_android"
309
314
build_job_names .append (name )
310
315
build_job = {
311
- ' build_environment' : f' { env_prefix } binary-libtorchvision_ops-android' ,
312
- ' name' : name ,
316
+ " build_environment" : f" { env_prefix } binary-libtorchvision_ops-android" ,
317
+ " name" : name ,
313
318
}
314
319
315
320
if nightly :
316
321
upload_job = {
317
- ' build_environment' : f' { env_prefix } binary-libtorchvision_ops-android-upload' ,
318
- ' context' : ' org-member' ,
319
- ' filters' : gen_filter_branch_tree (' nightly' ),
320
- ' name' : f' { name_prefix } binary_libtorchvision_ops_android_upload'
322
+ " build_environment" : f" { env_prefix } binary-libtorchvision_ops-android-upload" ,
323
+ " context" : " org-member" ,
324
+ " filters" : gen_filter_branch_tree (" nightly" ),
325
+ " name" : f" { name_prefix } binary_libtorchvision_ops_android_upload" ,
321
326
}
322
- jobs .append ({' binary_android_upload' : upload_job })
327
+ jobs .append ({" binary_android_upload" : upload_job })
323
328
else :
324
- jobs .append ({' binary_android_build' : build_job })
329
+ jobs .append ({" binary_android_build" : build_job })
325
330
return indent (indentation , jobs )
326
331
327
332
@@ -330,15 +335,17 @@ def android_workflows(indentation=6, nightly=False):
330
335
env = jinja2 .Environment (
331
336
loader = jinja2 .FileSystemLoader (d ),
332
337
lstrip_blocks = True ,
333
- autoescape = select_autoescape (enabled_extensions = (' html' , ' xml' )),
338
+ autoescape = select_autoescape (enabled_extensions = (" html" , " xml" )),
334
339
keep_trailing_newline = True ,
335
340
)
336
341
337
- with open (os .path .join (d , 'config.yml' ), 'w' ) as f :
338
- f .write (env .get_template ('config.yml.in' ).render (
339
- build_workflows = build_workflows ,
340
- unittest_workflows = unittest_workflows ,
341
- cmake_workflows = cmake_workflows ,
342
- ios_workflows = ios_workflows ,
343
- android_workflows = android_workflows ,
344
- ))
342
+ with open (os .path .join (d , "config.yml" ), "w" ) as f :
343
+ f .write (
344
+ env .get_template ("config.yml.in" ).render (
345
+ build_workflows = build_workflows ,
346
+ unittest_workflows = unittest_workflows ,
347
+ cmake_workflows = cmake_workflows ,
348
+ ios_workflows = ios_workflows ,
349
+ android_workflows = android_workflows ,
350
+ )
351
+ )
0 commit comments