MlflowLogger limit parameter value length to 250 char (#5893)
This commit is contained in:
parent
4062c6246c
commit
a0494aba72
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue