config.yml 14.4 KB
Newer Older
Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
1
2
3
4
5
6
7
# Python CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-python/ for more details
#
# Adopted from
# https://github.com/facebookresearch/detectron2/blob/master/.circleci/config.yml

Min Xu's avatar
Min Xu committed
8
version: 2.1
Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
9
10
11
12

# -------------------------------------------------------------------------------------
# Environments to run the jobs in
# -------------------------------------------------------------------------------------
13
cpu_py37: &cpu_py37
Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
14
15
16
17
  docker:
    - image: circleci/python:3.7
  resource_class: medium

18
19
20
21
22
23
24
25
26
27
cpu_py38: &cpu_py38
  docker:
    - image: circleci/python:3.8
  resource_class: medium

cpu_py39: &cpu_py39
  docker:
    - image: circleci/python:3.9
  resource_class: medium

Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
gpu: &gpu
  environment:
    CUDA_VERSION: "10.1"
  machine:
    image: ubuntu-1604-cuda-10.1:201909-23
  resource_class: gpu.large

# -------------------------------------------------------------------------------------
# Re-usable commands
# -------------------------------------------------------------------------------------
setup_venv: &setup_venv
  - run:
      name: Setup Virtual Env
      working_directory: ~/
      command: |
        python -m venv ~/venv
        echo ". ~/venv/bin/activate" >> $BASH_ENV
        . ~/venv/bin/activate
        python --version
        which python
        which pip
        pip install --upgrade pip

51
install_dep_151: &install_dep_151
Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
52
  - run:
53
      name: Install Dependencies with torch 1.5.1
Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
54
      command: |
55
        sudo apt-get install -y libopenmpi-dev
56
        pip install --progress-bar off torch==1.5.1+cu101 torchvision==0.6.1+cu101 -f https://download.pytorch.org/whl/torch_stable.html
Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
57
        pip install --progress-bar off -r requirements-test.txt
58
        pip install --progress-bar off -r requirements-benchmarks.txt
Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
59
        python -c 'import torch; print("Torch version:", torch.__version__)'
60
        python -c 'import torch; assert torch.__version__.split(".")[:2] == ["1", "5"], "wrong torch version"'
Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
61
62
        python -m torch.utils.collect_env

63
install_dep_160: &install_dep_160
64
  - run:
65
      name: Install Dependencies with torch 1.6.0
66
      command: |
67
        sudo apt-get install -y libopenmpi-dev
68
        pip install --progress-bar off torch==1.6.0+cu101 torchvision==0.7.0+cu101 -f https://download.pytorch.org/whl/torch_stable.html
69
        pip install --progress-bar off -r requirements-test.txt
70
        pip install --progress-bar off -r requirements-benchmarks.txt
71
        pip install --progress-bar off git+https://github.com/msbaines/torch_pg.git@c85c96f#egg=torch-pg
72
        python -c 'import torch; print("Torch version:", torch.__version__)'
73
        python -c 'import torch; assert torch.__version__.split(".")[:2] == ["1", "6"], "wrong torch version"'
74
75
        python -m torch.utils.collect_env

76
install_dep_171: &install_dep_171
77
  - run:
78
      name: Install Dependencies with torch 1.7.1
79
80
      command: |
        sudo apt-get install -y libopenmpi-dev
81
        pip install --progress-bar off torch==1.7.1+cu101 torchvision==0.8.2+cu101 -f https://download.pytorch.org/whl/torch_stable.html
82
        pip install --progress-bar off -r requirements-test.txt
83
        pip install --progress-bar off -r requirements-benchmarks.txt
84
85
        pip install --progress-bar off git+https://github.com/msbaines/torch_pg.git@c85c96f#egg=torch-pg
        python -c 'import torch; print("Torch version:", torch.__version__)'
86
        python -c 'import torch; assert torch.__version__.split(".")[:2] == ["1", "7"], "wrong torch version"'
87
88
        python -m torch.utils.collect_env

89
90
91
92
93
94
95
96
97
98
99
100
101
102
install_dep_180: &install_dep_180
  - run:
      name: Install Dependencies with torch 1.8.0 nightly
      command: |
        sudo apt-get install -y libopenmpi-dev
        pip install --pre --progress-bar off torch==1.8.0.dev20210128+cu110 -f https://download.pytorch.org/whl/nightly/cu110/torch_nightly.html
        pip install --progress-bar off  git+https://github.com/min-xu-ai/torch_pg.git@c723ab4#egg=torch-pg
        pip install --progress-bar off -r requirements-test.txt
        # TODO: We don't use 180 to run benchmark yet, because torchvision is not yet available on py39.
        #pip install --progress-bar off -r requirements-benchmarks.txt
        python -c 'import torch; print("Torch version:", torch.__version__)'
        python -c 'import torch; assert torch.__version__.split(".")[:2] == ["1", "8"], "wrong torch version"'
        python -m torch.utils.collect_env

