Skip to content

Instantly share code, notes, and snippets.

@zabir-nabil
Created June 21, 2023 05:15
Show Gist options
  • Save zabir-nabil/1049d4a6ee82d4c53beee02182b0e03c to your computer and use it in GitHub Desktop.
Save zabir-nabil/1049d4a6ee82d4c53beee02182b0e03c to your computer and use it in GitHub Desktop.
# Speaker Experiments and MLflow
Speaker experiments take relatively long time to finish. For tracking the experiment progress, we can utilize MLflow.
### What is MLflow?
MLflow is a platform to streamline machine learning development, including tracking experiments, packaging code into reproducible runs, and sharing and deploying models. MLflow offers a set of lightweight APIs that can be used with any existing machine learning application or library (TensorFlow, PyTorch, XGBoost, etc), wherever you currently run ML code (e.g. in notebooks, standalone applications or the cloud). MLflow's current components are:
* MLflow Tracking: An API to log parameters, code, and results in machine learning experiments and compare them using an interactive UI.
* MLflow Projects: A code packaging format for reproducible runs using Conda and Docker, so you can share your ML code with others.
* MLflow Models: A model packaging format and tools that let you easily deploy the same model (from any ML library) to batch and real-time scoring on platforms such as Docker, Apache Spark, Azure ML and AWS SageMaker.
* MLflow Model Registry: A centralized model store, set of APIs, and UI, to collaboratively manage the full lifecycle of MLflow Models.
### MLflow env
MLflow is deployed at `http://192.168.1.76:8005`
* user: `mlflow`
* pass: `mlflow`
### Why?
Having a common platform to store the results of different experiments. Tracking would be easy.
### How to track an experiment in MLflow?
In training code, we can use the following template to push the logs to mlflow. Before adding the code, you may need to create an experiment in MLflow UI.
Pass the mlflow experiment_id to the code.
```
import os
from random import random, randint
from mlflow import mlflow,log_metric, log_param, log_params, log_artifacts
from mlflow.exceptions import MlflowException
MLFLOW_EXP_ID = 1 # manually provide this after creating an exp. in mlflow UI
mlflow.set_tracking_uri('http://192.168.1.76:8005')
os.environ['MLFLOW_TRACKING_USERNAME'] = 'mlflow'
os.environ['MLFLOW_TRACKING_PASSWORD'] = 'mlflow'
with mlflow.start_run(experiment_id = 1, run_name = "PROVIDE_A_TAG_FOR_THIS_RUN") as run:
log_param("model-tag", "xxx")
log_param("dataset-detailed-info-path", "ppp")
log_param("num_speakers_in_train", 17789)
multi_params = {'emb_size': 512, 'kernel_size': 3}
log_params(multi_params)
for epoch in range(50):
log_metric("accuracy", random(), step = epoch)
log_metric("mse", random(), step = epoch)
log_metric("eer", random(), step = epoch)
time.sleep(5)
```
You can find the experiment details here: http://192.168.1.76:8005
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment