0. 简介
MLflow 是一个开源平台,专门为了帮助机器学习的从业者和团队处理机器学习过程中的复杂性而设计。MLflow 关注机器学习项目的完整生命周期,确保每个阶段都是可管理的、可追溯的和可复现的。
MLflow 目前提供了几个关键的组件:
MLflow AI Gateway:通过安全、简单的API与最先进的 LLM 进行交互。
MLflow LLM Evaluate:简化LLM和提示的评估。
MLflow Tracking:记录和查询实验:代码、数据、配置和结果。
MLflow Projects:将数据科学代码打包成一种格式,可以在任何平台上重现运行。
MLflow Models:在不同的服务环境中部署机器学习模型。
Model Registry:在一个中心仓库中存储、注释、发现和管理模型。
1. 安装 MLFlow
pip install mlflow
2. 启动 Tracking UI
mlflow server --host 127.0.0.1 --port 8080
端口可以任意指定一个本地可用端口即可。
浏览器输入 http://localhost:5000 访问:
3. 创建实验
这里的实验类似于我们的project,独立的实验可以方便进行管理和查看
from mlflow import MlflowClient
client = MlflowClient(tracking_uri="http://127.0.0.1:8080")
all_experiments = client.search_experiments()
default_experiment = [
{"name": experiment.name, "lifecycle_stage": experiment.lifecycle_stage}
for experiment in all_experiments
if experiment.name == "Default"
][0]
# Provide an Experiment description that will appear in the UI
experiment_description = (
"This is the grocery forecasting project. "
"This experiment contains the produce models for apples."
)
# Provide searchable tags that define characteristics of the Runs that
# will be in this Experiment
experiment_tags = {
"project_name": "grocery-forecasting",
"store_dept": "produce",
"team": "store