MLflow

MLflow

MLflow는 실험 추적, 모델 관리, 평가, 관측성(트레이싱), 배포를 위한 종단 간 오픈소스 MLOps 플랫폼이에요. LiteLLM과의 통합은 OpenTelemetry와 호환되는 고급 관측성을 지원해요.

출처: 문서

본문

MLflow가 뭔가요? (What is MLflow?)

MLflow실험 추적, 모델 관리, 평가, 관측성(트레이싱), 배포를 위한 종단 간 오픈소스 MLOps 플랫폼이에요. MLflow는 팀이 함께 LLM 애플리케이션을 개발하고 개선하도록 돕죠.

MLflow의 LiteLLM 통합은 OpenTelemetry와 호환되는 고급 관측성을 지원해요.

시작하기 (Getting Started)

MLflow 설치:

uv add "litellm[mlflow]"

LiteLLM의 MLflow 자동 트레이싱을 활성화하려면:

import mlflow

mlflow.litellm.autolog()

# Alternative, you can set the callback manually in LiteLLM
# litellm.callbacks = ["mlflow"]

MLflow는 오픈소스이고 무료이므로 트레이스를 로깅하는 데 가입이나 API 키가 필요 없어요!

import litellm
import os

# Set your LLM provider's API key
os.environ["OPENAI_API_KEY"] = ""

# Call LiteLLM as usual
response = litellm.completion(
    model="gpt-5.6-luna",
    messages=[
      {"role": "user", "content": "Hi 👋 - i'm openai"}
    ]
)

MLflow UI를 열고 Traces 탭으로 가서 로깅된 트레이스를 확인해 주세요:

mlflow ui

도구 호출 트레이싱 (Tracing Tool Calls)

MLflow와 LiteLLM의 통합은 메시지 외에도 도구 호출 추적을 지원해요.

import mlflow

# Enable MLflow auto-tracing for LiteLLM
mlflow.litellm.autolog()

# Define the tool function.
def get_weather(location: str) -> str:
    if location == "Tokyo":
        return "sunny"
    elif location == "Paris":
        return "rainy"
    return "unknown"

# Define function spec
get_weather_tool = {
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "Get the current weather in a given location",
        "parameters": {
            "properties": {
                "location": {
                    "description": "The city and state, e.g., San Francisco, CA",
                    "type": "string",
                },
            },
            "required": ["location"],
            "type": "object",
        },
    },
}

# Call LiteLLM as usual
response = litellm.completion(
    model="gpt-5.6-luna",
    messages=[
      {"role": "user", "content": "What's the weather like in Paris today?"}
    ],
    tools=[get_weather_tool]
)

평가 (Evaluation)

MLflow LiteLLM 통합은 LLM에 대한 정성적 평가를 실행해 GenAI 애플리케이션을 평가하거나 모니터링할 수 있게 해줘요.

LiteLLM과 MLflow로 평가 스위트를 실행하는 완전한 가이드는 Evaluate LLMs Tutorial을 방문해 주세요.

OpenTelemetry 컬렉터로 트레이스 내보내기 (Exporting Traces to OpenTelemetry collectors)

MLflow 트레이스는 OpenTelemetry와 호환돼요. 환경 변수에 엔드포인트 URL을 설정하면 어떤 OpenTelemetry 컬렉터(예: Jaeger, Zipkin, Datadog, New Relic)로도 트레이스를 내보낼 수 있어요.

# Set the endpoint of the OpenTelemetry Collector
os.environ["OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"] = "http://localhost:4317/v1/traces"
# Optionally, set the service name to group traces
os.environ["OTEL_SERVICE_NAME"] = "<your-service-name>"

자세한 내용은 MLflow 문서를 참고해 주세요.

LiteLLM 트레이스와 애플리케이션 트레이스 결합 (Combine LiteLLM Trace with Your Application Trace)

LiteLLM은 에이전트 모델 같은 더 큰 LLM 애플리케이션의 일부인 경우가 많아요. MLflow Tracing을 사용하면 사용자 지정 Python 코드를 계측할 수 있고, 이를 LiteLLM 트레이스와 결합할 수 있어요.

import litellm
import mlflow
from mlflow.entities import SpanType

# Enable MLflow auto-tracing for LiteLLM
mlflow.litellm.autolog()


class CustomAgent:
    # Use @mlflow.trace to instrument Python functions.
    @mlflow.trace(span_type=SpanType.AGENT)
    def run(self, query: str):
        # do something

        while i < self.max_turns:
            response = litellm.completion(
                model="gpt-5.6-luna",
                messages=messages,
            )

            action = self.get_action(response)
            ...

    @mlflow.trace
    def get_action(llm_response):
        ...

이 접근 방식은 사용자 지정 Python 코드와 LiteLLM 호출을 결합한 통합 트레이스를 생성해요.

LiteLLM 프록시 서버 (LiteLLM Proxy Server)

의존성 (Dependencies)

LiteLLM 프록시 서버에서 mlflow를 사용하려면 docker 컨테이너에 mlflow 패키지를 설치해야 해요.

uv add "mlflow>=3.1.4"

구성 (Configuration)

LiteLLM 프록시 구성 파일에서 MLflow를 구성해 주세요:

model_list:
  - model_name: openai/*
    litellm_params:
      model: openai/*

litellm_settings:
  success_callback: ["mlflow"]
  failure_callback: ["mlflow"]

환경 변수 (Environment Variables)

Databricks 서비스와 함께 MLflow를 사용하려면 다음 필수 환경 변수를 설정해 주세요:

DATABRICKS_TOKEN="dapixxxxx"
DATABRICKS_HOST="https://dbc-xxxx.cloud.databricks.com"
MLFLOW_TRACKING_URI="databricks"
MLFLOW_REGISTRY_URI="databricks-uc"
MLFLOW_EXPERIMENT_ID="xxxx"

더 나은 트레이싱을 위한 태그 추가 (Adding Tags for Better Tracing)

트레이스 구성을 개선하고 MLflow에서 필터링하기 위해 요청에 사용자 지정 태그를 추가할 수 있어요. 태그는 작업 ID, 태스크 이름, 또는 사용자 지정 메타데이터로 트레이스를 분류하고 검색하는 데 도움을 줘요.

curl:

curl --location 'http://0.0.0.0:4000/chat/completions' \
    --header 'Content-Type: application/json' \
    --header "Authorization: Bearer ***" \
    --data '{
    "model": "gemini-3.8-flash",
    "messages": [
        {
        "role": "user",
        "content": "what llm are you"
        }
    ],
    "litellm_metadata": {
        "tags": ["jobID:214590dsff09fds", "taskName:run_page_classification"]
    }
}'

OpenAI Python SDK:

from openai import OpenAI

# Initialize the OpenAI client pointing to your LiteLLM proxy
client = OpenAI(
    api_key="sk-<your-litellm-api-key>",  # Your LiteLLM proxy API key
    base_url="http://0.0.0.0:4000"  # Your LiteLLM proxy URL
)

# Make a request with tags in metadata
response = client.chat.completions.create(
    model="gemini-3.8-flash",
    messages=[
        {
            "role": "user", 
            "content": "what llm are you"
        }
    ],
    extra_body={
        "litellm_metadata": {
            "tags": ["jobID:214590dsff09fds", "taskName:run_page_classification"]
        }
    }
)

지원 (Support)

더 알아보기 (Learn more)