Skip to content

Commit cbea665

Browse files
committed
omegaconf flag added
1 parent 5c85183 commit cbea665

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
@@ -349,11 +349,14 @@ def load_hparams_from_yaml(config_yaml: str, use_omegaconf: bool = True) -> Dict
349349
return hparams
350350

351351

352-
def save_hparams_to_yaml(config_yaml, hparams: Union[dict, Namespace]) -> None:
352+
def save_hparams_to_yaml(config_yaml, hparams: Union[dict, Namespace], use_omegaconf: bool = True) -> None:
353353
"""
354354
Args:
355355
config_yaml: path to new YAML file
356356
hparams: parameters to be saved
357+
use_omegaconf: If both `OMEGACONF_AVAILABLE` and `use_omegaconf` are True,
358+
the hparams will be converted to `DictConfig` if possible
359+
357360
"""
358361
fs = get_filesystem(config_yaml)
359362
if not fs.isdir(os.path.dirname(config_yaml)):
@@ -366,7 +369,7 @@ def save_hparams_to_yaml(config_yaml, hparams: Union[dict, Namespace]) -> None:
366369
hparams = dict(hparams)
367370

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

0 commit comments

Comments
 (0)