Setup focuses on experiment and artifact tracking using mlflow.
Requires poetry, docker and docker compose.
poetry installBuild image, set environment variables, and start containers (within docker folder)
cd docker && \
./build_image.sh \
--repository localhost/mlflow \
--tag latest && \
\
echo '#!/bin/bash
# mlflow settings
export MLFLOW_PORT=5000
export POSTGRES_DATA=$(pwd)/data/pgdata
export STORAGE_DATA=$(pwd)/data/storage
# db settings
export POSTGRES_USER=mlflow
export POSTGRES_PASSWORD=mlflow123
# (optional) mlflow s3 storage backend settings (e.g. can be minio)
# export MLFLOW_ARTIFACTS_DESTINATION=s3://yourbucketname/yourfolder
# export AWS_ACCESS_KEY_ID=youraccesskey
# export AWS_SECRET_ACCESS_KEY=yoursecretaccesskey
# export MLFLOW_S3_ENDPOINT_URL=https://minio.yourdomain.com
# export MLFLOW_S3_IGNORE_TLS=true' > .env.sh && \
\
source .env.sh && \
\
if [ ! -d "./data/pgdata" ] ; then mkdir -p $POSTGRES_DATA; fi && \
if [ ! -d "./data/storage" ] ; then mkdir -p $STORAGE_DATA; fi && \
\
docker compose up -dNow checkout http://localhost:5000.
Run sample tracking script
poetry run python samples/tracking.pyRun sample artifact script
poetry run python samples/artifacts.pyNavigate to http://localhost:5000 to see the MLflow UI and the experiment tracking.
Using plain python and mlflow server.
Using poetry. Runs and artifacts are stored in the mlruns and mlartifacts directories.
poetry install && \
poetry run mlflow server --host 0.0.0.0Using postgres as backend.
docker run -d --name ml-postgres -p 5432:5432 \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=postgres_password \
-e POSTGRES_DB=mlflow \
postgres:latestRuns mlflow server with postgres backend (only psycopg2 supported)
poetry run mlflow server --backend-store-uri postgresql+psycopg2://postgres:postgres_password@localhost:5432/mlflow --host 0.0.0.0Run sample tracking script
poetry run python samples/tracking.pySet S3 credentials and endpoint URL
echo '
export AWS_ACCESS_KEY_ID=...
export AWS_SECRET_ACCESS_KEY=...
export MLFLOW_S3_ENDPOINT_URL=...
' > .env.shStart mlflow server with s3 backend (default)
source .env.sh && \
poetry run mlflow server \
--backend-store-uri postgresql+psycopg2://postgres:postgres_password@localhost:5432/mlflow \
--default-artifact-root s3://my-bucket/mlflow/test \
--host 0.0.0.0Run (client reqpuires s3 credentials)
source .env.sh && \
poetry run python samples/artifacts.pyProxied s3 backend for artifacts (client do not need to know s3 credentials)
source .env.sh && \
poetry run mlflow server \
--backend-store-uri postgresql+psycopg2://postgres:postgres_password@localhost:5432/mlflow \
--artifacts-destination s3://my-bucket/mlflow/test \
--host 0.0.0.0Run (client do not need to know s3 credentials)
poetry run python samples/artifacts.pySet azure credentials and endpoint URL - more info here and here.
echo "
export AZURE_STORAGE_CONNECTION_STRING='AccountName=<YOUR_ACCOUNT_NAME>;AccountKey=<YOUR_KEY>;EndpointSuffix=core.windows.net;DefaultEndpointsProtocol=https;'
export AZURE_STORAGE_ACCESS_KEY='<YOUR_KEY>'
" > .env_azure.shProxied azure blob storage backend for artifacts (client do not need to know azure credentials)
source .env_azure.sh && \
poetry run mlflow server \
--backend-store-uri postgresql+psycopg2://postgres:postgres_password@localhost:5432/mlflow \
--artifacts-destination wasbs://my-container@my-storage-account.blob.core.windows.net/my-folder \
--host 0.0.0.0Run (client do not need to know azure credentials)
poetry run python samples/artifacts.pyUsing prometheus as metrics backend.
source .env.sh && \
poetry run mlflow server \
--backend-store-uri postgresql+psycopg2://postgres:postgres_password@localhost:5432/mlflow \
--artifacts-destination s3://my-bucket/mlflow/test \
--expose-prometheus ./metrics \
--host 0.0.0.0Starting from MLflow 3.5+, the server defaults to uvicorn and includes security middleware for DNS rebinding and CORS protection. When running behind a reverse proxy, configure --allowed-hosts and --cors-allowed-origins accordingly. The following describes a corresponding config map for Kubernetes deployments:
apiVersion: v1
kind: ConfigMap
metadata:
name: mlflow-additional-config
data:
MLFLOW_HOST: "0.0.0.0"
MLFLOW_PORT: "5000"
MLFLOW_ADDITIONAL_OPTIONS: "--allowed-hosts mlflow.example.com --cors-allowed-origins https://mlflow.example.com"Note: --allowed-hosts and --cors-allowed-origins are only supported with the default uvicorn server and cannot be used together with --gunicorn-opts.
Create env file containing API keys and secrets
echo '#!/bin/bash
# openai
export OPENAI_API_KEY=yoursecretkey
export OPENAI_API_KEY2=yoursecretkey
# anthropic
export ANTHROPIC_API_KEY=yoursecretkey' > .env-deployments-server.shStart mlflow deployments server with additional options
source .env-deployments-server.sh && \
mlflow deployments start-server --config-path samples/config.yaml --workers 4Run samples after starting the deployments server
poetry run python samples/completions.pypoetry run python samples/embeddings.pypoetry run python samples/chat.py