-
Notifications
You must be signed in to change notification settings - Fork 1
114 lines (96 loc) · 3.16 KB
/
docker-test.yml
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
name: ML Training and artifact generation Workflow with DHCR
# on:
# push:
# branches: [ main ]
# pull_request:
# branches: [ main ]
# workflow_dispatch:
on:
workflow_dispatch:
inputs:
min_accuracy:
description: 'Minimum required accuracy'
required: true
default: '0.95'
type: string
docker_image:
description: 'Minimum required accuracy'
default: ghcr.io/ajithvcoder/emlo4-session-05-ajithvcoder:latest
type: string
workflow_call:
inputs:
min_accuracy:
description: 'Minimum required accuracy'
required: true
default: '0.95'
type: string
docker_image:
description: 'Minimum required accuracy'
required: false
default: 'ghcr.io/ajithvcoder/emlo4-session-05-ajithvcoder:latest'
type: string
permissions: # Define permissions for this workflow
packages: write # Allow writing to packages
contents: read # Allow reading repository contents
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
train_and_create_artifacts:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Debug Docker Image Input
run: echo "docker image - ${{ inputs.docker_image }}"
- name: Pull DHCR Image
run: docker pull ${{ inputs.docker_image }}
- name: Run training in DHCR container
run: |
output=$(docker run --rm \
-v ${PWD}:/workspace \
${{ inputs.docker_image }} \
bash -c "python src/train.py --config-name=train experiment=catdog_ex trainer.max_epochs=5")
echo "$output"
# Extract accuracy and compare with threshold
val_acc=$(echo "$output" | grep -o "'val_acc': tensor([0-9.]*)" | grep -o "[0-9.]*")
echo "Validation accuracy: $val_acc"
# Compare accuracy with minimum required
min_acc=${{ inputs.min_accuracy }}
if (( $(echo "$val_acc < $min_acc" | bc -l) )); then
echo "::error::Validation accuracy ($val_acc) is below the required threshold ($min_acc)"
exit 1
fi
echo "val_accuracy=$val_acc" >> $GITHUB_OUTPUT
- name: Fix permissions
run: |
sudo chown -R $USER:$USER model_storage logs configs
- name: Upload model checkpoint
uses: actions/upload-artifact@v3
with:
name: model-checkpoint
path: model_storage/
retention-days: 20
- name: Upload training logs
uses: actions/upload-artifact@v3
with:
name: training-logs
path: logs/
retention-days: 20
- name: Upload config
uses: actions/upload-artifact@v3
with:
name: all-config
path: configs/
retention-days: 20