Skip to content

feat[logger] update mlflow limit for parameters length log #20636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/lightning/pytorch/loggers/mlflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,17 @@ def log_hyperparams(self, params: Union[dict[str, Any], Namespace]) -> None:
params = _convert_params(params)
params = _flatten_dict(params)

import mlflow.utils.validation
from mlflow.entities import Param

# Truncate parameter values to 250 characters.
# TODO: MLflow 1.28 allows up to 500 characters: https://github.com/mlflow/mlflow/releases/tag/v1.28.0
params_list = [Param(key=k, value=str(v)[:250]) for k, v in params.items()]
# Check maximum param value length is available and use it
if hasattr(mlflow.utils.validation, "MAX_PARAM_VAL_LENGTH"):
param_length_limit = mlflow.utils.validation.MAX_PARAM_VAL_LENGTH
else: # Fallback
param_length_limit = 250 # Historical default value

# Use mlflow default limit or truncate parameter values to 250 characters if limit is not available
params_list = [Param(key=k, value=str(v)[:param_length_limit]) for k, v in params.items()]

# Log in chunks of 100 parameters (the maximum allowed by MLflow).
for idx in range(0, len(params_list), 100):
Expand Down
Loading