-
Notifications
You must be signed in to change notification settings - Fork 876
/
Copy pathjustfile
228 lines (193 loc) · 7.67 KB
/
justfile
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
set dotenv-load
set positional-arguments
KERAS_BACKEND := env("KERAS_BACKEND", "tensorflow")
MLFLOW_TRACKING_URI := env("MLFLOW_TRACKING_URI", "http://127.0.0.1:5000")
ENDPOINT_NAME := env("ENDPOINT_NAME", "penguins")
BUCKET := env("BUCKET", "")
AWS_REGION := env("AWS_REGION", "us-east-1")
AWS_ROLE := env("AWS_ROLE", "")
default:
@just --list
# Run project unit tests
test:
uv run -- pytest
# Display version of required dependencies
[group('setup')]
@dependencies:
uv_version=$(uv --version) && \
just_version=$(just --version) && \
docker_version=$(docker --version | awk '{print $3}' | sed 's/,//') && \
jq_version=$(jq --version | awk -F'-' '{print $2}') && \
echo "uv: $uv_version" && \
echo "just: $just_version" && \
echo "docker: $docker_version" && \
echo "jq: $jq_version"
# Run MLflow server
[group('setup')]
@mlflow:
uv run -- mlflow server --host 127.0.0.1 --port 5000
# Set up required environment variables
[group('setup')]
@env:
echo "KERAS_BACKEND={{KERAS_BACKEND}}\nMLFLOW_TRACKING_URI={{MLFLOW_TRACKING_URI}}" > .env
cat .env
# Run training pipeline
[group('training')]
@train:
uv run -- python pipelines/training.py \
--environment conda run
# Run training pipeline card server
[group('training')]
@train-viewer:
uv run -- python pipelines/training.py \
--environment conda card server
# Serve latest registered model locally
[group('serving')]
@serve:
uv run -- mlflow models serve \
-m models:/penguins/$(curl -s -X GET "{{MLFLOW_TRACKING_URI}}/api/2.0/mlflow/registered-models/get-latest-versions" \
-H "Content-Type: application/json" -d '{"name": "penguins"}' \
| jq -r '.model_versions[0].version') -h 0.0.0.0 -p 8080 --no-conda
# Invoke local running model with sample request
[group('serving')]
@invoke:
uv run -- curl -X POST http://0.0.0.0:8080/invocations \
-H "Content-Type: application/json" \
-d '{"inputs": [{"island": "Biscoe", "culmen_length_mm": 48.6, "culmen_depth_mm": 16.0, "flipper_length_mm": 230.0, "body_mass_g": 5800.0, "sex": "MALE" }]}'
# Display number of records in SQLite database
[group('serving')]
@sqlite:
uv run -- sqlite3 penguins.db "SELECT COUNT(*) FROM data;"
# Generate fake traffic to local running model
[group('monitoring')]
@traffic:
uv run -- python pipelines/traffic.py \
--environment conda run \
--samples 200
# Generate fake labels in SQLite database
[group('monitoring')]
@labels:
uv run -- python pipelines/labels.py \
--environment conda run
# Run the monitoring pipeline
[group('monitoring')]
@monitor:
uv run -- python pipelines/monitoring.py \
--config backend-config config/local.json \
--environment conda run
# Run monitoring pipeline card server
[group('monitoring')]
@monitor-viewer:
uv run -- python pipelines/monitoring.py \
--environment conda card server \
--port 8334
# Deploy MLflow Cloud Formation stack
[group('aws')]
@aws-mlflow:
aws cloudformation create-stack \
--stack-name mlflow \
--template-body file://cloud-formation/mlflow-cfn.yaml
# Create mlschool.pem file
[group('aws')]
@aws-pem:
aws ssm get-parameters \
--names "/ec2/keypair/$(aws cloudformation describe-stacks \
--stack-name mlflow \
--query "Stacks[0].Outputs[?OutputKey=='KeyPair'].OutputValue" \
--output text)" \
--with-decryption | python3 -c 'import json;import sys;o = json.load(sys.stdin);print(o["Parameters"][0]["Value"])' > mlschool.pem
chmod 400 mlschool.pem
# Connect to the MLflow remote server
[group('aws')]
@aws-remote:
ssh -i "mlschool.pem" ubuntu@$(aws cloudformation \
describe-stacks --stack-name mlflow \
--query "Stacks[0].Outputs[?OutputKey=='PublicDNS'].OutputValue" \
--output text)
# Deploy model to Sagemaker
[group('aws')]
@sagemaker-deploy:
uv run -- python pipelines/deployment.py \
--config backend-config config/sagemaker.json \
--environment conda run \
--backend backend.Sagemaker
# Invoke Sagemaker endpoint with sample request
[group('aws')]
@sagemaker-invoke:
awscurl --service sagemaker --region "$AWS_REGION" \
$(aws sts assume-role --role-arn "$AWS_ROLE" \
--role-session-name mlschool-session \
--profile "$AWS_USERNAME" --query "Credentials" \
--output json | \
jq -r '"--access_key \(.AccessKeyId) --secret_key \(.SecretAccessKey) --session_token \(.SessionToken)"' \
) -X POST -H "Content-Type: application/json" \
-d '{"inputs": [{"island": "Biscoe", "culmen_length_mm": 48.6, "culmen_depth_mm": 16.0, "flipper_length_mm": 230.0, "body_mass_g": 5800.0, "sex": "MALE" }] }' \
https://runtime.sagemaker."$AWS_REGION".amazonaws.com/endpoints/"$ENDPOINT_NAME"/invocations
# Delete Sagemaker endpoint
[group('aws')]
@sagemaker-delete:
aws sagemaker delete-endpoint --endpoint-name "$ENDPOINT_NAME"
# Generate fake traffic to Sagemaker endpoint
[group('aws')]
@sagemaker-traffic:
uv run -- python pipelines/traffic.py \
--config backend-config config/sagemaker.json \
--environment conda run \
--backend backend.Sagemaker \
--samples 200
# Generate fake labels in SQLite database
[group('aws')]
@sagemaker-labels:
uv run -- python pipelines/labels.py \
--config backend-config config/sagemaker.json \
--environment conda run \
--backend backend.Sagemaker
# Run monitoring pipeline card server
[group('aws')]
@sagemaker-monitor-viewer:
uv run -- python pipelines/monitoring.py \
--environment conda card server \
# Run the monitoring pipeline
[group('aws')]
@sagemaker-monitor:
uv run -- python pipelines/monitoring.py \
--config backend-config config/sagemaker.json \
--environment conda run \
--backend backend.Sagemaker
# Run training pipeline in AWS
[group('aws')]
@aws-train:
METAFLOW_PROFILE=production uv run -- python pipelines/training.py \
--environment conda run \
--with batch \
--with retry
# Create a state machine for the training pipeline in AWS Step Functions
[group('aws')]
@aws-train-sfn-create:
METAFLOW_PROFILE=production uv run -- python pipelines/training.py \
--environment conda step-functions create
# Trigger the training pipeline in AWS Step Functions
[group('aws')]
@aws-train-sfn-trigger:
METAFLOW_PROFILE=production uv run -- python pipelines/trainining.py \
--environment conda step-functions trigger
# Deploy model to Sagemaker
[group('aws')]
@aws-deploy:
METAFLOW_PROFILE=production uv run -- python pipelines/deployment.py \
--config-value backend-config '{"target": "{{ENDPOINT_NAME}}", "data-capture-uri": "s3://{{BUCKET}}/datastore", "ground-truth-uri": "s3://{{BUCKET}}/ground-truth", "region": "{{AWS_REGION}}", "assume-role": "{{AWS_ROLE}}"}' \
--environment conda run \
--backend backend.Sagemaker \
--with batch
# Create a state machine for the deployment pipeline in AWS Step Functions
[group('aws')]
@aws-deploy-sfn-create:
METAFLOW_PROFILE=production uv run -- python pipelines/deployment.py \
--config-value backend-config '{"target": "{{ENDPOINT_NAME}}", "data-capture-uri": "s3://{{BUCKET}}/datastore", "ground-truth-uri": "s3://{{BUCKET}}/ground-truth", "region": "{{AWS_REGION}}", "assume-role": "{{AWS_ROLE}}"}' \
--environment conda step-functions create
# Trigger the deployment pipeline in AWS Step Functions
[group('aws')]
@aws-deploy-sfn-trigger:
METAFLOW_PROFILE=production uv run -- python pipelines/deployment.py \
--environment conda step-functions trigger \
--backend backend.Sagemaker