Skip to content

Commit 76eb5dc

Browse files
grajat90rohitgr7
authored andcommitted
omegaconf flag added
1 parent d74e0a8 commit 76eb5dc

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

pytorch_lightning/core/saving.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,11 +347,14 @@ def load_hparams_from_yaml(config_yaml: str, use_omegaconf: bool = True) -> Dict
347347
return hparams
348348

349349

350-
def save_hparams_to_yaml(config_yaml, hparams: Union[dict, Namespace]) -> None:
350+
def save_hparams_to_yaml(config_yaml, hparams: Union[dict, Namespace], use_omegaconf: bool = True) -> None:
351351
"""
352352
Args:
353353
config_yaml: path to new YAML file
354354
hparams: parameters to be saved
355+
use_omegaconf: If both `OMEGACONF_AVAILABLE` and `use_omegaconf` are True,
356+
the hparams will be converted to `DictConfig` if possible
357+
355358
"""
356359
fs = get_filesystem(config_yaml)
357360
if not fs.isdir(os.path.dirname(config_yaml)):
@@ -364,7 +367,7 @@ def save_hparams_to_yaml(config_yaml, hparams: Union[dict, Namespace]) -> None:
364367
hparams = dict(hparams)
365368

366369
# saving with OmegaConf objects
367-
if _OMEGACONF_AVAILABLE:
370+
if _OMEGACONF_AVAILABLE and use_omegaconf:
368371
# deepcopy: hparams from user shouldn't be resolved
369372
hparams = deepcopy(hparams)
370373
hparams = apply_to_collection(hparams, DictConfig, OmegaConf.to_container, resolve=True)

0 commit comments

Comments
 (0)