pytorch-lightning
166 строк · 6.4 Кб
1# Python package
2# Create and test a Python package on multiple Python versions.
3# Add steps that analyze code, save the dist with the build record, publish to a PyPI-compatible index, and more:
4# https://docs.microsoft.com/azure/devops/pipelines/languages/python
5
6trigger:7tags:8include: ["*"]9branches:10include:11- "master"12- "release/*"13- "refs/tags/*"14
15pr:16branches:17include:18- "master"19- "release/*"20paths:21include:22- ".actions/*"23- ".azure/gpu-tests-fabric.yml"24- "examples/fabric/**"25- "examples/run_fabric_examples.sh"26- "tests/run_standalone_*.sh"27- "requirements/fabric/**"28- "src/lightning/__init__.py"29- "src/lightning/__setup__.py"30- "src/lightning/__version__.py"31- "src/lightning/fabric/**"32- "src/lightning_fabric/*"33- "tests/tests_fabric/**"34- "pyproject.toml" # includes pytest config35exclude:36- "requirements/*/docs.txt"37- "*.md"38- "**/*.md"39
40jobs:41- job: testing42# how long to run the job before automatically cancelling43timeoutInMinutes: "20"44# how much time to give 'run always even if cancelled tasks' before stopping them45cancelTimeoutInMinutes: "2"46pool: lit-rtx-309047variables:48DEVICES: $( python -c 'print("$(Agent.Name)".split("_")[-1])' )49FREEZE_REQUIREMENTS: "1"50PIP_CACHE_DIR: "/var/tmp/pip"51PL_RUN_CUDA_TESTS: "1"52container:53image: $(image)54# default shm size is 64m. Increase it to avoid:55# 'Error while creating shared memory: unhandled system error, NCCL version 2.7.8'56options: "--gpus=all --shm-size=2gb -v /var/tmp:/var/tmp"57strategy:58matrix:59# TODO: Upgrade to Python 3.1160"Fabric | latest":61image: "pytorchlightning/pytorch_lightning:base-cuda-py3.10-torch2.2-cuda12.1.0"62PACKAGE_NAME: "fabric"63"Lightning | latest":64image: "pytorchlightning/pytorch_lightning:base-cuda-py3.10-torch2.2-cuda12.1.0"65PACKAGE_NAME: "lightning"66workspace:67clean: all68steps:69- bash: |70echo "##vso[task.setvariable variable=CUDA_VISIBLE_DEVICES]$(DEVICES)"
71cuda_ver=$(python -c "import torch ; print(''.join(map(str, torch.version.cuda.split('.')[:2])))")
72echo "##vso[task.setvariable variable=CUDA_VERSION_MM]$cuda_ver"
73echo "##vso[task.setvariable variable=TORCH_URL]https://download.pytorch.org/whl/cu${cuda_ver}/torch_stable.html"
74scope=$(python -c 'n = "$(PACKAGE_NAME)" ; print(dict(fabric="lightning_fabric").get(n, n))')
75echo "##vso[task.setvariable variable=COVERAGE_SOURCE]$scope"
76displayName: "set env. vars"77- bash: |78echo "##vso[task.setvariable variable=TORCH_URL]https://download.pytorch.org/whl/test/cu${CUDA_VERSION_MM}/torch_test.html"
79condition: endsWith(variables['Agent.JobName'], 'future')80displayName: "set env. vars 4 future"81
82- bash: |83echo $(DEVICES)
84echo $CUDA_VISIBLE_DEVICES
85echo $CUDA_VERSION_MM
86echo $TORCH_URL
87echo $COVERAGE_SOURCE
88whereis nvidia
89nvidia-smi
90which python && which pip
91python --version
92pip --version
93pip list
94displayName: "Image info & NVIDIA"95
96- bash: |97PYTORCH_VERSION=$(python -c "import torch; print(torch.__version__.split('+')[0])")
98pip install -q wget packaging
99python -m wget https://raw.githubusercontent.com/Lightning-AI/utilities/main/scripts/adjust-torch-versions.py
100for fpath in `ls requirements/**/*.txt`; do \
101python ./adjust-torch-versions.py $fpath ${PYTORCH_VERSION}; \
102done
103displayName: "Adjust dependencies"104
105- bash: |106extra=$(python -c "print({'lightning': 'fabric-'}.get('$(PACKAGE_NAME)', ''))")
107pip install -e ".[${extra}dev]" pytest-timeout -U --find-links="${TORCH_URL}"
108displayName: "Install package & dependencies"109
110- bash: |111set -e
112python requirements/collect_env_details.py
113python -c "import torch ; mgpu = torch.cuda.device_count() ; assert mgpu == 2, f'GPU: {mgpu}'"
114python -c "import bitsandbytes"
115displayName: "Env details"116
117- bash: python -m pytest lightning_fabric118workingDirectory: src119# without succeeded this could run even if the job has already failed120condition: and(succeeded(), eq(variables['PACKAGE_NAME'], 'fabric'))121displayName: "Testing: Fabric doctests"122
123- bash: |124pip install -q -r .actions/requirements.txt
125python .actions/assistant.py copy_replace_imports --source_dir="./tests/tests_fabric" \
126--source_import="lightning.fabric" \
127--target_import="lightning_fabric"
128python .actions/assistant.py copy_replace_imports --source_dir="./examples/fabric" \
129--source_import="lightning.fabric" \
130--target_import="lightning_fabric"
131# without succeeded this could run even if the job has already failed132condition: and(succeeded(), eq(variables['PACKAGE_NAME'], 'fabric'))133displayName: "Adjust tests & examples"134
135- bash: python -m coverage run --source ${COVERAGE_SOURCE} -m pytest . -v --durations=50136workingDirectory: tests/tests_fabric/137displayName: "Testing: fabric standard"138timeoutInMinutes: "10"139
140- bash: bash ../run_standalone_tests.sh "."141workingDirectory: tests/tests_fabric/142env:143PL_STANDALONE_TESTS_SOURCE: $(COVERAGE_SOURCE)144displayName: "Testing: fabric standalone"145timeoutInMinutes: "10"146
147- bash: |148python -m coverage report
149python -m coverage xml
150python -m coverage html
151
152# https://docs.codecov.com/docs/codecov-uploader153curl -Os https://uploader.codecov.io/latest/linux/codecov154chmod +x codecov
155./codecov --token=$(CODECOV_TOKEN) --commit=$(Build.SourceVersion) \156--flags=gpu,pytest,${COVERAGE_SOURCE} --name="GPU-coverage" --env=linux,azure157ls -l158workingDirectory: tests/tests_fabric/159displayName: "Statistics"160
161- script: |162set -e
163bash run_fabric_examples.sh --accelerator=cuda --devices=1
164bash run_fabric_examples.sh --accelerator=cuda --devices=2 --strategy ddp
165workingDirectory: examples/166displayName: "Testing: fabric examples"167