Jun Ru Anderson's avatar
Jun Ru Anderson committed
103
install_repo_cpu: &install_repo_cpu
Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
104
105
106
  - run:
      name: Install Repository
      command: |
107
108
109
        pip install .
        # Test import.
        python -c 'import sys; sys.path = sys.path[1:]; import fairscale'
Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
110

Jun Ru Anderson's avatar
Jun Ru Anderson committed
111
112
113
114
115
install_repo_gpu: &install_repo_gpu
  - run:
      name: Install Repository
      command: |
        export CUDA_HOME=/usr/local/cuda-10.1
116
        pip install -e .
msbaines's avatar
msbaines committed
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

run_isort: &run_isort
   - run:
       name: Run Linter (isort)
       command: |
         isort . --check

run_black: &run_black
   - run:
       name: Run Linter (black)
       command: |
         black --check .

run_mypy: &run_mypy
   - run:
       name: Run type-checking (mypy)
       command: |
         mypy --ignore-missing-imports --scripts-are-modules --pretty .

run_flake8: &run_flake8
  - run:
      name: Run Linter (flake8)
      command: |
        flake8 --show-source --statistics


Min Xu's avatar
Min Xu committed
144
145
146
147
# TODO (Min): figure out how to do coverage nightly or on-demand. Doing it
# on every commit seems like an overkill since we can easily figure out which
# code is not covered without looking at coverage results from each commit.
# Also, it is a long pole for testing time, which slows down development a lot.
msbaines's avatar
msbaines committed
148
149
150
151
run_coverage: &run_coverage
  - run:
      name: Run Unit Tests With Coverage
      command: |
152
        pytest --junitxml=test-results/junit.xml --verbose --timeout 60 --cov-report=xml --cov=./
