Skip to content

Commit

Permalink
feat: add built-in run_test_experiment job to test the mlflow server …
Browse files Browse the repository at this point in the history
…internally so its super easy to test if it actually works e2e
  • Loading branch information
Tomasz Dłuski committed Nov 5, 2023
1 parent 1e92560 commit e9030c8
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 9 deletions.
19 changes: 19 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,25 @@ services:
command: tcp db:3306 -t 90s -i 250ms
networks:
- internal
run_test_experiment:
build:
context: ./test_experiment
dockerfile: Dockerfile
depends_on:
- "mlflow"
environment:
- AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
- AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
- AWS_DEFAULT_REGION=${AWS_REGION}
- MLFLOW_S3_ENDPOINT_URL=http://s3:9000
- MLFLOW_TRACKING_URI=http://mlflow:5000
entrypoint: >
/bin/sh -c "
python3 mlflow_tracking.py;
exit 0;
"
networks:
- internal
networks:
internal:
public:
Expand Down
12 changes: 6 additions & 6 deletions quickstart/mlflow_tracking.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import os
from random import random, randint

from mlflow import mlflow,log_metric, log_param, log_artifacts
import mlflow

if __name__ == "__main__":
with mlflow.start_run() as run:
mlflow.set_tracking_uri('http://localhost:5000')
print("Running mlflow_tracking.py")

log_param("param1", randint(0, 100))
mlflow.log_param("param1", randint(0, 100))

log_metric("foo", random())
log_metric("foo", random() + 1)
log_metric("foo", random() + 2)
mlflow.log_metric("foo", random())
mlflow.log_metric("foo", random() + 1)
mlflow.log_metric("foo", random() + 2)

if not os.path.exists("outputs"):
os.makedirs("outputs")
with open("outputs/test.txt", "w") as f:
f.write("hello world!")

log_artifacts("outputs")
mlflow.log_artifacts("outputs")
5 changes: 2 additions & 3 deletions mlflow/Dockerfile → test_experiment/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
FROM continuumio/miniconda3:latest

RUN pip install mlflow boto3 pymysql
RUN pip install mlflow boto3

ADD . /app
WORKDIR /app

COPY . .
22 changes: 22 additions & 0 deletions test_experiment/mlflow_tracking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import os
from random import random, randint

import mlflow

if __name__ == "__main__":
with mlflow.start_run() as run:
mlflow.set_tracking_uri('http://mlflow:5000')
print("Running mlflow_tracking.py")

mlflow.log_param("param1", randint(0, 100))

mlflow.log_metric("foo", random())
mlflow.log_metric("foo", random() + 1)
mlflow.log_metric("foo", random() + 2)

if not os.path.exists("outputs"):
os.makedirs("outputs")
with open("outputs/test.txt", "w") as f:
f.write("hello world!")

mlflow.log_artifacts("outputs")

0 comments on commit e9030c8

Please sign in to comment.