-
Notifications
You must be signed in to change notification settings - Fork 71
[2810] Allow private config to override output directories and filename #2811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
evenmn
wants to merge
7
commits into
ecmwf:develop
Choose a base branch
from
metno:feat/private-config-output-paths
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+43
−33
Open
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
81d6a21
Allow private config to override output directories and filename
evenmn a42cf9b
Avoid reassigning typed config parameter when loading a run
evenmn 944b8e6
Rename exact checkpoint directory override to full_model_path
evenmn 5ebe17c
Clarify private configuration argument and variable names
evenmn 1945007
Renamed _get_output_directory to _get_path_output
evenmn 27c6a08
Resolve log directories in config before initializing loggers
evenmn 07c1027
Reverted 'loaded_config' to 'config' like it was before
evenmn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -208,15 +208,18 @@ def save(config: Config, mini_epoch: int | None): | |
| f.write(json_str) | ||
|
|
||
|
|
||
| def load_run_config(run_id: str, mini_epoch: int | None, model_path: str | None) -> Config: | ||
| def load_run_config( | ||
| run_id: str, mini_epoch: int | None, model_path: str | None, *, config: Config | None = None | ||
| ) -> Config: | ||
| """ | ||
| Load a configuration file from a given run_id and mini_epoch. | ||
| If run_id is a full path, loads it from the full path. | ||
|
|
||
| Args: | ||
| run_id: Run ID of the pretrained WeatherGenerator model | ||
| mini_epoch: Mini_epoch of the checkpoint to load. -1 indicates last checkpoint available. | ||
| model_path: Path to the model directory. If None, uses the model_path from private config. | ||
| model_path: Parent model directory containing run-id subdirectories. | ||
| config: Active configuration for resolving path_model when model_path is None. | ||
|
evenmn marked this conversation as resolved.
Outdated
|
||
|
|
||
| Returns: | ||
| Configuration object loaded from the specified run and mini_epoch. | ||
|
|
@@ -228,7 +231,7 @@ def load_run_config(run_id: str, mini_epoch: int | None, model_path: str | None) | |
| else: | ||
| # Load model config here. In case model_path is not provided, get it from private conf | ||
| if model_path is None: | ||
| path = get_path_model(run_id=run_id) | ||
| path = get_path_model(config, run_id=run_id) | ||
| else: | ||
| path = Path(model_path) / run_id | ||
|
|
||
|
|
@@ -255,9 +258,9 @@ def load_run_config(run_id: str, mini_epoch: int | None, model_path: str | None) | |
| with fname.open() as f: | ||
| json_str = f.read() | ||
|
|
||
| config = OmegaConf.create(json.loads(json_str)) | ||
| loaded_config = OmegaConf.create(json.loads(json_str)) | ||
|
evenmn marked this conversation as resolved.
Outdated
|
||
|
|
||
| return _apply_fixes(config) | ||
| return _apply_fixes(loaded_config) | ||
|
|
||
|
|
||
| def _get_model_config_file_write_name(run_id: str, mini_epoch: int | None): | ||
|
|
@@ -451,7 +454,7 @@ def load_merge_configs( | |
| if from_run_id is None: | ||
| base_config = _load_base_conf(base) | ||
| else: | ||
| base_config = load_run_config(from_run_id, mini_epoch, None) | ||
| base_config = load_run_config(from_run_id, mini_epoch, None, config=private_config) | ||
| from_run_id = get_run_id_from_config(base_config) | ||
| with open_dict(base_config): | ||
| base_config.from_run_id = from_run_id | ||
|
|
@@ -698,9 +701,23 @@ def load_streams(streams_directory: Path) -> Config: | |
| return OmegaConf.create(streams) | ||
|
|
||
|
|
||
| def _get_output_directory(config: Config, key: str, folder: str, run_id: str) -> Path: | ||
|
evenmn marked this conversation as resolved.
Outdated
|
||
| """Use an exact directory override, or the existing shared per-run location.""" | ||
| if config.get(key) is not None: | ||
| return Path(config[key]) | ||
| working_dir = config.get("path_shared_working_dir") | ||
| root = Path(working_dir) if working_dir is not None else _get_shared_wg_path() | ||
| return root / folder / run_id | ||
|
|
||
|
|
||
| def get_path_logs(config: Config) -> Path: | ||
| """Get the application log directory.""" | ||
| return _get_output_directory(config, "path_logs", "logs", get_run_id_from_config(config)) | ||
|
|
||
|
|
||
| def get_path_run(config: Config) -> Path: | ||
| """Get the current runs results_path for storing run results and logs.""" | ||
| return _get_shared_wg_path() / "results" / get_run_id_from_config(config) | ||
| return _get_output_directory(config, "path_results", "results", get_run_id_from_config(config)) | ||
|
|
||
|
|
||
| def get_path_model(config: Config | None = None, run_id: str | None = None) -> Path: | ||
|
|
@@ -710,14 +727,16 @@ def get_path_model(config: Config | None = None, run_id: str | None = None) -> P | |
| else: | ||
| msg = f"Missing run_id and cannot infer it from config: {config}" | ||
| raise ValueError(msg) | ||
| return _get_shared_wg_path() / "models" / run_id | ||
| config = config if config is not None else _load_private_conf() | ||
|
evenmn marked this conversation as resolved.
Outdated
|
||
| return _get_output_directory(config, "path_model", "models", run_id) | ||
|
|
||
|
|
||
| def get_path_results(config: Config, mini_epoch: int) -> Path: | ||
| """Get the path to validation results for a specific mini_epoch and rank.""" | ||
| ext = StoreType(config.zarr_store).value # validate extension | ||
| base_path = get_path_run(config) | ||
| fname = f"validation_chkpt{mini_epoch:05d}_rank{config.rank:04d}.{ext}" | ||
| fname = config.get("output_name") or fname | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. config is here private config, right? Can we change the variable name. |
||
|
|
||
| return base_path / fname | ||
|
|
||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.