File size: 4,871 Bytes
9e7b284
 
 
 
 
2b5c395
4f7a99d
9e7b284
 
 
4f7a99d
9e7b284
 
 
 
 
 
 
 
 
 
 
1bcc0f7
 
 
9e7b284
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1bcc0f7
9e7b284
 
 
 
 
1bcc0f7
9e7b284
 
 
 
 
 
1bcc0f7
9e7b284
 
1bcc0f7
9e7b284
 
 
1bcc0f7
 
 
 
9e7b284
 
1bcc0f7
 
9e7b284
3b72aa1
1bcc0f7
9e7b284
 
 
 
 
1bcc0f7
 
 
9e7b284
1bcc0f7
9e7b284
 
 
 
 
 
 
 
 
1bcc0f7
 
 
 
9e7b284
 
 
 
 
 
 
 
 
 
 
 
1bcc0f7
9e7b284
 
 
 
 
1bcc0f7
9e7b284
 
 
 
 
 
1bcc0f7
9e7b284
 
1bcc0f7
9e7b284
 
 
1bcc0f7
9e7b284
 
 
 
1bcc0f7
 
9e7b284
 
 
 
1bcc0f7
 
9e7b284
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
name: CI Pipeline

on:
  push:
    branches:
      - master
    #   - feat/pytorch-catdog-setup
  pull_request:
    branches:
      - main
  workflow_dispatch:

jobs:
  python_basic_test:
    name: Test current codebase and setup Python environment
    runs-on: self-hosted

    strategy:
      matrix:
        python-version: [3.10.15]

    env:
      AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
      AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
      AWS_REGION: ${{ secrets.AWS_REGION }}

    steps:
      - name: Configure AWS credentials
        uses: aws-actions/configure-aws-credentials@v4
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: ${{ secrets.AWS_REGION }}

      - name: Print branch name
        run: echo "Branch name is ${{ github.ref_name }}"

      - name: Checkout code
        uses: actions/checkout@v3

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

      - name: Install Poetry
        run: |
          python -m pip install --upgrade pip
          pip install poetry
          poetry config virtualenvs.in-project true

      - name: Cache Poetry dependencies
        uses: actions/cache@v3
        with:
          path: |
            .venv
            ~/.cache/pypoetry
          key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}
          restore-keys: |
            ${{ runner.os }}-poetry-

      - name: Install dependencies
        run: poetry install --no-root --no-interaction

      - name: Check Poetry environment
        run: poetry env info

      - name: Create .env file
        run: |
          echo "AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}" >> .env
          echo "AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}" >> .env
          echo "AWS_REGION=${AWS_REGION}" >> .env
          echo ".env file created"

      - name: Run lint checks
        run: poetry run flake8 . --exclude=.venv,tests,notebooks

      - name: black
        run: poetry run black . --exclude="(\.venv|tests|notebooks)"

  pytorch_code_test:
    name: Test PyTorch code
    runs-on: self-hosted

    env:
      AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
      AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
      AWS_REGION: ${{ secrets.AWS_REGION }}

    needs: python_basic_test

    strategy:
      matrix:
        python-version: [3.10.15]

    steps:
      - name: Configure AWS credentials
        uses: aws-actions/configure-aws-credentials@v4
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: ${{ secrets.AWS_REGION }}

      - name: Checkout code
        uses: actions/checkout@v3

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

      - name: Install Poetry
        run: |
          python -m pip install --upgrade pip
          pip install poetry
          poetry config virtualenvs.in-project true

      - name: Cache Poetry dependencies
        uses: actions/cache@v3
        with:
          path: |
            .venv
            ~/.cache/pypoetry
          key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}
          restore-keys: |
            ${{ runner.os }}-poetry-

      - name: Install dependencies
        run: poetry install --no-root --no-interaction

      - name: Check Poetry environment
        run: poetry env info

      - name: Get data from DVC
        run: |
          poetry run dvc pull || echo "No data to pull from DVC"

      - name: Run Train code
        run: |
          echo "Training the model"
          poetry run python -m src.train_optuna_callbacks experiment=catdog_experiment ++task_name=train ++train=True ++test=False || exit 1
          poetry run python -m src.create_artifacts

      - name: Run Test code
        run: |
          echo "Testing the model"
          poetry run python -m src.train_optuna_callbacks experiment=catdog_experiment ++task_name=test ++train=False ++test=True || exit 1

      - name: upload model checkpoints
        uses: actions/upload-artifact@v4
        with:
          name: model-checkpoints
          path: ./checkpoints/

      - name: upload logs
        uses: actions/upload-artifact@v4
        with:
          name: logs
          path: ./logs/

      - name: upload configs
        uses: actions/upload-artifact@v4
        with:
          name: configs
          path: ./configs/

      - name: upload artifacts
        uses: actions/upload-artifact@v4
        with:
          name: artifacts
          path: ./artifacts/