config.yml 18.8 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
            if test -n "$CIRCLE_PR_NUMBER"
15
            then
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
                echo $CIRCLE_PR_NUMBER
                resp=$(curl -Ls https://api.github.com/repos/huggingface/transformers/pulls/${CIRCLE_PR_NUMBER})
                user=$(jq -r .user.login \<<< $resp)   # PR creator username
                head_ref=$(jq -r .head.ref \<<< $resp) # PR user's branch name
                echo head_ref=$head_ref, user=$user
            fi
            
            if test -n "$user" && test -n "$head_ref"
            then
                git clone https://github.com/$user/transformers user-clone
                cd user-clone
                git checkout $head_ref
                fork_point_sha=$(git merge-base --fork-point master)
                cd -
            fi

            if test -n "$fork_point_sha" && test -n "$(git diff --name-only $fork_point_sha)"
            then
                git --no-pager diff --name-only $fork_point_sha
                if git diff --name-only $fork_point_sha | egrep -qv '\.(md|rst)$'
36
37
38
39
                then
                    echo "Non-docs were modified in this PR, proceeding normally"
                else
                    echo "Only docs were modified in this PR, quitting this job"
40
                    # enable skipping once we get this sorted out
41
                    # circleci step halt
42
                fi
43
            else
44
                echo "Not enough data to perform a skipping check - continuing the job"
45
46
            fi

47

48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# 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
64
                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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
                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" && \
87
88
89
                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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
                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
106
jobs:
Aymeric Augustin's avatar
Aymeric Augustin committed
107
    run_tests_torch_and_tf:
108
        working_directory: ~/transformers
109
        docker:
110
            - image: circleci/python:3.6
111
112
        environment:
            OMP_NUM_THREADS: 1
113
114
115
116
        resource_class: xlarge
        parallelism: 1
        steps:
            - checkout
117
            - skip-job-on-doc-only-changes
118
119
            - restore_cache:
                  keys:
Lysandre Debut's avatar
Lysandre Debut committed
120
121
                      - v0.4-torch_and_tf-{{ checksum "setup.py" }}
                      - v0.4-{{ checksum "setup.py" }}
122
            - run: pip install --upgrade pip
123
            - run: pip install .[sklearn,tf-cpu,torch,testing,sentencepiece]
124
            - save_cache:
Lysandre Debut's avatar
Lysandre Debut committed
125
                key: v0.4-{{ checksum "setup.py" }}
126
127
                paths:
                    - '~/.cache/pip'
128
            - 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
129
            - store_artifacts:
130
131
132
133
                  path: ~/transformers/tests_output.txt
            - store_artifacts:
                  path: ~/transformers/reports

Aymeric Augustin's avatar
Aymeric Augustin committed
134
    run_tests_torch:
135
        working_directory: ~/transformers
Julien Chaumond's avatar
Julien Chaumond committed
136
        docker:
137
            - image: circleci/python:3.7
138
139
        environment:
            OMP_NUM_THREADS: 1
140
        resource_class: xlarge
141
        parallelism: 1
Julien Chaumond's avatar
Julien Chaumond committed
142
143
        steps:
            - checkout
144
            - skip-job-on-doc-only-changes
145
146
            - restore_cache:
                  keys:
Lysandre Debut's avatar
Lysandre Debut committed
147
148
                      - v0.4-torch-{{ checksum "setup.py" }}
                      - v0.4-{{ checksum "setup.py" }}
149
            - run: pip install --upgrade pip
150
            - run: pip install .[sklearn,torch,testing,sentencepiece]
151
            - save_cache:
Lysandre Debut's avatar
Lysandre Debut committed
152
                  key: v0.4-torch-{{ checksum "setup.py" }}
153
154
                  paths:
                      - '~/.cache/pip'
155
            - run: python -m pytest -n 8 --dist=loadfile -s --make-reports=tests_torch ./tests/ | tee tests_output.txt
156
            - store_artifacts:
157
158
159
                  path: ~/transformers/tests_output.txt
            - store_artifacts:
                  path: ~/transformers/reports
Lysandre Debut's avatar
Lysandre Debut committed
160

Aymeric Augustin's avatar
Aymeric Augustin committed
161
    run_tests_tf:
162
        working_directory: ~/transformers
thomwolf's avatar
thomwolf committed
163
        docker:
164
            - image: circleci/python:3.7
165
166
        environment:
            OMP_NUM_THREADS: 1
thomwolf's avatar
thomwolf committed
167
168
169
170
        resource_class: xlarge
        parallelism: 1
        steps:
            - checkout
171
            - skip-job-on-doc-only-changes
172
173
            - restore_cache:
                  keys:
Lysandre Debut's avatar
Lysandre Debut committed
174
175
                      - v0.4-tf-{{ checksum "setup.py" }}
                      - v0.4-{{ checksum "setup.py" }}
176
            - run: pip install --upgrade pip
177
            - run: pip install .[sklearn,tf-cpu,testing,sentencepiece]
178
            - save_cache:
Lysandre Debut's avatar
Lysandre Debut committed
179
                  key: v0.4-tf-{{ checksum "setup.py" }}
180
181
                  paths:
                      - '~/.cache/pip'
182
            - run: python -m pytest -n 8 --dist=loadfile -rA -s --make-reports=tests_tf ./tests/ | tee tests_output.txt
183
            - store_artifacts:
184
185
186
187
                  path: ~/transformers/tests_output.txt
            - store_artifacts:
                  path: ~/transformers/reports

188
189
190
191
192
193
194
195
196
197
    run_tests_flax:
        working_directory: ~/transformers
        docker:
            - image: circleci/python:3.7
        environment:
            OMP_NUM_THREADS: 1
        resource_class: xlarge
        parallelism: 1
        steps:
            - checkout
198
            - skip-job-on-doc-only-changes
199
200
            - restore_cache:
                keys:
Lysandre Debut's avatar
Lysandre Debut committed
201
202
                    - v0.4-flax-{{ checksum "setup.py" }}
                    - v0.4-{{ checksum "setup.py" }}
203
            - run: pip install --upgrade pip
204
            - run: sudo pip install .[flax,sklearn,torch,testing,sentencepiece]
205
            - save_cache:
Lysandre Debut's avatar
Lysandre Debut committed
206
                  key: v0.4-flax-{{ checksum "setup.py" }}
207
208
                  paths:
                      - '~/.cache/pip'
209
            - run: python -m pytest -n 8 --dist=loadfile -rA -s --make-reports=tests_flax ./tests/ | tee tests_output.txt
210
            - store_artifacts:
211
212
213
214
                  path: ~/transformers/tests_output.txt
            - store_artifacts:
                  path: ~/transformers/reports

215
216
217
218
219
220
221
222
223
224
    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
225
            - skip-job-on-doc-only-changes
226
227
            - restore_cache:
                  keys:
Lysandre Debut's avatar
Lysandre Debut committed
228
229
                      - v0.4-torch-{{ checksum "setup.py" }}
                      - v0.4-{{ checksum "setup.py" }}
230
            - run: pip install --upgrade pip
231
            - run: pip install .[sklearn,torch,testing,sentencepiece]
232
            - save_cache:
Lysandre Debut's avatar
Lysandre Debut committed
233
                  key: v0.4-torch-{{ checksum "setup.py" }}
234
235
                  paths:
                      - '~/.cache/pip'
236
            - 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
237
            - store_artifacts:
238
239
240
241
                  path: ~/transformers/tests_output.txt
            - store_artifacts:
                  path: ~/transformers/reports

242
243
244
245
246
247
248
249
250
251
    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
252
            - skip-job-on-doc-only-changes
253
254
            - restore_cache:
                  keys:
Lysandre Debut's avatar
Lysandre Debut committed
255
256
                      - v0.4-tf-{{ checksum "setup.py" }}
                      - v0.4-{{ checksum "setup.py" }}
257
            - run: pip install --upgrade pip
258
            - run: pip install .[sklearn,tf-cpu,testing,sentencepiece]
259
            - save_cache:
Lysandre Debut's avatar
Lysandre Debut committed
260
                  key: v0.4-tf-{{ checksum "setup.py" }}
261
262
                  paths:
                      - '~/.cache/pip'
263
264
265
            - 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
266
            - store_artifacts:
267
268
                  path: ~/transformers/reports

Aymeric Augustin's avatar
Aymeric Augustin committed
269
    run_tests_custom_tokenizers:
270
271
        working_directory: ~/transformers
        docker:
272
            - image: circleci/python:3.7
273
274
        environment:
            RUN_CUSTOM_TOKENIZERS: yes
275
276
        steps:
            - checkout
277
            - skip-job-on-doc-only-changes
278
279
            - restore_cache:
                  keys:
Lysandre Debut's avatar
Lysandre Debut committed
280
281
                      - v0.4-custom_tokenizers-{{ checksum "setup.py" }}
                      - v0.4-{{ checksum "setup.py" }}
282
            - run: pip install --upgrade pip
283
            - run: pip install .[ja,testing,sentencepiece]
284
            - run: python -m unidic download
285
            - save_cache:
Lysandre Debut's avatar
Lysandre Debut committed
286
                  key: v0.4-custom_tokenizers-{{ checksum "setup.py" }}
287
288
                  paths:
                      - '~/.cache/pip'
289
290
291
            - 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
292
            - store_artifacts:
293
294
                  path: ~/transformers/reports

Aymeric Augustin's avatar
Aymeric Augustin committed
295
    run_examples_torch:
296
297
        working_directory: ~/transformers
        docker:
298
            - image: circleci/python:3.6
299
300
301
302
303
304
        environment:
            OMP_NUM_THREADS: 1
        resource_class: xlarge
        parallelism: 1
        steps:
            - checkout
305
            - skip-job-on-doc-only-changes
306
307
            - restore_cache:
                  keys:
Lysandre Debut's avatar
Lysandre Debut committed
308
309
                      - v0.4-torch_examples-{{ checksum "setup.py" }}
                      - v0.4-{{ checksum "setup.py" }}
310
            - run: pip install --upgrade pip
311
            - run: pip install .[sklearn,torch,sentencepiece,testing]
312
313
            - run: pip install -r examples/requirements.txt
            - save_cache:
Lysandre Debut's avatar
Lysandre Debut committed
314
                  key: v0.4-torch_examples-{{ checksum "setup.py" }}
315
316
                  paths:
                      - '~/.cache/pip'
317
            - run: python -m pytest -n 8 --dist=loadfile -s --make-reports=examples_torch ./examples/ | tee examples_output.txt
318
            - store_artifacts:
319
320
321
                  path: ~/transformers/examples_output.txt
            - store_artifacts:
                  path: ~/transformers/reports
322

323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
    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"

339
340
341
342
343
344
    build_doc:
        working_directory: ~/transformers
        docker:
            - image: circleci/python:3.6
        steps:
            - checkout
345
346
            - restore_cache:
                  keys:
Lysandre Debut's avatar
Lysandre Debut committed
347
348
                      - v0.4-build_doc-{{ checksum "setup.py" }}
                      - v0.4-{{ checksum "setup.py" }}
349
            - run: pip install --upgrade pip
350
            - run: pip install ."[all, docs]"
351
            - save_cache:
Lysandre Debut's avatar
Lysandre Debut committed
352
                  key: v0.4-build_doc-{{ checksum "setup.py" }}
353
354
                  paths:
                      - '~/.cache/pip'
355
            - run: cd docs && make html SPHINXOPTS="-W"
356
357
            - store_artifacts:
                path: ./docs/_build
358

LysandreJik's avatar
LysandreJik committed
359
    deploy_doc:
360
        working_directory: ~/transformers
LysandreJik's avatar
LysandreJik committed
361
        docker:
362
            - image: circleci/python:3.6
LysandreJik's avatar
LysandreJik committed
363
364
        steps:
            - add_ssh_keys:
365
366
                fingerprints:
                    - "5b:7a:95:18:07:8c:aa:76:4c:60:35:88:ad:60:56:71"
LysandreJik's avatar
LysandreJik committed
367
            - checkout
368
369
            - restore_cache:
                  keys:
Lysandre Debut's avatar
Lysandre Debut committed
370
371
                      - v0.4-deploy_doc-{{ checksum "setup.py" }}
                      - v0.4-{{ checksum "setup.py" }}
372
            - run: pip install ."[all,docs]"
373
            - save_cache:
Lysandre Debut's avatar
Lysandre Debut committed
374
                  key: v0.4-deploy_doc-{{ checksum "setup.py" }}
375
376
                  paths:
                      - '~/.cache/pip'
Lysandre's avatar
Lysandre committed
377
            - run: ./.circleci/deploy.sh
378

Aymeric Augustin's avatar
Aymeric Augustin committed
379
380
381
382
    check_code_quality:
        working_directory: ~/transformers
        docker:
            - image: circleci/python:3.6
Aymeric Augustin's avatar
Aymeric Augustin committed
383
        resource_class: medium
Aymeric Augustin's avatar
Aymeric Augustin committed
384
385
386
        parallelism: 1
        steps:
            - checkout
387
388
            - restore_cache:
                  keys:
Lysandre Debut's avatar
Lysandre Debut committed
389
390
                      - v0.4-code_quality-{{ checksum "setup.py" }}
                      - v0.4-{{ checksum "setup.py" }}
391
            - run: pip install --upgrade pip
392
            - run: pip install isort
393
            - run: pip install .[all,quality]
394
            - save_cache:
Lysandre Debut's avatar
Lysandre Debut committed
395
                  key: v0.4-code_quality-{{ checksum "setup.py" }}
396
397
                  paths:
                      - '~/.cache/pip'
398
399
400
            - 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
401
            - run: python utils/style_doc.py src/transformers docs/source --max_len 119 --check_only
402
            - run: python utils/check_copies.py
403
            - run: python utils/check_table.py
404
            - run: python utils/check_dummies.py
405
            - run: python utils/check_repo.py
406

407
    check_repository_consistency:
R茅mi Louf's avatar
R茅mi Louf committed
408
409
        working_directory: ~/transformers
        docker:
410
            - image: circleci/python:3.6
R茅mi Louf's avatar
R茅mi Louf committed
411
412
413
414
        resource_class: small
        parallelism: 1
        steps:
            - checkout
415
            - run: pip install requests
R茅mi Louf's avatar
R茅mi Louf committed
416
            - run: python ./utils/link_tester.py
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436

# 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
437

438
439
440
441
442
443
444
445
446
    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
447

LysandreJik's avatar
LysandreJik committed
448
449
450
451
workflow_filters: &workflow_filters
    filters:
        branches:
            only:
Lysandre's avatar
Lysandre committed
452
                - master
453
workflows:
LysandreJik's avatar
LysandreJik committed
454
455
456
    version: 2
    build_and_test:
        jobs:
Aymeric Augustin's avatar
Aymeric Augustin committed
457
            - check_code_quality
458
            - check_repository_consistency
Aymeric Augustin's avatar
Aymeric Augustin committed
459
460
461
462
463
            - run_examples_torch
            - run_tests_custom_tokenizers
            - run_tests_torch_and_tf
            - run_tests_torch
            - run_tests_tf
464
            - run_tests_flax
465
466
            - run_tests_pipelines_torch
            - run_tests_pipelines_tf
467
            - run_tests_git_lfs
468
            - build_doc
Lysandre's avatar
Lysandre committed
469
            - deploy_doc: *workflow_filters
Lysandre's avatar
Lysandre committed
470
471
472
473
474
475
476
477
478
479
480
481
    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