Skip to content

Commit

Permalink
add ci for dep check
Browse files Browse the repository at this point in the history
  • Loading branch information
ControlNet committed Feb 10, 2024
1 parent 35ace6b commit 7ad51b9
Show file tree
Hide file tree
Showing 3 changed files with 191 additions and 5 deletions.
184 changes: 184 additions & 0 deletions .github/workflows/dependency_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
name: Dependency Test
on:
push:
branches-ignore:
- "master"
pull_request:

jobs:
lib-import-test:
name: Lib Dependency Test
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]
torch-version: ["1.8.*", "1.9.*", "1.10.*", "1.11.*", "1.12.*", "1.13.*", "2.0.*", "2.1.*"]
include:
- torch-version: "1.8.*"
torchvision-version: "0.9.*"
- torch-version: "1.9.*"
torchvision-version: "0.10.*"
- torch-version: "1.10.*"
torchvision-version: "0.11.*"
- torch-version: "1.11.*"
torchvision-version: "0.12.*"
- torch-version: "1.12.*"
torchvision-version: "0.13.*"
- torch-version: "1.13.*"
torchvision-version: "0.14.*"
- torch-version: "2.0.*"
torchvision-version: "0.15.*"
- torch-version: "2.1.*"
torchvision-version: "0.16.*"
exclude:
- python-version: "3.6"
torch-version: "1.11.*"
- python-version: "3.6"
torch-version: "1.12.*"
- python-version: "3.6"
torch-version: "1.13.*"
- python-version: "3.6"
torch-version: "2.0.*"
- python-version: "3.6"
torch-version: "2.1.*"

- python-version: "3.7"
torch-version: "2.0.*"
- python-version: "3.7"
torch-version: "2.1.*"

- python-version: "3.10"
torch-version: "1.8.*"
- python-version: "3.10"
torch-version: "1.9.*"
- python-version: "3.10"
torch-version: "1.10.*"

- python-version: "3.11"
torch-version: "1.8.*"
- python-version: "3.11"
torch-version: "1.9.*"
- python-version: "3.11"
torch-version: "1.10.*"
- python-version: "3.11"
torch-version: "1.11.*"
- python-version: "3.11"
torch-version: "1.12.*"
- python-version: "3.11"
torch-version: "1.13.*"

steps:
- uses: actions/checkout@v3

- name: Set Swap Space
uses: pierotofy/set-swap-space@master
with:
swap-size-gb: 10

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
architecture: x64

- name: Install PyAV Dependencies for Python 3.6
if: matrix.python-version == '3.6'
run: |
sudo apt install -y libavformat-dev libavdevice-dev
pip install "av==6.*"
- name: Install dependencies
run: |
sudo apt install -y ffmpeg wget
pip install torch==${{ matrix.torch-version }}
pip install torchvision==${{ matrix.torchvision-version }}
pip install -r requirements.lib.txt
python init.py
- name: Set PYTHONPATH
run: echo "PYTHONPATH=$(pwd)/src" >> $GITHUB_ENV

- name: Run Import Test
run: python -c "from marlin_pytorch import Marlin"

script-import-test:
name: Script Dependency Test
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
torch-version: ["1.8.*", "1.9.*", "1.10.*", "1.11.*", "1.12.*", "1.13.*", "2.0.*", "2.1.*"]
include:
- torch-version: "1.8.*"
torchvision-version: "0.9.*"
- torch-version: "1.9.*"
torchvision-version: "0.10.*"
- torch-version: "1.10.*"
torchvision-version: "0.11.*"
- torch-version: "1.11.*"
torchvision-version: "0.12.*"
- torch-version: "1.12.*"
torchvision-version: "0.13.*"
- torch-version: "1.13.*"
torchvision-version: "0.14.*"
- torch-version: "2.0.*"
torchvision-version: "0.15.*"
- torch-version: "2.1.*"
torchvision-version: "0.16.*"
exclude:
- python-version: "3.7"
torch-version: "2.0.*"
- python-version: "3.7"
torch-version: "2.1.*"

- python-version: "3.10"
torch-version: "1.8.*"
- python-version: "3.10"
torch-version: "1.9.*"
- python-version: "3.10"
torch-version: "1.10.*"

- python-version: "3.11"
torch-version: "1.8.*"
- python-version: "3.11"
torch-version: "1.9.*"
- python-version: "3.11"
torch-version: "1.10.*"
- python-version: "3.11"
torch-version: "1.11.*"
- python-version: "3.11"
torch-version: "1.12.*"
- python-version: "3.11"
torch-version: "1.13.*"

steps:
- uses: actions/checkout@v3

- name: Set Swap Space
uses: pierotofy/set-swap-space@master
with:
swap-size-gb: 10

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
architecture: x64

- name: Install dependencies
run: |
sudo apt install -y ffmpeg wget
pip install torch==${{ matrix.torch-version }}
pip install torchvision==${{ matrix.torchvision-version }}
pip install -r requirements.txt
python init.py
- name: Set PYTHONPATH
run: echo "PYTHONPATH=$(pwd)/src" >> $GITHUB_ENV

- name: Run Import Test
run: |
python -c "from train import *"
python -c "from evaluate import *"
8 changes: 5 additions & 3 deletions model/classifier.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Optional, Union, Sequence, Dict, Literal, Any
from typing import Optional, Union, Sequence, Dict, Any

from pytorch_lightning import LightningModule
from torch import Tensor
from torch.nn import CrossEntropyLoss, Linear, Identity, BCEWithLogitsLoss
from torch.nn import CrossEntropyLoss, Linear, BCEWithLogitsLoss
from torch.optim import Adam
from torch.optim.lr_scheduler import ReduceLROnPlateau
from torchmetrics import Accuracy, AUROC
Expand All @@ -15,7 +15,7 @@ class Classifier(LightningModule):

def __init__(self, num_classes: int, backbone: str, finetune: bool,
marlin_ckpt: Optional[str] = None,
task: Literal["binary", "multiclass", "multilabel"] = "binary",
task: str = "binary",
learning_rate: float = 1e-4, distributed: bool = False
):
super().__init__()
Expand Down Expand Up @@ -47,6 +47,8 @@ def __init__(self, num_classes: int, backbone: str, finetune: bool,
self.loss_fn = BCEWithLogitsLoss()
self.acc_fn = Accuracy(task="binary", num_classes=1)
self.auc_fn = AUROC(task="binary", num_classes=1)
else:
raise ValueError(f"Unknown task: {task}, it should be one of 'binary', 'multiclass', 'multilabel'.")

@classmethod
def from_module(cls, model, learning_rate: float = 1e-4, distributed=False):
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
opencv-python>=4.6
numpy>=1.23
numpy>=1.21
einops~=0.4
torchvision>=0.12.0
torch
Expand All @@ -8,7 +8,7 @@ tqdm>=4.64.0
scikit-image>=0.19.3
matplotlib>=3.5.2
pillow>=9.2.0
pandas~=1.4.3
pandas>=1.3.0
marlin_pytorch==0.3.4
pytorch_lightning==1.7.*
ffmpeg-python>=0.2.0
Expand Down

0 comments on commit 7ad51b9

Please sign in to comment.