Skip to content

Fix how torch version is derived in ci/cd and clean up github actions #8

Fix how torch version is derived in ci/cd and clean up github actions

Fix how torch version is derived in ci/cd and clean up github actions #8

name: Test Matrix
on: [push, pull_request]
jobs:
tests:
runs-on: ${{ matrix.runner }}
strategy:
matrix:
package_manager: [pdm, pip]
device: [cpu, gpu]
include:
- device: cpu
runner: ubuntu-latest
torch_index: https://download.pytorch.org/whl/cpu
- device: gpu
runner: "cirun-aws-runner--${{ github.run_id }}"
torch_index: https://download.pytorch.org/whl/cu121
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Python 3.9
if: matrix.device == 'gpu'
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install PDM (if applicable)
if: matrix.package_manager == 'pdm'
run: |
python -m pip install pdm
- name: Configure and create PDM virtual environment (GPU)
if: matrix.package_manager == 'pdm' && matrix.device == 'gpu'
run: |
pdm config venv.in_project False
pdm config venv.location /opt/dlami/nvme/venv
pdm venv create --with-pip --venv /opt/dlami/nvme/venv
- name: Create virtual environment (PDM CPU)
if: matrix.package_manager == 'pdm' && matrix.device == 'cpu'
run: |
pdm venv create --with-pip
pdm use --venv in-project
- name: Determine PyTorch version
run: |
TORCH_VERSION=$(${{ matrix.package_manager == 'pdm' && 'pdm run python -m pip' || 'python -m pip' }} install --dry-run "." | grep "Would install" | grep -o 'torch-[0-9.]*' | awk -F'-' '{print $2}' | tail -n 1)
echo "TORCH_VERSION=$TORCH_VERSION" >> $GITHUB_ENV
- name: Install PyTorch
run: |
${{ matrix.package_manager == 'pdm' && 'pdm run python -m pip' || 'python -m pip' }} install "torch==$TORCH_VERSION" --index-url ${{ matrix.torch_index }}
- name: Install package (including dev dependencies)
run: |
${{ matrix.package_manager == 'pdm' && 'pdm install --group :all' || 'python -m pip install ".[dev]"' }}
- name: Print and check torch version
run: |
${{ matrix.package_manager == 'pdm' && 'pdm run' || '' }} python -c "import torch; print(torch.__version__)"
${{ matrix.package_manager == 'pdm' && 'pdm run' || '' }} python -c "import torch; assert ('+cpu' in torch.__version__) == (matrix.device == 'cpu')"
- name: Load cache data
uses: actions/cache/restore@v4
with:
path: tests/datastore_examples/npyfilesmeps/meps_example_reduced.tar.gz
key: ${{ runner.os }}-meps-reduced-example-data-v0.3.0
restore-keys: |
${{ runner.os }}-meps-reduced-example-data-v0.3.0
- name: Run tests
run: |
${{ matrix.package_manager == 'pdm' && 'pdm run' || '' }} pytest -vv -s
- name: Save cache data
uses: actions/cache/save@v4
with:
path: tests/datastore_examples/npyfilesmeps/meps_example_reduced.tar.gz
key: ${{ runner.os }}-meps-reduced-example-data-v0.3.0