config.yml 18.3 KB
Newer Older
1
2
3
4
5
version: 2.1
orbs:
    gcp-gke: circleci/gcp-gke@1.0.4
    go: circleci/go@1.3.0

6
7
8
9
10
11
12
13
commands:
  skip-job-on-doc-only-changes:
    description: "Do not continue this job and exit with success for PRs with only doc changes"
    steps:

      - run:
          name: docs-only changes skip check
          command: |
14
            # pipeline.git.base_revision is not always defined, so only proceed if all external vars are defined
15
            if test -n "<< pipeline.git.base_revision >>" && test -n "<< pipeline.git.revision >>" && test -n "$(git diff --name-only << pipeline.git.base_revision >>...<< pipeline.git.revision >>)"
16
            then
17
18
19
20
21
                if git diff --name-only << pipeline.git.base_revision >>...<< pipeline.git.revision >> | egrep -qv '\.(md|rst)$'
                then
                    echo "Non-docs were modified in this PR, proceeding normally"
                else
                    echo "Only docs were modified in this PR, quitting this job"
22
23
                    # disable skipping for now, as circleCI's base_revision is inconsistent leading to invalid ranges
                    # circleci step halt
24
                fi
25
            else
26
                echo "Can't perform skipping check w/o base_revision defined, continuing the job"
27
28
            fi

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# TPU REFERENCES
references:
    checkout_ml_testing: &checkout_ml_testing
        run:
            name: Checkout ml-testing-accelerators
            command: |
                git clone https://github.com/GoogleCloudPlatform/ml-testing-accelerators.git
                cd ml-testing-accelerators
                git fetch origin 5e88ac24f631c27045e62f0e8d5dfcf34e425e25:stable
                git checkout stable
    build_push_docker: &build_push_docker
        run:
            name: Configure Docker
            command: |
                gcloud --quiet auth configure-docker
                cd docker/transformers-pytorch-tpu
