Skip to content

Commit

Permalink
Fix hyperparameter logging crash with missing config values (#19)
Browse files Browse the repository at this point in the history
* fix: logging hyperparameters with missing config values

* chore: update changelog
  • Loading branch information
gmertes authored Aug 14, 2024
1 parent 7113de9 commit 6d289fd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Keep it human-readable, your future self will thank you!
- Moved callbacks into folder to fascilitate future refactor
- Adjusted PyPI release infrastructure to common ECMWF workflow
- Bumped versions in Pre-commit hooks
- Fix crash when logging hyperparameters with missing values in the config

### Removed
- Dependency on mlflow-export-import
Expand Down
6 changes: 6 additions & 0 deletions src/anemoi/training/diagnostics/mlflow/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from pytorch_lightning.utilities.rank_zero import rank_zero_only

from anemoi.training.diagnostics.mlflow.auth import TokenAuth
from anemoi.training.utils.jsonify import map_config_to_primitives

if TYPE_CHECKING:
from argparse import Namespace
Expand Down Expand Up @@ -454,6 +455,11 @@ def log_hyperparams(self, params: dict[str, Any] | Namespace) -> None:
"""Overwrite the log_hyperparams method to flatten config params using '.'."""
if self._flag_log_hparams:
params = _convert_params(params)

# this is needed to resolve optional missing config values to a string, instead of raising a missing error
if config := params.get("config"):
params["config"] = map_config_to_primitives(config)

params = _flatten_dict(params, delimiter=".") # Flatten dict with '.' to not break API queries
params = self._clean_params(params)

Expand Down

0 comments on commit 6d289fd

Please sign in to comment.