MlflowLogger limit parameter value length to 250 char (#5893)

This commit is contained in:
Thien Bui 2021-02-17 08:22:06 +11:00 committed by GitHub
parent 4062c6246c
commit a0494aba72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -150,6 +150,12 @@ class MLFlowLogger(LightningLoggerBase):
params = self._convert_params(params)
params = self._flatten_dict(params)
for k, v in params.items():
if len(str(v)) > 250:
rank_zero_warn(
f"Mlflow only allows parameters with up to 250 characters. Discard {k}={v}", RuntimeWarning
)
continue
self.experiment.log_param(self.run_id, k, v)
@rank_zero_only

View File

@ -184,3 +184,18 @@ def test_mlflow_logger_with_unexpected_characters(client, mlflow, tmpdir):
with pytest.warns(RuntimeWarning, match='special characters in metric name'):
logger.log_metrics(metrics)
@mock.patch('pytorch_lightning.loggers.mlflow.mlflow')
@mock.patch('pytorch_lightning.loggers.mlflow.MlflowClient')
def test_mlflow_logger_with_long_param_value(client, mlflow, tmpdir):
"""
Test that the logger raises warning with special characters not accepted by MLFlow.
"""
logger = MLFlowLogger('test', save_dir=tmpdir)
value = 'test' * 100
key = 'test_param'
params = {key: value}
with pytest.warns(RuntimeWarning, match=f'Discard {key}={value}'):
logger.log_hyperparams(params)