Skip to content

Commit

Permalink
Update experiment name limit (mlflow#12651)
Browse files Browse the repository at this point in the history
Signed-off-by: Serena Ruan <[email protected]>
  • Loading branch information
serena-ruan authored Jul 15, 2024
1 parent 2008fc6 commit a598dd8
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 5 deletions.
3 changes: 2 additions & 1 deletion mlflow/store/tracking/abstract_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ def create_experiment(self, name, artifact_location, tags):
If an experiment with the given name already exists, throws exception.
Args:
name: Desired name for an experiment
name: Desired name for an experiment. The name must be a string
with maximum length of 500 characters.
artifact_location: Base location for artifacts in runs. May be None.
tags: Experiment tags to set upon experiment creation
Expand Down
5 changes: 4 additions & 1 deletion mlflow/store/tracking/rest_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
get_single_trace_endpoint,
get_trace_info_endpoint,
)
from mlflow.utils.validation import _validate_experiment_name

_METHOD_TO_INFO = extract_api_info_for_service(MlflowService, _REST_API_PATH_PREFIX)
_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -110,11 +111,13 @@ def create_experiment(self, name, artifact_location=None, tags=None):
If an experiment with the given name already exists, throws exception.
Args:
name: Desired name for an experiment
name: Desired name for an experiment. The name must be a string
with maximum length of 500 characters.
Returns:
experiment_id for the newly created experiment if successful, else None
"""
_validate_experiment_name(name)
tag_protos = [tag.to_proto() for tag in tags] if tags else []
req_body = message_to_json(
CreateExperiment(name=name, artifact_location=artifact_location, tags=tag_protos)
Expand Down
5 changes: 4 additions & 1 deletion mlflow/tracking/_tracking_service/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
MAX_PARAMS_TAGS_PER_BATCH,
PARAM_VALIDATION_MSG,
_validate_experiment_artifact_location,
_validate_experiment_name,
_validate_run_id,
)

Expand Down Expand Up @@ -485,7 +486,8 @@ def create_experiment(self, name, artifact_location=None, tags=None):
"""Create an experiment.
Args:
name: The experiment name. Must be unique.
name: The experiment name, which must be a unique string
with maximum length of 500 characters.
artifact_location: The location to store run artifacts. If not provided, the server
picks an appropriate default.
tags: A dictionary of key-value pairs that are converted into
Expand All @@ -495,6 +497,7 @@ def create_experiment(self, name, artifact_location=None, tags=None):
Integer ID of the created experiment.
"""
_validate_experiment_name(name)
_validate_experiment_artifact_location(artifact_location)
return self.store.create_experiment(
name=name,
Expand Down
3 changes: 2 additions & 1 deletion mlflow/tracking/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,8 @@ def create_experiment(
"""Create an experiment.
Args:
name: The experiment name. Must be unique.
name: The experiment name, which must be a unique string
with maximum length of 500 characters.
artifact_location: The location to store run artifacts. If not provided, the server
picks anappropriate default.
tags: A dictionary of key-value pairs that are converted into
Expand Down
3 changes: 2 additions & 1 deletion mlflow/tracking/fluent.py
Original file line number Diff line number Diff line change
Expand Up @@ -1683,7 +1683,8 @@ def create_experiment(
Create an experiment.
Args:
name: The experiment name, which must be unique and is case sensitive.
name: The experiment name, which must be a unique string with maximum
length of 500 characters, and it is case sensitive.
artifact_location: The location to store run artifacts. If not provided, the server picks
an appropriate default.
tags: An optional dictionary of string keys and values to set as tags on the experiment.
Expand Down
6 changes: 6 additions & 0 deletions mlflow/utils/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
MAX_BATCH_LOG_REQUEST_SIZE = int(1e6)
MAX_PARAM_VAL_LENGTH = 6000
MAX_TAG_VAL_LENGTH = 5000
MAX_EXPERIMENT_NAME_LENGTH = 500
MAX_EXPERIMENT_TAG_KEY_LENGTH = 250
MAX_EXPERIMENT_TAG_VAL_LENGTH = 5000
MAX_ENTITY_KEY_LENGTH = 250
Expand Down Expand Up @@ -371,6 +372,11 @@ def _validate_experiment_name(experiment_name):
error_code=INVALID_PARAMETER_VALUE,
)

if len(experiment_name) > MAX_EXPERIMENT_NAME_LENGTH:
raise MlflowException.invalid_parameter_value(
f"Experiment name exceeds the maximum length of {MAX_EXPERIMENT_NAME_LENGTH} characters"
)


def _validate_experiment_id_type(experiment_id):
"""
Expand Down
3 changes: 3 additions & 0 deletions tests/store/tracking/test_file_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
from mlflow.utils.os import is_windows
from mlflow.utils.time import get_current_time_millis
from mlflow.utils.uri import append_to_uri_path
from mlflow.utils.validation import MAX_EXPERIMENT_NAME_LENGTH

from tests.helper_functions import random_int, random_str, safe_edit_yaml

Expand Down Expand Up @@ -589,6 +590,8 @@ def test_create_experiment(store):
store.create_experiment(None)
with pytest.raises(Exception, match="Invalid experiment name: ''"):
store.create_experiment("")
with pytest.raises(MlflowException, match=r"Experiment name exceeds the maximum length"):
store.create_experiment(name="x" * (MAX_EXPERIMENT_NAME_LENGTH + 1))
name = random_str(25) # since existing experiments are 10 chars long
time_before_create = get_current_time_millis()
created_id = store.create_experiment(name)
Expand Down
4 changes: 4 additions & 0 deletions tests/store/tracking/test_sqlalchemy_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
MAX_DATASET_PROFILE_SIZE,
MAX_DATASET_SCHEMA_SIZE,
MAX_DATASET_SOURCE_SIZE,
MAX_EXPERIMENT_NAME_LENGTH,
MAX_INPUT_TAG_KEY_SIZE,
MAX_INPUT_TAG_VALUE_SIZE,
)
Expand Down Expand Up @@ -663,6 +664,9 @@ def test_create_experiments(store: SqlAlchemyStore):
assert actual.creation_time >= time_before_create
assert actual.last_update_time == actual.creation_time

with pytest.raises(MlflowException, match=r"Experiment name exceeds the maximum length"):
store.create_experiment(name="x" * (MAX_EXPERIMENT_NAME_LENGTH + 1))


def test_create_experiment_with_tags_works_correctly(store: SqlAlchemyStore):
experiment_id = store.create_experiment(
Expand Down

0 comments on commit a598dd8

Please sign in to comment.