-
Notifications
You must be signed in to change notification settings - Fork 454
534 lines (454 loc) · 16.4 KB
/
ci.yml
File metadata and controls
534 lines (454 loc) · 16.4 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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
name: CI
on:
push:
branches:
- "**"
tags:
- v*
pull_request:
branches:
- master
jobs:
build-and-test-cpp-x86_64:
runs-on: ${{ matrix.os }}
env:
CT2_VERBOSE: 1
strategy:
matrix:
os: [ubuntu-22.04]
backend: [mkl, dnnl]
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install Intel oneAPI
if: startsWith(matrix.os, 'ubuntu')
run: |
wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB
sudo apt-key add *.PUB
sudo sh -c 'echo "deb https://apt.repos.intel.com/oneapi all main" > /etc/apt/sources.list.d/oneAPI.list'
sudo apt-get update
- name: Configure with MKL
if: startsWith(matrix.os, 'ubuntu') && matrix.backend == 'mkl'
env:
CT2_USE_MKL: 1
MKL_VERSION: 2023.0.0
run: |
sudo apt-get install -y intel-oneapi-mkl-devel-$MKL_VERSION
cmake -DCMAKE_INSTALL_PREFIX=$PWD/install -DBUILD_TESTS=ON .
- name: Configure with DNNL
if: startsWith(matrix.os, 'ubuntu') && matrix.backend == 'dnnl'
env:
DNNL_VERSION: 2023.0.0-25399
run: |
sudo apt-get install -y intel-oneapi-dnnl-devel=$DNNL_VERSION intel-oneapi-dnnl=$DNNL_VERSION
cmake -DCMAKE_INSTALL_PREFIX=$PWD/install -DBUILD_TESTS=ON -DWITH_MKL=OFF -DOPENMP_RUNTIME=COMP -DWITH_DNNL=ON .
- name: Build
run: |
make -j $(nproc) install
- name: Download test data
working-directory: tests/data/models
run: |
wget https://opennmt-models.s3.amazonaws.com/pi_lm_step_5000.pt
wget https://opennmt-models.s3.amazonaws.com/transliteration-aren-all.tar.gz
tar xf transliteration-aren-all.tar.gz
- name: Test MKL
if: matrix.backend == 'mkl'
env:
CT2_USE_MKL: 1
run: |
tests/ctranslate2_test tests/data
- name: Test DNNL
if: matrix.backend == 'dnnl'
run: |
tests/ctranslate2_test tests/data
build-and-test-cpp-x86_64-address_sanitizer:
runs-on: ubuntu-22.04
env:
CT2_VERBOSE: 1
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install Intel oneAPI
run: |
wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB
sudo apt-key add *.PUB
sudo sh -c 'echo "deb https://apt.repos.intel.com/oneapi all main" > /etc/apt/sources.list.d/oneAPI.list'
sudo apt update
- name: Install MKL
env:
CT2_USE_MKL: 1
MKL_VERSION: 2023.0.0
run: |
sudo apt install -y intel-oneapi-mkl-devel-$MKL_VERSION
- name: Install Clang
run: |
sudo apt install -y clang
- name: Configure with MKL and Clang
env:
CT2_USE_MKL: 1
run: |
cmake -DCMAKE_INSTALL_PREFIX=$PWD/install -DBUILD_TESTS=ON -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++ -DENABLE_ADDRESS_SANITIZER=ON -DCMAKE_BUILD_TYPE=Debug .
- name: Build
run: |
make -j $(nproc) install
- name: Download test data
working-directory: tests/data/models
run: |
wget https://opennmt-models.s3.amazonaws.com/pi_lm_step_5000.pt
wget https://opennmt-models.s3.amazonaws.com/transliteration-aren-all.tar.gz
tar xf transliteration-aren-all.tar.gz
- name: Test AddressSanitizer
env:
CT2_USE_MKL: 1
run: |
ASAN_OPTIONS=detect_leaks=1:print_stats=1 tests/ctranslate2_test tests/data
build-and-test-cpp-x86_64-thread_sanitizer:
runs-on: ubuntu-22.04
env:
CT2_VERBOSE: 1
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install Intel oneAPI
run: |
wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB
sudo apt-key add *.PUB
sudo sh -c 'echo "deb https://apt.repos.intel.com/oneapi all main" > /etc/apt/sources.list.d/oneAPI.list'
sudo apt update
- name: Install MKL
env:
CT2_USE_MKL: 1
MKL_VERSION: 2023.0.0
run: |
sudo apt install -y intel-oneapi-mkl-devel-$MKL_VERSION
- name: Install Clang
run: |
sudo apt install -y clang
- name: Configure with MKL and Clang
env:
CT2_USE_MKL: 1
run: |
cmake -DCMAKE_INSTALL_PREFIX=$PWD/install -DBUILD_TESTS=ON -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++ -DENABLE_THREAD_SANITIZER=ON -DCMAKE_BUILD_TYPE=Debug .
- name: Build
run: |
make -j $(nproc) install
- name: Download test data
working-directory: tests/data/models
run: |
wget https://opennmt-models.s3.amazonaws.com/pi_lm_step_5000.pt
wget https://opennmt-models.s3.amazonaws.com/transliteration-aren-all.tar.gz
tar xf transliteration-aren-all.tar.gz
- name: Test ThreadSanitizer
env:
CT2_USE_MKL: 1
run: |
TSAN_OPTIONS="ignore_noninstrumented_modules=1:halt_on_error=1" tests/ctranslate2_test tests/data
build-and-test-cpp-arm64:
runs-on: ${{ matrix.os }}
env:
CT2_VERBOSE: 1
strategy:
matrix:
include:
- os: ubuntu-22.04-arm
backend: openblas
- os: macos-15
backend: ruy
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Build with OpenBLAS and Ruy
if: matrix.backend == 'openblas'
run: |
wget https://github.com/xianyi/OpenBLAS/archive/v0.3.13.tar.gz
tar xzvf v0.3.13.tar.gz
cd OpenBLAS-0.3.13
make TARGET=ARMV8 NO_LAPACK=1 -j $(nproc)
sudo make PREFIX=/usr/local install -j $(nproc)
cd ..
export OpenBLAS_HOME=/usr/local
cmake \
-DOPENMP_RUNTIME=COMP \
-DCMAKE_INSTALL_PREFIX=$PWD/install \
-DWITH_MKL=OFF \
-DWITH_OPENBLAS=ON \
-DWITH_RUY=ON \
-DBUILD_TESTS=ON \
.
make -j $(nproc) install
- name: Build Ruy
if: matrix.backend == 'ruy'
run: |
CMAKE_EXTRA_OPTIONS='-DCMAKE_OSX_ARCHITECTURES=arm64 -DWITH_ACCELERATE=ON -DWITH_MKL=OFF -DOPENMP_RUNTIME=NONE -DWITH_RUY=ON'
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON \
-DCMAKE_INSTALL_PREFIX=$PWD/install \
-DBUILD_TESTS=ON \
$CMAKE_EXTRA_OPTIONS \
.
make -j $(nproc) install
- name: Download test data
run: |
wget https://opennmt-models.s3.amazonaws.com/transliteration-aren-all.tar.gz
tar xf transliteration-aren-all.tar.gz -C tests/data/models/
- name: Test
run: |
tests/ctranslate2_test tests/data
build-python-wheels:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-22.04, windows-2022]
arch: [auto64]
include:
- os: ubuntu-22.04
arch: aarch64
- os: macos-15
arch: arm64
- os: macos-15-intel
arch: x86_64
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: docker/setup-qemu-action@v2
if: ${{ matrix.arch == 'aarch64' }}
name: Set up QEMU
- name: Build wheels
uses: pypa/cibuildwheel@v3.2.1
with:
package-dir: python
output-dir: python/wheelhouse
env:
CIBW_ENVIRONMENT_PASS_LINUX: CIBW_ARCHS
CIBW_ENVIRONMENT_WINDOWS: CTRANSLATE2_ROOT='${{ github.workspace }}\install'
CIBW_ENVIRONMENT_MACOS: "CTRANSLATE2_ROOT='/usr/local' MACOSX_DEPLOYMENT_TARGET=11.00"
CIBW_BEFORE_ALL_LINUX: python/tools/prepare_build_environment_linux.sh
CIBW_BEFORE_ALL_MACOS: python/tools/prepare_build_environment_macos.sh
CIBW_BEFORE_ALL_WINDOWS: bash python/tools/prepare_build_environment_windows.sh
CIBW_BEFORE_BUILD: pip install -r python/install_requirements.txt
CIBW_MANYLINUX_X86_64_IMAGE: manylinux_2_28
CIBW_MANYLINUX_AARCH64_IMAGE: manylinux_2_28
CIBW_ARCHS: ${{ matrix.arch }}
CIBW_SKIP: "*-musllinux_*"
- name: Upload Python wheels
uses: actions/upload-artifact@v4
with:
name: python-wheels-${{ runner.os }}-${{ matrix.arch }}
path: python/wheelhouse
build-python-wheels-rocm:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-24.04, windows-2025]
steps:
- uses: actions/checkout@v6
with:
submodules: recursive
- name: Build wheels
uses: pypa/cibuildwheel@v3.2.1
with:
package-dir: python
output-dir: python/wheelhouse
env:
CIBW_ENVIRONMENT_LINUX: ROCM_PATH=/opt/rocm LD_LIBRARY_PATH=/opt/rocm/lib/llvm/lib:$LD_LIBRARY_PATH
CIBW_ENVIRONMENT_WINDOWS: CTRANSLATE2_ROOT='${{ github.workspace }}\install'
CIBW_BEFORE_ALL_LINUX: python/tools/prepare_build_environment_linux_rocm.sh
CIBW_BEFORE_ALL_WINDOWS: bash python/tools/prepare_build_environment_windows_rocm.sh
CIBW_BEFORE_BUILD: pip install -r python/install_requirements.txt
CIBW_MANYLINUX_X86_64_IMAGE: manylinux_2_28
CIBW_ARCHS: auto64
CIBW_SKIP: "*-musllinux_*"
CIBW_REPAIR_WHEEL_COMMAND_LINUX: 'auditwheel repair -w {dest_dir} --exclude "/opt/rocm/lib/lib*" {wheel}'
- name: Upload Python wheels
uses: actions/upload-artifact@v6
with:
name: rocm-python-wheels-${{ runner.os }}
path: python/wheelhouse
# We could test the Python wheels using cibuildwheel but we prefer to run the tests outside
# the build environment to ensure wheels correctly embed all dependencies.
test-python-wheels:
needs: [build-python-wheels]
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-22.04
artifact_pattern: python-wheels-Linux-auto64
wheel_pattern: "*cp310*manylinux*x86_64.whl"
- os: ubuntu-22.04-arm
artifact_pattern: python-wheels-Linux-aarch64
wheel_pattern: "*cp310*manylinux*_aarch64.whl"
- os: windows-2022
artifact_pattern: python-wheels-Windows-auto64
wheel_pattern: "*cp310*win*amd64.whl"
- os: macos-15
artifact_pattern: python-wheels-macOS-arm64
wheel_pattern: "*cp310*macosx*arm64.whl"
steps:
- name: Set up Python 3.10.11
uses: actions/setup-python@v5
with:
python-version: "3.10.11"
- uses: actions/checkout@v4
- name: Prepare test environment
shell: bash
run: |
./python/tools/prepare_test_environment.sh
- name: Download Python wheels
uses: actions/download-artifact@v4
with:
pattern: ${{ matrix.artifact_pattern }}
merge-multiple: true
path: .
- name: Install wheel
shell: bash
run: |
pip install ${{ matrix.wheel_pattern }}
- name: Test Python wheel
run: |
pytest -v python/tests/ --ignore=python/tests/test_opennmt_tf.py
check-python-style:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10.11
uses: actions/setup-python@v5
with:
python-version: "3.10.11"
- name: Install dependencies
run: |
python -m pip install black==22.* flake8==3.8.* isort==5.*
- name: Check code format with Black
working-directory: python
run: |
black --check .
- name: Check imports order with isort
working-directory: python
run: |
isort --check-only .
- name: Check code style with Flake8
working-directory: python
if: ${{ always() }}
run: |
flake8 .
publish-python-wheels-on-pypi:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
needs: [build-and-test-cpp-x86_64, build-and-test-cpp-arm64, build-python-wheels, test-python-wheels, check-python-style]
runs-on: ubuntu-22.04
steps:
- name: Download Python wheels
uses: actions/download-artifact@v4
with:
pattern: python-wheels-*
merge-multiple: true
path: .
- name: Publish Python wheels to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
packages-dir: .
build-and-push-docker-images:
runs-on: ubuntu-22.04
strategy:
matrix:
gpu: [cuda, rocm]
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Show disk and docker usage (before cleanup)
run: |
df -h
echo " -= Docker System =-"
docker system df || true
- name: Free disk space (cleanup heavy preinstalled directories + docker prune)
run: |
echo " -= Removing big preinstalled directories (shouldn't remove the needed tools) =-"
sudo rm -rf /opt/hostedtoolcache || true
sudo rm -rf /usr/share/dotnet || true
sudo rm -rf /usr/lib/jvm || true
sudo rm -rf /usr/local/lib/android || true
echo " -= Running docker prune =-"
docker system prune -af --volumes || true
docker builder prune -af || true
- name: Show disk and docker usage (after cleanup)
run: |
df -h
echo " -= Docker System =-"
docker system df || true
- name: Build Docker images
run: |
./docker/build_all.sh latest 0 ${{ matrix.gpu }}
- name: Login to DockerHub
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push Docker images
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
run: |
./docker/build_all.sh ${GITHUB_REF##*/v} 1 ${{ matrix.gpu }}
build-and-deploy-docs:
runs-on: ubuntu-latest
needs: [check-python-style, build-python-wheels, build-python-wheels-rocm]
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10.11
uses: actions/setup-python@v5
with:
python-version: "3.10.11"
- name: Download CTranslate2 wheels
uses: actions/download-artifact@v4
with:
pattern: python-wheels-${{ runner.os }}-*
merge-multiple: true
path: .
- name: Install CTranslate2 wheel
run: |
pip install *cp310*manylinux*x86_64.whl
- name: Install dependencies to build docs
working-directory: docs
run: |
python -m pip install -r requirements.txt
- name: Build docs
working-directory: docs
run: |
python generate.py python
sphinx-build . build
- name: Deploy docs
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: docs/build
clean: true
- name: Download ROCm wheels and zip for release
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
mkdir -p release-zips
gh run download ${{ github.run_id }} \
--name rocm-python-wheels-Linux \
--dir temp-linux
zip -r release-zips/rocm-python-wheels-Linux.zip temp-linux/*
rm -rf temp-linux
gh run download ${{ github.run_id }} \
--name rocm-python-wheels-Windows \
--dir temp-windows
zip -r release-zips/rocm-python-wheels-Windows.zip temp-windows/*
rm -rf temp-windows
- name: Create GitHub Release
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: softprops/action-gh-release@v2
with:
files: release-zips/*.zip