Skip to content

Commit

Permalink
✨ Add a km.random_name resolver to enable auto-generated names in con…
Browse files Browse the repository at this point in the history
…figuration (#426)
  • Loading branch information
Galileo-Galilei committed Jan 28, 2024
1 parent e886799 commit ea1344e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions kedro_mlflow/config/resolvers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from mlflow.utils.name_utils import _generate_random_name


def resolve_random_name():
return _generate_random_name()
8 changes: 8 additions & 0 deletions kedro_mlflow/framework/hooks/mlflow_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
from mlflow.models import infer_signature
from mlflow.tracking import MlflowClient
from mlflow.utils.validation import MAX_PARAM_VAL_LENGTH
from omegaconf import OmegaConf
from pydantic import __version__ as pydantic_version

from kedro_mlflow.config.kedro_mlflow_config import KedroMlflowConfig
from kedro_mlflow.config.resolvers import resolve_random_name
from kedro_mlflow.framework.hooks.utils import (
_assert_mlflow_enabled,
_flatten_dict,
Expand Down Expand Up @@ -60,6 +62,12 @@ def after_context_created(
context: The context that was created.
"""

LOGGER.info(r"Registering new custom resolver: 'km.random_name'")
if not OmegaConf.has_resolver("km.random_name"):
OmegaConf.register_new_resolver(
"km.random_name", resolve_random_name, use_cache=True
)

try:
if "mlflow" not in context.config_loader.config_patterns.keys():
context.config_loader.config_patterns.update(
Expand Down

0 comments on commit ea1344e

Please sign in to comment.