generated from ashleve/lightning-hydra-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into patch_composer
- Loading branch information
Showing
3 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# | ||
# Copyright (C) 2022 Intel Corporation | ||
# | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# | ||
|
||
from __future__ import annotations | ||
|
||
import fire | ||
from omegaconf import OmegaConf | ||
|
||
from .utils.config import ( | ||
DEFAULT_CONFIG_DIR, | ||
DEFAULT_CONFIG_NAME, | ||
DEFAULT_VERSION_BASE, | ||
compose, | ||
) | ||
|
||
|
||
def main( | ||
*overrides, | ||
version_base: str = DEFAULT_VERSION_BASE, | ||
config_dir: str = DEFAULT_CONFIG_DIR, | ||
config_name: str = DEFAULT_CONFIG_NAME, | ||
export_node: str | None = None, | ||
resolve: bool = False, | ||
sort_keys: bool = True, | ||
): | ||
cfg = compose( | ||
*overrides, | ||
version_base=version_base, | ||
config_dir=config_dir, | ||
config_name=config_name, | ||
export_node=export_node, | ||
) | ||
|
||
cfg_yaml = OmegaConf.to_yaml(cfg, resolve=resolve, sort_keys=sort_keys) | ||
|
||
# OmegaConf.to_yaml() already ends with `\n`. | ||
print(cfg_yaml, end="") | ||
|
||
|
||
if __name__ == "__main__": | ||
fire.Fire(main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# | ||
# Copyright (C) 2022 Intel Corporation | ||
# | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# | ||
|
||
from __future__ import annotations | ||
|
||
import os | ||
|
||
from hydra import compose as hydra_compose | ||
from hydra import initialize_config_dir | ||
|
||
DEFAULT_VERSION_BASE = "1.2" | ||
DEFAULT_CONFIG_DIR = "." | ||
DEFAULT_CONFIG_NAME = "lightning.yaml" | ||
|
||
__all__ = ["compose"] | ||
|
||
|
||
def compose( | ||
*overrides, | ||
version_base: str = DEFAULT_VERSION_BASE, | ||
config_dir: str = DEFAULT_CONFIG_DIR, | ||
config_name: str = DEFAULT_CONFIG_NAME, | ||
export_node: str | None = None, | ||
): | ||
# Add an absolute path {config_dir} to the search path of configs, preceding those in mart.configs. | ||
if not os.path.isabs(config_dir): | ||
config_dir = os.path.abspath(config_dir) | ||
|
||
# hydra.initialize_config_dir() requires an absolute path, | ||
# while hydra.initialize() searches paths relatively to mart. | ||
with initialize_config_dir(version_base=version_base, config_dir=config_dir): | ||
cfg = hydra_compose(config_name=config_name, overrides=overrides) | ||
|
||
# Export a sub-tree. | ||
if export_node is not None: | ||
for key in export_node.split("."): | ||
cfg = cfg[key] | ||
|
||
return cfg |