# Python package # Create and test a Python package on multiple Python versions. # Add steps that analyze code, save the dist with the build record, publish to a PyPI-compatible index, and more: # https://docs.microsoft.com/azure/devops/pipelines/languages/python trigger: tags: include: - '*' branches: include: - "master" - "release/*" - "refs/tags/*" pr: - "master" - "release/*" variables: - name: continue value: '1' jobs: - job: testing strategy: matrix: 'PyTorch - stable': image: "pytorchlightning/pytorch_lightning:base-cuda-py3.9-torch1.12-cuda11.3.1" # how long to run the job before automatically cancelling timeoutInMinutes: "80" # how much time to give 'run always even if cancelled tasks' before stopping them cancelTimeoutInMinutes: "2" pool: azure-jirka-spot container: image: $(image) # default shm size is 64m. Increase it to avoid: # 'Error while creating shared memory: unhandled system error, NCCL version 2.7.8' options: "--runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=all --shm-size=512m" workspace: clean: all steps: - bash: | CHANGED_FILES=$(git diff --name-status origin/master -- . | awk '{print $2}') FILTER='src/pytorch_lightning|requirements/pytorch|tests/tests_pytorch|examples/pl_*' echo $CHANGED_FILES > changed_files.txt MATCHES=$(cat changed_files.txt | grep -E $FILTER) echo $MATCHES if [ -z "$MATCHES" ]; then echo "Skip" echo "##vso[task.setvariable variable=continue]0" else echo "Continue" echo "##vso[task.setvariable variable=continue]1" fi displayName: Skipper - bash: | lspci | egrep 'VGA|3D' whereis nvidia nvidia-smi which python && which pip python --version pip --version pip list displayName: 'Image info & NVIDIA' condition: eq(variables['continue'], '1') - bash: | set -e python -c "fname = 'requirements/pytorch/strategies.txt' ; lines = [line for line in open(fname).readlines() if 'horovod' not in line] ; open(fname, 'w').writelines(lines)" python -c "fname = 'requirements/pytorch/strategies.txt' ; lines = [line for line in open(fname).readlines() if 'bagua' not in line] ; open(fname, 'w').writelines(lines)" CUDA_VERSION_MM=$(python -c "import torch ; print(''.join(map(str, torch.version.cuda.split('.')[:2])))") pip install "bagua-cuda$CUDA_VERSION_MM>=0.9.0" pip install -e .[strategies] pip install -U deepspeed # TODO: remove when docker images are upgraded pip install --requirement requirements/pytorch/devel.txt pip list env: PACKAGE_NAME: pytorch FREEZE_REQUIREMENTS: 1 displayName: 'Install dependencies' condition: eq(variables['continue'], '1') - bash: | set -e python requirements/collect_env_details.py python -c "import torch ; mgpu = torch.cuda.device_count() ; assert mgpu >= 2, f'GPU: {mgpu}'" python requirements/pytorch/check-avail-strategies.py python requirements/pytorch/check-avail-extras.py displayName: 'Env details' condition: eq(variables['continue'], '1') - bash: bash .actions/pull_legacy_checkpoints.sh displayName: 'Get legacy checkpoints' condition: eq(variables['continue'], '1') - bash: python -m coverage run --source pytorch_lightning -m pytest workingDirectory: src/pytorch_lightning displayName: 'Testing: PyTorch doctests' condition: eq(variables['continue'], '1') - bash: python -m coverage run --source pytorch_lightning -m pytest --ignore benchmarks -v --junitxml=$(Build.StagingDirectory)/test-results.xml --durations=50 env: PL_RUN_CUDA_TESTS: "1" workingDirectory: tests/tests_pytorch displayName: 'Testing: PyTorch standard' timeoutInMinutes: "35" condition: eq(variables['continue'], '1') - bash: bash run_standalone_tests.sh workingDirectory: tests/tests_pytorch env: PL_USE_MOCKED_MNIST: "1" PL_RUN_CUDA_TESTS: "1" displayName: 'Testing: PyTorch standalone tests' timeoutInMinutes: "35" condition: eq(variables['continue'], '1') - bash: | python -m coverage report python -m coverage xml python -m coverage html python -m codecov --token=$(CODECOV_TOKEN) --commit=$(Build.SourceVersion) --flags=gpu,pytest --name="GPU-coverage" --env=linux,azure ls -l workingDirectory: tests/tests_pytorch displayName: 'Statistics' condition: eq(variables['continue'], '1') - task: PublishTestResults@2 displayName: 'Publish test results' inputs: testResultsFiles: '$(Build.StagingDirectory)/test-results.xml' testRunTitle: '$(Agent.OS) - $(Build.DefinitionName) - Python $(python.version)' condition: and(succeededOrFailed(), eq(variables['continue'], '1')) - script: | set -e bash run_ddp_examples.sh bash run_pl_examples.sh --trainer.accelerator=gpu --trainer.devices=1 bash run_pl_examples.sh --trainer.accelerator=gpu --trainer.devices=2 --trainer.strategy=ddp bash run_pl_examples.sh --trainer.accelerator=gpu --trainer.devices=2 --trainer.strategy=ddp --trainer.precision=16 workingDirectory: examples env: PL_USE_MOCKED_MNIST: "1" displayName: 'Testing: PyTorch examples' condition: eq(variables['continue'], '1') - bash: python -m pytest benchmarks -v --maxfail=2 --durations=0 workingDirectory: tests/tests_pytorch env: PL_RUN_CUDA_TESTS: "1" displayName: 'Testing: PyTorch benchmarks' condition: eq(variables['continue'], '1')