Skip to content

Mlflow

mlflow

MlflowCallback

MlflowCallback(step=None, nested=False)

Bases: Callback

LLMeter callback to log test run parameters and metrics to an MLFlow tracking server.

This callback integrates with MLflow to track and log parameters and metrics from LLMeter test runs. It can operate either in the current MLflow run context or create nested runs for each test.

Example
import mlflow
from llmeter.callbacks import MlflowCallback

with mlflow.start_run():
    runner = Runner(
        endpoint=endpoint,
        callbacks=[MlflowCallback()]
    )
    results = await runner.run()

Attributes:

Name Type Description
step int | None

Step number for MLflow metrics logging

nested bool

Whether to create nested runs for each test

parameters_names list

List of parameter names to log to MLflow

Parameters:

Name Type Description Default
step int | None

Passed through to mlflow.log_metrics

None
nested bool

By default (False) the externally-provided mlflow run context will be used. Set True to log under a new nested run with the name of the LLMeter Result.run_name.

False

Raises:

Type Description
ImportError

If MLflow is not installed

Source code in llmeter/callbacks/mlflow.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
def __init__(self, step: int | None = None, nested: bool = False) -> None:
    """Create an MlflowCallback

    Args:
        step (int | None, optional): Passed through to `mlflow.log_metrics`
        nested (bool, optional): By default (`False`) the externally-provided mlflow run context will be used.
            Set `True` to log under a new nested run with the name of the LLMeter
            `Result.run_name`.

    Raises:
        ImportError: If MLflow is not installed
    """
    super().__init__()
    self.step = step
    self.nested = nested
    # Check MLFlow is installed by polling any attribute on the module to trigger DeferredError
    mlflow.__version__

after_run async

after_run(result)

Callback method executed after an LLMeter test run completes.

Logs parameters and metrics to MLflow, either in the current run context or in a new nested run depending on the nested setting.

Parameters:

Name Type Description Default
result Result

LLMeter test run result containing parameters and metrics to log

required
Source code in llmeter/callbacks/mlflow.py
117
118
119
120
121
122
123
124
125
126
127
128
129
async def after_run(self, result: Result):
    """Callback method executed after an LLMeter test run completes.

    Logs parameters and metrics to MLflow, either in the current run context
    or in a new nested run depending on the `nested` setting.

    Args:
        result (Result): LLMeter test run result containing parameters and metrics to log
    """
    if self.nested:
        await self._log_nested_run(result)
        return
    await self._log_llmeter_run(result)