Implementation:Mlflow Mlflow Log Param
| Knowledge Sources | |
|---|---|
| Domains | ML_Ops, Experiment_Tracking |
| Last Updated | 2026-02-13 20:00 GMT |
Overview
Concrete tool for recording experiment hyperparameters and configuration values within an MLflow run, provided by the MLflow library.
Description
mlflow.log_param and mlflow.log_params are fluent API functions for recording key-value parameter pairs under the currently active MLflow run. log_param logs a single parameter, while log_params logs a dictionary of parameters in a single batch operation. Both convert values to strings before storage. If no run is active when either function is called, a new run is automatically created.
Usage
Use log_param for individual hyperparameters that are determined dynamically during script execution. Use log_params when logging a configuration dictionary or argparse namespace all at once. Call these functions within an active run context (inside a with mlflow.start_run() block or after calling mlflow.start_run()). Set synchronous=False in high-throughput scenarios where logging latency is a concern.
Code Reference
Source Location
- Repository: mlflow
- File:
mlflow/tracking/fluent.py - Lines (log_param): L827-861
- Lines (log_params): L1255-1298
Signature
def log_param(
key: str,
value: Any,
synchronous: bool | None = None,
) -> Any: ...
def log_params(
params: dict[str, Any],
synchronous: bool | None = None,
run_id: str | None = None,
) -> RunOperations | None: ...
Import
import mlflow
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| key | str | Yes (log_param) | Parameter name. May contain alphanumerics, underscores, dashes, periods, spaces, and slashes. Maximum length 250 characters in all backend stores. |
| value | Any | Yes (log_param) | Parameter value. Will be converted to a string if not already. Maximum length 6000 characters in all built-in backend stores. |
| params | dict[str, Any] | Yes (log_params) | Dictionary mapping parameter names to values. All values are string-ified before storage. |
| synchronous | bool or None | No | If True, blocks until the parameter is logged. If False, logs asynchronously and returns a future. If None, reads from MLFLOW_ENABLE_ASYNC_LOGGING (defaults to False).
|
| run_id | str or None | No (log_params only) | If specified, logs parameters to the given run instead of the active run. |
Outputs
| Name | Type | Description |
|---|---|---|
| (log_param return) | Any | When synchronous=True, returns the parameter value as passed. When synchronous=False, returns a RunOperations instance representing the pending logging operation.
|
| (log_params return) | RunOperations or None | When synchronous=True, returns None. When synchronous=False, returns a RunOperations future for the batch logging operation.
|
Usage Examples
Basic Usage
import mlflow
with mlflow.start_run():
# Log individual parameters
mlflow.log_param("learning_rate", 0.01)
mlflow.log_param("optimizer", "adam")
mlflow.log_param("epochs", 100)
Batch Parameter Logging
import mlflow
params = {
"learning_rate": 0.01,
"n_estimators": 100,
"max_depth": 5,
"min_samples_split": 10,
"random_state": 42,
}
with mlflow.start_run():
mlflow.log_params(params)
Asynchronous Logging
import mlflow
with mlflow.start_run():
# Log asynchronously to avoid blocking the training loop
future = mlflow.log_param("batch_size", 64, synchronous=False)