45
                if [ -z "$CIRCLE_PR_NUMBER" ]; then docker build --tag "$GCR_IMAGE_PATH:$CIRCLE_WORKFLOW_JOB_ID" -f Dockerfile --build-arg "TEST_IMAGE=1" . ; else docker build --tag "$GCR_IMAGE_PATH:$CIRCLE_WORKFLOW_JOB_ID" -f Dockerfile --build-arg "TEST_IMAGE=1" --build-arg "GITHUB_REF=pull/$CIRCLE_PR_NUMBER/head" . ; fi
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
                docker push "$GCR_IMAGE_PATH:$CIRCLE_WORKFLOW_JOB_ID"
    deploy_cluster: &deploy_cluster
        run:
            name: Deploy the job on the kubernetes cluster
            command: |
                go get github.com/google/go-jsonnet/cmd/jsonnet && \
                export PATH=$PATH:$HOME/go/bin && \
                kubectl create -f docker/transformers-pytorch-tpu/dataset.yaml || true && \
                job_name=$(jsonnet -J ml-testing-accelerators/ docker/transformers-pytorch-tpu/bert-base-cased.jsonnet --ext-str image=$GCR_IMAGE_PATH --ext-str image-tag=$CIRCLE_WORKFLOW_JOB_ID | kubectl create -f -) && \
                job_name=${job_name#job.batch/} && \
                job_name=${job_name% created} && \
                echo "Waiting on kubernetes job: $job_name" && \
                i=0 && \
                # 30 checks spaced 30s apart = 900s total.
                max_checks=30 && \
                status_code=2 && \
                # Check on the job periodically. Set the status code depending on what
                # happened to the job in Kubernetes. If we try max_checks times and
                # still the job hasn't finished, give up and return the starting
                # non-zero status code.
                while [ $i -lt $max_checks ]; do ((i++)); if kubectl get jobs $job_name -o jsonpath='Failed:{.status.failed}' | grep "Failed:1"; then status_code=1 && break; elif kubectl get jobs $job_name -o jsonpath='Succeeded:{.status.succeeded}' | grep "Succeeded:1" ; then status_code=0 && break; else echo "Job not finished yet"; fi; sleep 30; done && \
                echo "Done waiting. Job status code: $status_code" && \
68
69
70
                pod_name=$(kubectl get po -l controller-uid=`kubectl get job $job_name -o "jsonpath={.metadata.labels.controller-uid}"` | awk 'match($0,!/NAME/) {print $1}') && \
                echo "GKE pod name: $pod_name" && \
                kubectl logs -f $pod_name --container=train
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
                echo "Done with log retrieval attempt." && \
                gcloud container images delete "$GCR_IMAGE_PATH:$CIRCLE_WORKFLOW_JOB_ID" --force-delete-tags && \
                exit $status_code
    delete_gke_jobs: &delete_gke_jobs
        run:
            name: Delete GKE Jobs
            command: |
                # Match jobs whose age matches patterns like '1h' or '1d', i.e. any job
                # that has been around longer than 1hr. First print all columns for
                # matches, then execute the delete.
                kubectl get job | awk 'match($4,/[0-9]+[dh]/) {print $0}'
                kubectl delete job $(kubectl get job | awk 'match($4,/[0-9]+[dh]/) {print $1}')




Julien Chaumond's avatar
Julien Chaumond committed
87
jobs:
Aymeric Augustin's avatar
Aymeric Augustin committed
88
    run_tests_torch_and_tf:
89
        working_directory: ~/transformers
90
        docker:
91
            - image: circleci/python:3.6
92
93
        environment:
            OMP_NUM_THREADS: 1
94
95
96
97
        resource_class: xlarge
        parallelism: 1
        steps:
            - checkout
98
            - skip-job-on-doc-only-changes
99
100
            - restore_cache:
                  keys:
Lysandre Debut's avatar
Lysandre Debut committed
101
102
                      - v0.4-torch_and_tf-{{ checksum "setup.py" }}
                      - v0.4-{{ checksum "setup.py" }}
103
            - run: pip install --upgrade pip
104
            - run: pip install .[sklearn,tf-cpu,torch,testing,sentencepiece]
105
            - save_cache:
Lysandre Debut's avatar
Lysandre Debut committed
106
                key: v0.4-{{ checksum "setup.py" }}
107
108
                paths:
                    - '~/.cache/pip'
109
            - run: RUN_PT_TF_CROSS_TESTS=1 python -m pytest -n 8 --dist=loadfile -rA -s --make-reports=tests_torch_and_tf ./tests/ -m is_pt_tf_cross_test --durations=0 | tee tests_output.txt
110
            - store_artifacts:
111
112
113
114
                  path: ~/transformers/tests_output.txt
            - store_artifacts:
                  path: ~/transformers/reports

Aymeric Augustin's avatar
Aymeric Augustin committed
115
    run_tests_torch:
116
        working_directory: ~/transformers
Julien Chaumond's avatar
Julien Chaumond committed
117
        docker:
118
            - image: circleci/python:3.7
119
120
        environment:
            OMP_NUM_THREADS: 1
121
        resource_class: xlarge
122
        parallelism: 1
Julien Chaumond's avatar
Julien Chaumond committed
123
124
        steps:
            - checkout
125
            - skip-job-on-doc-only-changes
126
127
            - restore_cache:
                  keys:
Lysandre Debut's avatar
Lysandre Debut committed
128
129
                      - v0.4-torch-{{ checksum "setup.py" }}
                      - v0.4-{{ checksum "setup.py" }}
130
            - run: pip install --upgrade pip
131
            - run: pip install .[sklearn,torch,testing,sentencepiece]
132
            - save_cache:
Lysandre Debut's avatar
Lysandre Debut committed
133
                  key: v0.4-torch-{{ checksum "setup.py" }}
134
135
                  paths:
                      - '~/.cache/pip'
136
            - run: python -m pytest -n 8 --dist=loadfile -s --make-reports=tests_torch ./tests/ | tee tests_output.txt
137
            - store_artifacts:
138
139
140
                  path: ~/transformers/tests_output.txt
            - store_artifacts:
                  path: ~/transformers/reports
Lysandre Debut's avatar
Lysandre Debut committed
141

Aymeric Augustin's avatar
Aymeric Augustin committed
142
    run_tests_tf:
143
        working_directory: ~/transformers
thomwolf's avatar
thomwolf committed
144
        docker:
145
            - image: circleci/python:3.7
146
147
        environment:
            OMP_NUM_THREADS: 1
thomwolf's avatar
thomwolf committed
148
149
150
151
        resource_class: xlarge
        parallelism: 1
        steps:
            - checkout
152
            - skip-job-on-doc-only-changes
153
154
            - restore_cache:
                  keys:
Lysandre Debut's avatar
Lysandre Debut committed
155
156
                      - v0.4-tf-{{ checksum "setup.py" }}
                      - v0.4-{{ checksum "setup.py" }}
157
            - run: pip install --upgrade pip
158
            - run: pip install .[sklearn,tf-cpu,testing,sentencepiece]
159
            - save_cache:
Lysandre Debut's avatar
Lysandre Debut committed
160
                  key: v0.4-tf-{{ checksum "setup.py" }}
161
162
                  paths:
                      - '~/.cache/pip'
163
            - run: python -m pytest -n 8 --dist=loadfile -rA -s --make-reports=tests_tf ./tests/ | tee tests_output.txt
164
            - store_artifacts:
165
166
167
168
                  path: ~/transformers/tests_output.txt
            - store_artifacts:
                  path: ~/transformers/reports

169
170
171
172
173
174
175
176
177
178
    run_tests_flax:
        working_directory: ~/transformers
        docker:
            - image: circleci/python:3.7
        environment:
            OMP_NUM_THREADS: 1
        resource_class: xlarge
        parallelism: 1
        steps:
            - checkout
179
            - skip-job-on-doc-only-changes
180
181
            - restore_cache:
                keys:
Lysandre Debut's avatar
Lysandre Debut committed
182
183
                    - v0.4-flax-{{ checksum "setup.py" }}
                    - v0.4-{{ checksum "setup.py" }}
184
            - run: pip install --upgrade pip
185
            - run: sudo pip install .[flax,sklearn,torch,testing,sentencepiece]
186
            - save_cache:
Lysandre Debut's avatar
Lysandre Debut committed
187
                  key: v0.4-flax-{{ checksum "setup.py" }}
188
189
                  paths:
                      - '~/.cache/pip'
190
            - run: python -m pytest -n 8 --dist=loadfile -rA -s --make-reports=tests_flax ./tests/ | tee tests_output.txt
191
            - store_artifacts:
192
193
194
195
                  path: ~/transformers/tests_output.txt
            - store_artifacts:
                  path: ~/transformers/reports

196
197
198
199
200
201
202
203
204
205
    run_tests_pipelines_torch:
        working_directory: ~/transformers
        docker:
            - image: circleci/python:3.7
        environment:
            OMP_NUM_THREADS: 1
        resource_class: xlarge
        parallelism: 1
        steps:
            - checkout
206
            - skip-job-on-doc-only-changes
207
208
            - restore_cache:
                  keys:
Lysandre Debut's avatar
Lysandre Debut committed
209
210
                      - v0.4-torch-{{ checksum "setup.py" }}
                      - v0.4-{{ checksum "setup.py" }}
211
            - run: pip install --upgrade pip
212
            - run: pip install .[sklearn,torch,testing,sentencepiece]
213
            - save_cache:
Lysandre Debut's avatar
Lysandre Debut committed
214
                  key: v0.4-torch-{{ checksum "setup.py" }}
215
216
                  paths:
                      - '~/.cache/pip'
217
            - run: RUN_PIPELINE_TESTS=1 python -m pytest -n 8 --dist=loadfile -rA -s --make-reports=tests_pipelines_torch -m is_pipeline_test ./tests/ | tee tests_output.txt
218
            - store_artifacts:
219
220
221
222
                  path: ~/transformers/tests_output.txt
            - store_artifacts:
                  path: ~/transformers/reports

223
224
225
226
227
228
229
230
231
232
    run_tests_pipelines_tf:
        working_directory: ~/transformers
        docker:
            - image: circleci/python:3.7
        environment:
            OMP_NUM_THREADS: 1
        resource_class: xlarge
        parallelism: 1
        steps:
            - checkout
233
            - skip-job-on-doc-only-changes
234
235
            - restore_cache:
                  keys:
Lysandre Debut's avatar
Lysandre Debut committed
236
237
                      - v0.4-tf-{{ checksum "setup.py" }}
                      - v0.4-{{ checksum "setup.py" }}
238
            - run: pip install --upgrade pip
239
            - run: pip install .[sklearn,tf-cpu,testing,sentencepiece]
240
            - save_cache:
Lysandre Debut's avatar
Lysandre Debut committed
241
                  key: v0.4-tf-{{ checksum "setup.py" }}
242
243
                  paths:
                      - '~/.cache/pip'
244
245
246
            - run: RUN_PIPELINE_TESTS=1 python -m pytest -n 8 --dist=loadfile -rA -s --make-reports=tests_pipelines_tf ./tests/ -m is_pipeline_test | tee tests_output.txt
            - store_artifacts:
                  path: ~/transformers/tests_output.txt
247
            - store_artifacts:
248
249
                  path: ~/transformers/reports

Aymeric Augustin's avatar
Aymeric Augustin committed
250
    run_tests_custom_tokenizers:
251
252
        working_directory: ~/transformers
        docker:
253
            - image: circleci/python:3.7
254
255
        environment:
            RUN_CUSTOM_TOKENIZERS: yes
256
257
        steps:
            - checkout
258
            - skip-job-on-doc-only-changes
259
260
            - restore_cache:
                  keys:
Lysandre Debut's avatar
Lysandre Debut committed
261
262
                      - v0.4-custom_tokenizers-{{ checksum "setup.py" }}
                      - v0.4-{{ checksum "setup.py" }}
263
            - run: pip install --upgrade pip
264
            - run: pip install .[ja,testing,sentencepiece]
265
            - run: python -m unidic download
266
            - save_cache:
Lysandre Debut's avatar
Lysandre Debut committed
267
                  key: v0.4-custom_tokenizers-{{ checksum "setup.py" }}
268
269
                  paths:
                      - '~/.cache/pip'
270
271
272
            - run: python -m pytest -s --make-reports=tests_custom_tokenizers ./tests/test_tokenization_bert_japanese.py | tee tests_output.txt
            - store_artifacts:
                  path: ~/transformers/tests_output.txt
273
            - store_artifacts:
274
275
                  path: ~/transformers/reports

Aymeric Augustin's avatar
Aymeric Augustin committed
276
    run_examples_torch:
277
278
        working_directory: ~/transformers
        docker:
279
            - image: circleci/python:3.6
280
281
282
283
284
285
        environment:
            OMP_NUM_THREADS: 1
        resource_class: xlarge
        parallelism: 1
        steps:
            - checkout
286
            - skip-job-on-doc-only-changes
287
288
            - restore_cache:
                  keys:
Lysandre Debut's avatar
Lysandre Debut committed
289
290
                      - v0.4-torch_examples-{{ checksum "setup.py" }}
                      - v0.4-{{ checksum "setup.py" }}
291
            - run: pip install --upgrade pip
292
            - run: pip install .[sklearn,torch,sentencepiece,testing]
293
294
            - run: pip install -r examples/requirements.txt
            - save_cache:
Lysandre Debut's avatar
Lysandre Debut committed
295
                  key: v0.4-torch_examples-{{ checksum "setup.py" }}
296
297
                  paths:
                      - '~/.cache/pip'
298
            - run: python -m pytest -n 8 --dist=loadfile -s --make-reports=examples_torch ./examples/ | tee examples_output.txt
299
            - store_artifacts:
300
301
302
                  path: ~/transformers/examples_output.txt
            - store_artifacts:
                  path: ~/transformers/reports
303

304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
    run_tests_git_lfs:
        working_directory: ~/transformers
        docker:
            - image: circleci/python:3.7
        resource_class: xlarge
        parallelism: 1
        steps:
            - checkout
            - run: sudo apt-get install git-lfs
            - run: |
                git config --global user.email "ci@dummy.com"
                git config --global user.name "ci"
            - run: pip install --upgrade pip
            - run: pip install .[testing]
            - run: RUN_GIT_LFS_TESTS=1 python -m pytest -sv ./tests/test_hf_api.py -k "HfLargefilesTest"

320
321
322
323
324
325
    build_doc:
        working_directory: ~/transformers
        docker:
            - image: circleci/python:3.6
        steps:
            - checkout
326
327
            - restore_cache:
                  keys:
Lysandre Debut's avatar
Lysandre Debut committed
328
329
                      - v0.4-build_doc-{{ checksum "setup.py" }}
                      - v0.4-{{ checksum "setup.py" }}
330
            - run: pip install --upgrade pip
331
            - run: pip install ."[all, docs]"
332
            - save_cache:
Lysandre Debut's avatar
Lysandre Debut committed
333
                  key: v0.4-build_doc-{{ checksum "setup.py" }}
334
335
                  paths:
                      - '~/.cache/pip'
336
            - run: cd docs && make html SPHINXOPTS="-W"
337
338
            - store_artifacts:
                path: ./docs/_build
339

LysandreJik's avatar
LysandreJik committed
340
    deploy_doc:
341
        working_directory: ~/transformers
LysandreJik's avatar
LysandreJik committed
342
        docker:
343
            - image: circleci/python:3.6
LysandreJik's avatar
LysandreJik committed
344
345
        steps:
            - add_ssh_keys:
346
347
                fingerprints:
                    - "5b:7a:95:18:07:8c:aa:76:4c:60:35:88:ad:60:56:71"
LysandreJik's avatar
LysandreJik committed
348
            - checkout
349
350
            - restore_cache:
                  keys:
Lysandre Debut's avatar
Lysandre Debut committed
351
352
                      - v0.4-deploy_doc-{{ checksum "setup.py" }}
                      - v0.4-{{ checksum "setup.py" }}
353
            - run: pip install ."[all,docs]"
354
            - save_cache:
Lysandre Debut's avatar
Lysandre Debut committed
355
                  key: v0.4-deploy_doc-{{ checksum "setup.py" }}
356
357
                  paths:
                      - '~/.cache/pip'
Lysandre's avatar
Lysandre committed
358
            - run: ./.circleci/deploy.sh
359

Aymeric Augustin's avatar
Aymeric Augustin committed
360
361
362
363
    check_code_quality:
        working_directory: ~/transformers
        docker:
            - image: circleci/python:3.6
Aymeric Augustin's avatar
Aymeric Augustin committed
364
        resource_class: medium
Aymeric Augustin's avatar
Aymeric Augustin committed
365
366
367
        parallelism: 1
        steps:
            - checkout
368
369
            - restore_cache:
                  keys:
Lysandre Debut's avatar
Lysandre Debut committed
370
371
                      - v0.4-code_quality-{{ checksum "setup.py" }}
                      - v0.4-{{ checksum "setup.py" }}
372
            - run: pip install --upgrade pip
373
            - run: pip install isort
374
            - run: pip install .[all,quality]
375
            - save_cache:
Lysandre Debut's avatar
Lysandre Debut committed
376
                  key: v0.4-code_quality-{{ checksum "setup.py" }}
377
378
                  paths:
                      - '~/.cache/pip'
379
380
381
            - run: black --check examples tests src utils
            - run: isort --check-only examples tests src utils
            - run: flake8 examples tests src utils
Sylvain Gugger's avatar
Sylvain Gugger committed
382
            - run: python utils/style_doc.py src/transformers docs/source --max_len 119 --check_only
383
            - run: python utils/check_copies.py
384
            - run: python utils/check_dummies.py
385
            - run: python utils/check_repo.py
386

387
    check_repository_consistency:
R茅mi Louf's avatar
R茅mi Louf committed
388
389
        working_directory: ~/transformers
        docker:
390
            - image: circleci/python:3.6
R茅mi Louf's avatar
R茅mi Louf committed
391
392
393
394
        resource_class: small
        parallelism: 1
        steps:
            - checkout
395
            - run: pip install requests
R茅mi Louf's avatar
R茅mi Louf committed
396
            - run: python ./utils/link_tester.py
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416

# TPU JOBS
    run_examples_tpu:
        docker:
            - image: circleci/python:3.6
        environment:
            OMP_NUM_THREADS: 1
        resource_class: xlarge
        parallelism: 1
        steps:
            - checkout
            - go/install
            - *checkout_ml_testing
            - gcp-gke/install
            - gcp-gke/update-kubeconfig-with-credentials:
                  cluster: $GKE_CLUSTER
                  perform-login: true
            - setup_remote_docker
            - *build_push_docker
            - *deploy_cluster
417

418
419
420
421
422
423
424
425
426
    cleanup-gke-jobs:
        docker:
            - image: circleci/python:3.6
        steps:
            - gcp-gke/install
            - gcp-gke/update-kubeconfig-with-credentials:
                  cluster: $GKE_CLUSTER
                  perform-login: true
            - *delete_gke_jobs
427

LysandreJik's avatar
LysandreJik committed
428
429
430
431
workflow_filters: &workflow_filters
    filters:
        branches:
            only:
Lysandre's avatar
Lysandre committed
432
                - master
433
workflows:
LysandreJik's avatar
LysandreJik committed
434
435
436
    version: 2
    build_and_test:
        jobs:
Aymeric Augustin's avatar
Aymeric Augustin committed
437
            - check_code_quality
438
            - check_repository_consistency
Aymeric Augustin's avatar
Aymeric Augustin committed
439
440
441
442
443
            - run_examples_torch
            - run_tests_custom_tokenizers
            - run_tests_torch_and_tf
            - run_tests_torch
            - run_tests_tf
444
            - run_tests_flax
445
446
            - run_tests_pipelines_torch
            - run_tests_pipelines_tf
447
            - run_tests_git_lfs
448
            - build_doc
Lysandre's avatar
Lysandre committed
449
            - deploy_doc: *workflow_filters
Lysandre's avatar
Lysandre committed
450
451
452
453
454
455
456
457
458
459
460
461
    tpu_testing_jobs:
        triggers:
            - schedule:
                # Set to run at the first minute of every hour.
                cron: "0 8 * * *"
                filters:
                    branches:
                        only:
                            - master
        jobs:
            - cleanup-gke-jobs
            - run_examples_tpu