-
Notifications
You must be signed in to change notification settings - Fork 0
209 lines (167 loc) · 8.21 KB
/
dataprep-train.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
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# Train model, evaluate and test champion model, build containerized model, and deploy model
name: Data Prep
on:
push:
branches: ["workflows"]
workflow_dispatch:
# schedule:
# - cron: '00 4 * * *' # Runs at 4:00 AM UTC every day
jobs:
deploy-azure-resources:
runs-on: ubuntu-latest
steps:
# Checks-out repository under $GITHUB_WORKSPACE, so the job can access it
# Use cache action to cache the virtual environment (https://stackoverflow.com/a/62639424)
- name: Checkout code
uses: actions/checkout@v4
- name: Login to Azure
uses: azure/#@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
# # Deploys ARM template to create Azure resources for training
# - name: Deploy ARM Template
# id: deploy-arm
# run: |
# az deployment group create --resource-group ${{ vars.RESOURCE_GROUP_NAME }} --template-file ./infrastructure/azure_train_resource.json --name TrainDeployment
# KEY_VAULT_NAME=$(az deployment group show --resource-group ${{ vars.RESOURCE_GROUP_NAME }} --name TrainDeployment --query 'properties.outputs.keyVaultName.value' -o tsv)
# echo "KEY_VAULT_NAME=$KEY_VAULT_NAME" >> $GITHUB_ENV
# echo "key_vault_name=$KEY_VAULT_NAME" >> $GITHUB_ENV
# env:
# GITHUB_OUTPUT: ${{ github.output }}
# - name: Check and Update AML Environment if Necessary
# run: |
# echo "Setting up Azure credentials..."
# AZURE_CREDENTIALS=$(echo '${{ secrets.AZURE_CREDENTIALS }}')
# CLIENT_ID=$(echo $AZURE_CREDENTIALS | jq -r '.clientId')
# CLIENT_SECRET=$(echo $AZURE_CREDENTIALS | jq -r '.clientSecret')
# TENANT_ID=$(echo $AZURE_CREDENTIALS | jq -r '.tenantId')
# echo "Upgrading Azure CLI..."
# az upgrade --yes --allow-preview false
# echo "Adding/upgrading Azure Machine Learning CLI extension..."
# az extension add --name ml --upgrade --yes --allow-preview false
# echo "Logging in to Azure..."
# az login --service-principal -u $CLIENT_ID -p $CLIENT_SECRET --tenant $TENANT_ID
# echo "Creating/updating Azure Machine Learning environment from YAML file..."
# az ml environment create --file aml-train-env.yml --resource-group ${{ vars.RESOURCE_GROUP_NAME }} --workspace-name ${{ vars.AML_WORKSPACE_NAME }}
# - name: Check if AML environment is updated
# id: diff
# run: |
# echo "Setting up Azure credentials..."
# AZURE_CREDENTIALS=$(echo '${{ secrets.AZURE_CREDENTIALS }}')
# CLIENT_ID=$(echo $AZURE_CREDENTIALS | jq -r '.clientId')
# CLIENT_SECRET=$(echo $AZURE_CREDENTIALS | jq -r '.clientSecret')
# TENANT_ID=$(echo $AZURE_CREDENTIALS | jq -r '.tenantId')
# echo "Upgrading Azure CLI..."
# az upgrade --yes --allow-preview false
# echo "Adding/upgrading Azure Machine Learning CLI extension..."
# az extension add --name ml --upgrade --yes --allow-preview false
# echo "Logging in to Azure..."
# az login --service-principal -u $CLIENT_ID -p $CLIENT_SECRET --tenant $TENANT_ID
# LATEST_VERSION=$(az ml environment list --resource-group ${{ vars.RESOURCE_GROUP_NAME }} --workspace-name ${{ vars.AML_WORKSPACE_NAME }} --query "[?name=='${{ vars.AML_TRAIN_ENV_NAME }}'].version" --output tsv | sort -V | tail -n1)
# if [ -z "$LATEST_VERSION" ]; then
# echo "Environment ${{ vars.AML_TRAIN_ENV_NAME }} not found. Setting update_required to true."
# echo "update_required=true" >> $GITHUB_ENV
# else
# echo "Latest version of ${{ vars.AML_TRAIN_ENV_NAME }} is $LATEST_VERSION"
# az ml environment show --name ${{ vars.AML_TRAIN_ENV_NAME }} --resource-group ${{ vars.RESOURCE_GROUP_NAME }} --workspace-name ${{ vars.AML_WORKSPACE_NAME }} --version $LATEST_VERSION --debug > current-env.yml
# if diff current-env.yml train-conda.yml; then
# echo "No changes in the environment. Skipping update."
# echo "update_required=false" >> $GITHUB_ENV
# else
# echo "Changes detected. Updating environment."
# echo "update_required=true" >> $GITHUB_ENV
# fi
# fi
# - name: Create or update Azure ML Environment
# if: steps.diff.outputs.update_required == 'true'
# run: |
# echo "Setting up Azure credentials..."
# AZURE_CREDENTIALS=$(echo '${{ secrets.AZURE_CREDENTIALS }}')
# CLIENT_ID=$(echo $AZURE_CREDENTIALS | jq -r '.clientId')
# CLIENT_SECRET=$(echo $AZURE_CREDENTIALS | jq -r '.clientSecret')
# TENANT_ID=$(echo $AZURE_CREDENTIALS | jq -r '.tenantId')
# echo "Upgrading Azure CLI..."
# az upgrade --yes --allow-preview false
# echo "Adding/upgrading Azure Machine Learning CLI extension..."
# az extension add --name ml --upgrade --yes --allow-preview false
# echo "Logging in to Azure..."
# az login --service-principal -u $CLIENT_ID -p $CLIENT_SECRET --tenant $TENANT_ID
# echo "Creating/updating Azure Machine Learning environment from YAML file..."
# az ml environment create --file aml-train-env.yml --resource-group ${{ vars.RESOURCE_GROUP_NAME }} --workspace-name ${{ vars.AML_WORKSPACE_NAME }}
# data-prep:
# runs-on: ubuntu-latest
# needs: deploy-azure-resources
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# - name: Set up Python 3.10.*
# uses: actions/setup-python@v4
# with:
# python-version: 3.10.*
# - name: Get pip cache dir
# id: pip-cache
# run: echo "PIP_CACHE_DIR=$(pip cache dir)" >> $GITHUB_ENV
# # Use cache action to cache the virtual environment
# - name: Cache pip dependencies
# uses: actions/cache@v3
# with:
# path: ${{ env.PIP_CACHE_DIR }}
# key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
# restore-keys: |
# ${{ runner.os }}-pip-
# - name: Install dependencies
# run: |
# make install
# - name: Add project path to sys.path
# run: |
# echo "PYTHONPATH=${{github.workspace}}" >> $GITHUB_ENV
# - name: Prepare data
# run: |
# make prep_data
# - name: Setup Feast
# run: |
# make setup_feast
# - name: Split data
# run: |
# make split_data
train:
runs-on: ubuntu-latest
# needs: data-prep
steps:
# Checks-out repository under $GITHUB_WORKSPACE, so the job can access it
# Use cache action to cache the virtual environment (https://stackoverflow.com/a/62639424)
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python 3.10.*
uses: actions/setup-python@v4
with:
python-version: 3.10.*
- name: Get pip cache dir
id: pip-cache
run: echo "PIP_CACHE_DIR=$(pip cache dir)" >> $GITHUB_ENV
# Use cache action to cache the virtual environment
- name: Cache pip dependencies
uses: actions/cache@v3
with:
path: ${{ env.PIP_CACHE_DIR }}
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
make install
- name: Add project path to sys.path
run: |
echo "PYTHONPATH=${{ github.workspace }}" >> $GITHUB_ENV
- name: Login to Azure
uses: azure/#@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Submit train.py to Azure Compute Cluster
run: |
echo "Upgrading Azure CLI..."
az upgrade --yes --allow-preview false
echo "Adding/upgrading Azure Machine Learning CLI extension..."
az extension add --name ml --upgrade --yes --allow-preview false
echo "Submitting training script to Azure ML Compute..."
az ml job create --file ./src/training/train.yml --resource-group ${{ vars.RESOURCE_GROUP_NAME }} --workspace-name ${{ vars.AML_WORKSPACE_NAME }}