forked from browsermt/bergamot-translator
-
Notifications
You must be signed in to change notification settings - Fork 0
533 lines (455 loc) · 20.4 KB
/
build.yml
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
name: "Build"
'on':
push:
branches:
- main
- ci-sandbox
tags:
- "v*.*.*"
pull_request:
branches:
- '**'
env:
qt_version: "6.2.1" # only used by build-macos
emsdk_version: 2.0.9 # For use in emscripten build
ccache_basedir: ${{ github.workspace }}
ccache_dir: "${{ github.workspace }}/.ccache"
ccache_compilercheck: content
ccache_compress: 'true'
ccache_compresslevel: 9
ccache_maxsize: 200M
ccache_cmake: -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache
jobs:
python-ubuntu:
strategy:
fail-fast: false
matrix:
include:
- name: "Ubuntu 18.04 / py3.6"
os: "ubuntu-18.04"
python-version: "3.6"
- name: "Ubuntu 18.04 / py3.7"
os: "ubuntu-18.04"
python-version: "3.7"
- name: "Ubuntu 20.04 / py3.8"
os: "ubuntu-20.04"
python-version: "3.8"
- name: "Ubuntu 20.04 / py3.9"
os: "ubuntu-20.04"
python-version: "3.9"
- name: "Ubuntu 20.04 / py3.10"
os: "ubuntu-20.04"
python-version: "3.10"
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: recursive
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies
run: |-
sudo apt-get update
sudo apt-get install -y \
ccache libprotobuf-dev protobuf-compiler \
python3-setuptools python3-pybind11
- name: Install MKL
run: |-
wget -qO- "https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB" | sudo apt-key add -
sudo sh -c "echo deb https://apt.repos.intel.com/mkl all main > /etc/apt/sources.list.d/intel-mkl.list"
sudo apt-get update -o Dir::Etc::sourcelist="/etc/apt/sources.list.d/intel-mkl.list"
sudo apt-get install -y --no-install-recommends intel-mkl-64bit-2020.0-088
- name: Generate ccache_vars for ccache based on machine
shell: bash
id: ccache_vars
run: |-
echo "::set-output name=hash::$(echo ${{ env.ccache_compilercheck }})"
echo "::set-output name=timestamp::$(date '+%Y-%m-%dT%H.%M.%S')"
- name: Cache-op for build-cache through ccache
uses: actions/cache@v2
with:
path: ${{ env.ccache_dir }}
key: ccache-${{ matrix.name }}-${{ steps.ccache_vars.outputs.hash }}-${{ github.ref }}-${{ steps.ccache_vars.outputs.timestamp }}
restore-keys: |-
ccache-${{ matrix.name }}-${{ steps.ccache_vars.outputs.hash }}-${{ github.ref }}
ccache-${{ matrix.name }}-${{ steps.ccache_vars.outputs.hash }}
ccache-${{ matrix.name }}
- name: ccache environment setup
run: |-
echo "CCACHE_COMPILER_CHECK=${{ env.ccache_compilercheck }}" >> $GITHUB_ENV
echo "CCACHE_BASEDIR=${{ env.ccache_basedir }}" >> $GITHUB_ENV
echo "CCACHE_COMPRESS=${{ env.ccache_compress }}" >> $GITHUB_ENV
echo "CCACHE_COMPRESSLEVEL=${{ env.ccache_compresslevel }}" >> $GITHUB_ENV
echo "CCACHE_DIR=${{ env.ccache_dir }}" >> $GITHUB_ENV
echo "CCACHE_MAXSIZE=${{ env.ccache_maxsize }}" >> $GITHUB_ENV
- name: ccache prolog
run: |-
ccache -s # Print current cache stats
ccache -z # Zero cache entry
- name: Inject local version identifier for non tag builds
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
run: |-
echo "PYTHON_LOCAL_VERSION_IDENTIFIER=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: setup.py
run: |-
python3 -m pip install wheel
BUILD_ARCH=core-avx-i python3 setup.py bdist_wheel --universal
# We're happy with just compile for the moment, so cache gets some seeding.
- name: Install onto root python lib
run: |-
python3 -m pip install --ignore-installed dist/bergamot-*.whl
- name: Fetch models from translateLocally repository.
run: |-
python3 -m bergamot download -m en-de-tiny
python3 -m bergamot download -m de-en-tiny
python3 -m bergamot ls
- name: Fetch models from opus repository.
run: |-
python3 -m bergamot download -m eng-fin-tiny -r opus
python3 -m bergamot ls -r opus
- name: Run the sample python script shipped with module
run: |-
python3 -m bergamot translate --model en-de-tiny <<< "Hello World"
python3 -m bergamot translate --model en-de-tiny de-en-tiny <<< "Hello World"
python3 -m bergamot translate --model eng-fin-tiny --repository opus <<< "Hello World"
- name: ccache epilog
run: 'ccache -s # Print current cache stats'
- uses: actions/upload-artifact@v2
with:
path: ${{github.workspace}}/dist/bergamot-*.whl
python-macos:
name: "MacOS 10.15 / py3.10"
runs-on: "macos-10.15"
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: recursive
- name: Install Dependencies
run: |-
brew update
brew install openblas protobuf ccache boost pybind11
brew install coreutils findutils libarchive
- name: Generate ccache_vars for ccache based on machine
shell: bash
id: ccache_vars
run: |-
echo "::set-output name=hash::$(echo ${{ env.ccache_compilercheck }})"
echo "::set-output name=timestamp::$(date '+%Y-%m-%dT%H.%M.%S')"
- name: Cache-op for build-cache through ccache
uses: actions/cache@v2
with:
path: ${{ env.ccache_dir }}
key: ccache-${{ job.id }}-${{ steps.ccache_vars.outputs.hash }}-${{ github.ref }}-${{ steps.ccache_vars.outputs.timestamp }}
restore-keys: |-
ccache-${{ job.id }}-${{ steps.ccache_vars.outputs.hash }}-${{ github.ref }}
ccache-${{ job.id }}-${{ steps.ccache_vars.outputs.hash }}
ccache-${{ job.id }}
- name: ccache environment setup
run: |-
echo "CCACHE_COMPILER_CHECK=${{ env.ccache_compilercheck }}" >> $GITHUB_ENV
echo "CCACHE_BASEDIR=${{ env.ccache_basedir }}" >> $GITHUB_ENV
echo "CCACHE_COMPRESS=${{ env.ccache_compress }}" >> $GITHUB_ENV
echo "CCACHE_COMPRESSLEVEL=${{ env.ccache_compresslevel }}" >> $GITHUB_ENV
echo "CCACHE_DIR=${{ env.ccache_dir }}" >> $GITHUB_ENV
echo "CCACHE_MAXSIZE=${{ env.ccache_maxsize }}" >> $GITHUB_ENV
- name: ccache prolog
run: |-
ccache -s # Print current cache stats
ccache -z # Zero cache entry
- name: Apply required patches
run: |-
patch -p1 < patches/01-marian-fstream-for-macos.patch
# Appears to be required per GitHub CI;
- name: Set MACOSX DEPLOYMENT TARGET via environment variable
run: |-
echo "MACOSX_DEPLOYMENT_TARGET=10.15" >> $GITHUB_ENV
- name: Inject local version identifier for non tag builds
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
run: |-
echo "PYTHON_LOCAL_VERSION_IDENTIFIER=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: setup.py
run: |-
python3 -m pip install --upgrade packaging wheel
BUILD_ARCH=core-avx-i python3 setup.py bdist_wheel --universal
# We're happy with just compile for the moment, so cache gets some seeding.
- name: Install onto root python lib
run: |-
python3 -m pip install dist/bergamot-*.whl
- name: Fetch models from translateLocally repository.
run: |-
python3 -m bergamot download -m en-de-tiny
python3 -m bergamot download -m de-en-tiny
- name: Fetch models from opus repository.
run: |-
python3 -m bergamot download -m eng-fin-tiny -r opus
python3 -m bergamot ls -r opus
- name: Run the sample python script shipped with module
run: |-
python3 -m bergamot translate --model en-de-tiny <<< "Hello World"
python3 -m bergamot translate --model en-de-tiny de-en-tiny <<< "Hello World"
python3 -m bergamot translate --model eng-fin-tiny --repository opus <<< "Hello World"
- name: ccache epilog
run: 'ccache -s # Print current cache stats'
- uses: actions/upload-artifact@v2
with:
path: ${{github.workspace}}/dist/bergamot-*.whl
build-wasm:
name: "emscripten"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: recursive
- name: Set ccache environment for emcc
run: |
# We are hardcoding this to mtime instead of env pickup. Rest use content.
echo "CCACHE_COMPILER_CHECK=mtime" >> $GITHUB_ENV
echo "CCACHE_BASEDIR=${{ env.ccache_basedir }}" >> $GITHUB_ENV
echo "CCACHE_COMPRESS=${{ env.ccache_compress }}" >> $GITHUB_ENV
echo "CCACHE_COMPRESSLEVEL=${{ env.ccache_compresslevel }}" >> $GITHUB_ENV
echo "CCACHE_DIR=${{ env.ccache_dir }}" >> $GITHUB_ENV
echo "CCACHE_MAXSIZE=${{ env.ccache_maxsize }}" >> $GITHUB_ENV
# https://emscripten.org/docs/compiling/Building-Projects.html#using-a-compiler-wrapper
echo "EM_COMPILER_WRAPPER=ccache" >> $GITHUB_ENV
# This need to be run before setup, so ccache build caching doesn't complain.
- name: Obtain emsdk sources
run: |
git clone --depth 1 https://github.com/emscripten-core/emsdk.git
- name: Cache-op for build-cache through ccache
uses: actions/cache@v2
with:
path: |
${{ env.ccache_dir }}
${{ github.workspace }}/emsdk/ccache/git-emscripten_64bit/
key: ccache-${{ github.job }}-${{ env.emsdk_version }}-${{ steps.ccache_vars.outputs.hash }}-${{ github.ref }}-${{ steps.ccache_vars.outputs.timestamp }}
restore-keys: |-
ccache-${{ github.job }}-${{ env.emsdk_version }}-${{ steps.ccache_vars.outputs.hash }}-${{ github.ref }}
ccache-${{ github.job }}-${{ env.emsdk_version }}-${{ steps.ccache_vars.outputs.hash }}
ccache-${{ github.job }}-${{ env.emsdk_version }}
- name: Setup Emscripten toolchain
run: |
(cd emsdk && ./emsdk install ${{ env.emsdk_version }} ccache-git-emscripten-64bit)
(cd emsdk && ./emsdk activate ${{ env.emsdk_version }} ccache-git-emscripten-64bit)
# mtime of this file is checked by ccache, we set it to avoid cache misses.
touch -m -d '1 Jan 2021 12:00' emsdk/.emscripten
# These needs to be done in the activated shell.
eval $(./emsdk/emsdk construct_env \
| sed 's/export PATH=\(.*\);/echo \1 >> $GITHUB_PATH;/' \
| sed 's/export \(.*\);/echo \1 >> $GITHUB_ENV;/' );
# This looks more permanent than version pinned, so keeping temporarily to avoid failures.
echo "${{ github.workspace }}/emsdk/ccache/git-emscripten_64bit/bin" >> $GITHUB_PATH
- name: Generate ccache_vars for ccache based on machine
shell: bash
id: ccache_vars
run: |-
echo "::set-output name=hash::$(echo ${{ env.ccache_compilercheck }})"
echo "::set-output name=timestamp::$(date '+%Y-%m-%dT%H.%M.%S')"
- name: Verify Emscripten setup
run: |
emcc --version
emcmake cmake --version
emmake make --version
- name: ccache prolog
run: |-
ccache -s # Print current cache stats
ccache -z # Zero cache entry
# WORMHOLE=off
- name: "Configure builds for WORMHOLE=off"
run: |
mkdir -p build-wasm-without-wormhole
cd build-wasm-without-wormhole
emcmake cmake -DCOMPILE_WASM=on -DWORMHOLE=off ..
- name: "Compile with WORMHOLE=off"
working-directory: build-wasm-without-wormhole
run: |
emmake make -j2
- name: ccache epilog
run: |
ccache -s # Print current cache stats
- name: Import GEMM library from a separate wasm module
working-directory: build-wasm-without-wormhole
run: bash ../wasm/patch-artifacts-import-gemm-module.sh
# WORMHOLE=on
- name: "Configure builds for WORMHOLE=on"
run: |
mkdir -p build-wasm-with-wormhole
cd build-wasm-with-wormhole
emcmake cmake -DCOMPILE_WASM=on -DWORMHOLE=on ..
- name: "Compile with WORMHOLE=on"
working-directory: build-wasm-with-wormhole
run: |
emmake make -j2
- name: ccache epilog
run: |
ccache -s # Print current cache stats
- name: Instantiate simd wormhole
working-directory: build-wasm-with-wormhole
run: bash ../wasm/patch-artifacts-enable-wormhole.sh
- name: Import GEMM library from a separate wasm module
working-directory: build-wasm-with-wormhole
run: bash ../wasm/patch-artifacts-import-gemm-module.sh
# Rename the wormhole on builds
- name: Rename artefacts with wormhole
working-directory: build-wasm-with-wormhole
run: |
mv bergamot-translator-worker{,-with-wormhole}.js
mv bergamot-translator-worker{,-with-wormhole}.js.bak
mv bergamot-translator-worker{,-with-wormhole}.wasm
# Upload both together.
- name: Upload wasm artifact
uses: actions/upload-artifact@v2
with:
name: wasm-artefacts
if-no-files-found: error
path: |
# Without wormhole
${{github.workspace}}/build-wasm-without-wormhole/bergamot-translator-worker.js
${{github.workspace}}/build-wasm-without-wormhole/bergamot-translator-worker.wasm
${{github.workspace}}/build-wasm-without-wormhole/bergamot-translator-worker.js.bak
${{github.workspace}}/build-wasm-with-wormhole/bergamot-translator-worker-with-wormhole.js
${{github.workspace}}/build-wasm-with-wormhole/bergamot-translator-worker-with-wormhole.wasm
${{github.workspace}}/build-wasm-with-wormhole/bergamot-translator-worker-with-wormhole.js.bak
# Try to upload a release using https://github.com/marvinpinto/actions/issues/177#issuecomment-917605585 as a model
release-latest:
name: Release Latest Build
runs-on: ubuntu-latest
needs: [python-ubuntu, python-macos, build-wasm]
if: github.ref == 'refs/heads/main'
steps:
- name: Download artifacts
uses: actions/download-artifact@v2
- name: Update GitHub prerelease
uses: marvinpinto/action-automatic-releases@latest
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
automatic_release_tag: latest
prerelease: true
title: "Latest Build"
files: |
artifact/*.whl
wasm-artefacts/build-wasm-without-wormhole/bergamot-translator-worker.js
wasm-artefacts/build-wasm-without-wormhole/bergamot-translator-worker.wasm
wasm-artefacts/build-wasm-with-wormhole/bergamot-translator-worker-with-wormhole.js
wasm-artefacts/build-wasm-with-wormhole/bergamot-translator-worker-with-wormhole.wasm
release-version:
name: Release version
runs-on: ubuntu-latest
needs: [python-ubuntu, python-macos, build-wasm]
permissions:
contents: "write"
packages: "write"
pull-requests: "read"
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Download artifacts
uses: actions/download-artifact@v2
- name: Update GitHub release
uses: marvinpinto/action-automatic-releases@latest
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
automatic_release_tag: ${{ github.ref_name }}
prerelease: false
title: "${{ github.ref_name }}"
files: |
artifact/*.whl
wasm-artefacts/build-wasm-without-wormhole/bergamot-translator-worker.js
wasm-artefacts/build-wasm-without-wormhole/bergamot-translator-worker.wasm
wasm-artefacts/build-wasm-with-wormhole/bergamot-translator-worker-with-wormhole.js
wasm-artefacts/build-wasm-with-wormhole/bergamot-translator-worker-with-wormhole.wasm
python-checks:
name: "formatting and typechecks"
runs-on: "ubuntu-latest"
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: recursive
- name: Install Dependencies
run: |-
python3 -m pip install black isort pytype
- name: "Formatting checks: black, isort"
run: |
python3 -m black --check bindings/python/ setup.py doc/conf.py
python3 -m isort --profile black --diff --check bindings/python setup.py doc/conf.py
- name: "Static typing checks: pytype"
run: |-
python3 -m pytype bindings/python
docs:
runs-on: ubuntu-18.04
needs: [python-ubuntu]
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: recursive
# Runs javascript to extract push events from both tags and branch (only main, due to workflow trigger)
# converts refs/<>/<name> -> <name>
# eg:
# refs/head/main -> main
# refs/tags/v0.1.0 -> v0.1.0
#
- name: Download artifacts
uses: actions/download-artifact@v2
- name: Extract tag name
id: tag
uses: actions/[email protected]
if: ${{ github.event_name == 'push' }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const args = context.payload.ref.split("/");
[refs, category, ...rest] = args;
return rest.join("/");
# Patches the BERGAMOT_VERSION file used by sphinx-docs at run time to
# obtain names like 'main' or 'ci-sandbox' to not confuse with version
# based documentation built separately.
- name: Deploy-time patch version
run: |
echo ${{steps.tag.outputs.result }} > BERGAMOT_VERSION
- name: Set up Doxygen
run: sudo apt-get install -y doxygen
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.7
- name: Set up dependency cache
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('doc/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
working-directory: ./doc
run: |
python3 -m pip install -r requirements.txt
python3 -m pip install ${{github.workspace}}/artifact/bergamot-*-cp37*.whl
- name: Build documentation
working-directory: ./doc
run: sphinx-build -b html ./ build/
- name: Deploy 🚀
uses: JamesIves/[email protected]
if: ${{ github.event_name == 'push' && github.repository == 'browsermt/bergamot-translator' }}
with:
repository-name: 'browsermt/docs'
branch: gh-pages # The branch the action should deploy to.
folder: './doc/build/' # The folder the action should deploy.
target-folder: '${{ steps.tag.outputs.result }}'
ssh-key: ${{ secrets.BERGAMOT_SSH_PRIVATE_KEY }}
# This artifact contains the HTML output of Sphinx only.
# With index.html at the root of the produced zip file.
# For use for maintainers to download the zip and check render of
# documentation while generated at pull-request.
- name: Upload documentation
uses: actions/upload-artifact@v2
if: ${{ github.event_name == 'pull_request'}}
with:
name: api-docs
path: ./doc/build/
if-no-files-found: error