Skip to content

Commit 029c7ab

Browse files
feat[logger] update mlflow limit for parameters length log using mlflow package
1 parent 87108d8 commit 029c7ab

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/lightning/pytorch/loggers/mlflow.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,17 @@ def log_hyperparams(self, params: Union[dict[str, Any], Namespace]) -> None:
235235
params = _flatten_dict(params)
236236

237237
from mlflow.entities import Param
238-
239-
# Truncate parameter values to 250 characters.
240-
# TODO: MLflow 1.28 allows up to 500 characters: https://github.com/mlflow/mlflow/releases/tag/v1.28.0
241-
params_list = [Param(key=k, value=str(v)[:250]) for k, v in params.items()]
238+
239+
import mlflow.utils.validation
240+
241+
# Check maximum param value length is available and use it
242+
if hasattr(mlflow.utils.validation, 'MAX_PARAM_VAL_LENGTH'):
243+
param_length_limit = mlflow.utils.validation.MAX_PARAM_VAL_LENGTH
244+
else: # Fallback
245+
param_length_limit = 250 # Historical default value
246+
247+
# Use mlflow default limit or truncate parameter values to 250 characters if limit is not available
248+
params_list = [Param(key=k, value=str(v)[:param_length_limit]) for k, v in params.items()]
242249

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

0 commit comments

Comments
 (0)