msbaines's avatar
msbaines committed
153
154
155
        #Uploading test coverage for Python code
        bash <(curl -s https://codecov.io/bash) -f coverage.xml -cF Python

156
157
158
159
run_mpi_unittests: &run_mpi_unittests
  - run:
      name: Run MPI Unit Tests
      command: |
160
        mpirun -n 4 python -m pytest -p torch_pg.pytest --only-mpi --junitxml=test-results/junit.xml --verbose tests/nn/moe
161

Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
162

Jun Ru Anderson's avatar
Jun Ru Anderson committed
163
run_pipe_benchmark: &run_pipe_benchmark
Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
164
  - run:
Jun Ru Anderson's avatar
Jun Ru Anderson committed
165
      name: Run Pipe Benchmark
Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
166
      command: |
Jun Ru Anderson's avatar
Jun Ru Anderson committed
167
        python benchmarks/pipe.py
Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
168

169
170
171
172
run_mp_pipe_benchmark: &run_mp_pipe_benchmark
  - run:
      name: Run Multiprocess Pipe Benchmark
      command: |
173
        python benchmarks/pipe.py --multiprocess --lazy-construction
174

175
176
177
178
run_oss_benchmark: &run_oss_benchmark
  - run:
      name: Run OSS Benchmark
      command: |
179
        python benchmarks/oss.py --world_size 4 --epochs 2
180
        python benchmarks/oss.py --check_regression --world_size 4 --optim_type oss_sharded_ddp
181
182

run_oss_gloo: &run_oss_gloo
183
184
185
186
187
188
  - run:
      name: Run OSS with Gloo
      command: |
        python benchmarks/oss.py --gloo --optim_type oss_ddp --epochs 2
        python benchmarks/oss.py --gloo --optim_type oss_sharded_ddp --epochs 2

189
run_oss_amp: &run_oss_amp
190
191
192
193
194
   - run:
       name: Run OSS with Torch AMP
       command: |
         python benchmarks/oss.py --amp --epochs 3 --optim_type oss_sharded_ddp

195
196
197
198
199
200
run_oss_for_each: &run_oss_for_each
   - run:
       name: Run OSS with Torch AMP and ForEach optmizer
       command: |
         python benchmarks/oss.py --amp --epochs 3 --optim_type oss_sharded_ddp --multi_tensor_optim

201
202
203
204
205
206
207
208
209
210

run_doc_build: &run_doc_build
   - run:
       name: Testing doc build
       command: |
         cd docs
         pip install --progress-bar off -r requirements.txt
         make help
         make singlehtml | tee make.out
         ! tail make.out | grep -q warning
211

Min Xu's avatar
Min Xu committed
212
213
214
215
216
217
218
219
220
221
222
223
commands:
   run_unittests:
     parameters:
       test_dir:
         type: string
         default: "."  # Default to run all tests, which may take a long time on GPUs.
     steps:
       - run:
           name: Run Unit Tests
           command: |
             pytest --junitxml=test-results/junit.xml --verbose --timeout 60 <<parameters.test_dir>>

Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
224
225
226
227
228
# -------------------------------------------------------------------------------------
# Jobs to run
# -------------------------------------------------------------------------------------

jobs:
229
230
  cpu_tests_py37:
    <<: *cpu_py37
Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
231
232
233
234
235
236
237
238
239
240

    working_directory: ~/fairscale

    steps:
      - checkout
      - <<: *setup_venv

      # Cache the venv directory that contains dependencies
      - restore_cache:
          keys:
241
            - cache-key-cpu-py37-171-{{ checksum "setup.py"}}-{{ checksum "requirements-test.txt"}}
Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
242

243
      - <<: *install_dep_171
Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
244
245
246
247

      - save_cache:
          paths:
            - ~/venv
248
          key: cache-key-cpu-py37-171-{{ checksum "setup.py"}}-{{ checksum "requirements-test.txt"}}
Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
249

Jun Ru Anderson's avatar
Jun Ru Anderson committed
250
      - <<: *install_repo_cpu
Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
251

252
253
254
255
      - <<: *run_isort
      - <<: *run_black
      - <<: *run_mypy
      - <<: *run_flake8
Min Xu's avatar
Min Xu committed
256
      - run_unittests
257
258
259
260
261
      - <<: *run_mpi_unittests
      - <<: *run_doc_build

      - store_test_results:
          path: test-results
Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
262

263
264
  cpu_tests_py38:
    <<: *cpu_py38
Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
265

266
    working_directory: ~/fairscale
Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
267

268
269
270
    steps:
      - checkout
      - <<: *setup_venv
Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
271

272
273
274
275
276
277
278
279
280
281
282
283
284
      # Cache the venv directory that contains dependencies
      - restore_cache:
          keys:
            - cache-key-cpu-py38-171-{{ checksum "setup.py"}}-{{ checksum "requirements-test.txt"}}

      - <<: *install_dep_171

      - save_cache:
          paths:
            - ~/venv
          key: cache-key-cpu-py38-171-{{ checksum "setup.py"}}-{{ checksum "requirements-test.txt"}}

      - <<: *install_repo_cpu
Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
285

286
287
288
289
      - <<: *run_isort
      - <<: *run_black
      - <<: *run_mypy
      - <<: *run_flake8
Min Xu's avatar
Min Xu committed
290
      - run_unittests
291
      - <<: *run_mpi_unittests
292
      - <<: *run_doc_build
293

Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
294
295
296
      - store_test_results:
          path: test-results

297
298
299
300
301
302
303
304
305
306
307
308
  cpu_tests_py39:
    <<: *cpu_py39

    working_directory: ~/fairscale

    steps:
      - checkout
      - <<: *setup_venv

      # Cache the venv directory that contains dependencies
      - restore_cache:
          keys:
309
            - cache-key-cpu-py39-180-{{ checksum "setup.py"}}-{{ checksum "requirements-test.txt"}}
310

311
312
313
314
315
      # py3.9 doesn't work well with torch < 1.8. See this PR:
      # https://github.com/pytorch/pytorch/pull/50998
      #
      # Therefore, we test py39 with torch 1.8.0.
      - <<: *install_dep_180
316
317
318
319

      - save_cache:
          paths:
            - ~/venv
320
          key: cache-key-cpu-py39-180-{{ checksum "setup.py"}}-{{ checksum "requirements-test.txt"}}
321
322
323
324
325
326
327

      - <<: *install_repo_cpu

      - <<: *run_isort
      - <<: *run_black
      - <<: *run_mypy
      - <<: *run_flake8
Min Xu's avatar
Min Xu committed
328
      - run_unittests
329
      - <<: *run_mpi_unittests
330
331
332
333
334
335
      - <<: *run_doc_build

      - store_test_results:
          path: test-results


336
  gpu_tests_151:
Min Xu's avatar
Min Xu committed
337
338
339
340
341
    parameters:
      test_dir:
        type: string
        default: "."
      
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
    <<: *gpu

    working_directory: ~/fairscale

    steps:
      - checkout

      - run: nvidia-smi

      - run: pyenv global 3.7.0

      - <<: *setup_venv

      # Cache the venv directory that contains dependencies
      - restore_cache:
          keys:
358
            - cache-key-gpu-151-{{ checksum "setup.py"}}-{{ checksum "requirements-test.txt"}}
359

360
      - <<: *install_dep_151
361
362
363
364

      - save_cache:
          paths:
            - ~/venv
365
          key: cache-key-gpu-151-{{ checksum "setup.py"}}-{{ checksum "requirements-test.txt"}}
366
367
368

      - <<: *install_repo_gpu

Min Xu's avatar
Min Xu committed
369
370
      - run_unittests:
          test_dir: <<parameters.test_dir>>
371
372
373
374

      - store_test_results:
          path: test-results

375
  gpu_tests_160:
Min Xu's avatar
Min Xu committed
376
377
378
379
380
    parameters:
      test_dir:
        type: string
        default: "."

Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
    <<: *gpu

    working_directory: ~/fairscale

    steps:
      - checkout

      - run: nvidia-smi

      - run: pyenv global 3.7.0

      - <<: *setup_venv

      # Cache the venv directory that contains dependencies
      - restore_cache:
          keys:
397
            - cache-key-gpu-160-{{ checksum "setup.py"}}-{{ checksum "requirements-test.txt"}}
Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
398

399
      - <<: *install_dep_160
Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
400
401
402
403

      - save_cache:
          paths:
            - ~/venv
404
          key: cache-key-gpu-160-{{ checksum "setup.py"}}-{{ checksum "requirements-test.txt"}}
Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
405

Jun Ru Anderson's avatar
Jun Ru Anderson committed
406
      - <<: *install_repo_gpu
Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
407

Min Xu's avatar
Min Xu committed
408
409
      - run_unittests:
          test_dir: <<parameters.test_dir>>
Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
410
411
412
413

      - store_test_results:
          path: test-results

414
  gpu_tests_171:
Min Xu's avatar
Min Xu committed
415
416
417
418
419
    parameters:
      test_dir:
        type: string
        default: "."

420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
    <<: *gpu

    working_directory: ~/fairscale

    steps:
      - checkout

      - run: nvidia-smi

      - run: pyenv global 3.7.0

      - <<: *setup_venv

      # Cache the venv directory that contains dependencies
      - restore_cache:
          keys:
436
            - cache-key-gpu-171-{{ checksum "setup.py"}}-{{ checksum "requirements-test.txt"}}
437

438
      - <<: *install_dep_171
439
440
441
442

      - save_cache:
          paths:
            - ~/venv
443
          key: cache-key-gpu-171-{{ checksum "setup.py"}}-{{ checksum "requirements-test.txt"}}
444
445
446

      - <<: *install_repo_gpu

Min Xu's avatar
Min Xu committed
447
448
      - run_unittests:
          test_dir: <<parameters.test_dir>>
449
450
451
452

      - store_test_results:
          path: test-results

Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
453
454
455
456
457
458
459
460
461
462
  benchmarks:
    <<: *gpu

    working_directory: ~/fairscale

    steps:
      - checkout

      - run: nvidia-smi

463
464
465
466
      - run: pyenv uninstall -f 3.7.0

      - run: pyenv install 3.7.0

Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
467
468
469
470
471
472
473
      - run: pyenv global 3.7.0

      - <<: *setup_venv

      # Cache the venv directory that contains dependencies
      - restore_cache:
          keys:
474
            - cache-key-benchmarks-{{ checksum "setup.py"}}-{{ checksum "requirements-test.txt"}}
Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
475

476
      - <<: *install_dep_171
Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
477
478
479
480

      - save_cache:
          paths:
            - ~/venv
481
          key: cache-key-benchmarks-{{ checksum "setup.py"}}-{{ checksum "requirements-test.txt"}}
Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
482

Jun Ru Anderson's avatar
Jun Ru Anderson committed
483
      - <<: *install_repo_gpu
Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
484

Jun Ru Anderson's avatar
Jun Ru Anderson committed
485
      - <<: *run_pipe_benchmark
Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
486

487
488
      - <<: *run_mp_pipe_benchmark

489
490
      - <<: *run_oss_benchmark

491
492
      - <<: *run_oss_gloo

493
494
      - <<: *run_oss_amp

495
      - <<: *run_oss_for_each
496

497

Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
498
499
500
501
502

workflows:
  version: 2
  build:
    jobs:
503
504
505
      - cpu_tests_py37
      - cpu_tests_py38
      - cpu_tests_py39
Min Xu's avatar
Min Xu committed
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
      - gpu_tests_151:
          test_dir: tests/experimental
      - gpu_tests_160:
          test_dir: tests/experimental
      - gpu_tests_171:
          test_dir: tests/experimental
      - gpu_tests_151:
          test_dir: tests/nn
      - gpu_tests_160:
          test_dir: tests/nn
      - gpu_tests_171:
          test_dir: tests/nn
      - gpu_tests_151:
          test_dir: tests/optim
      - gpu_tests_160:
          test_dir: tests/optim
      - gpu_tests_171:
          test_dir: tests/optim
      - gpu_tests_151:
          test_dir: tests/utils
      - gpu_tests_160:
          test_dir: tests/utils
      - gpu_tests_171:
          test_dir: tests/utils
Mandeep Singh Baines's avatar
Mandeep Singh Baines committed
530
      - benchmarks