-
Notifications
You must be signed in to change notification settings - Fork 42
Rename epoch to mini_epoch #1190
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
TillHae
wants to merge
4
commits into
ecmwf:develop
Choose a base branch
from
TillHae:thauer/develop/issue_515
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.
Open
Changes from all commits
Commits
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
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
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
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 |
|---|---|---|
|
|
@@ -54,23 +54,23 @@ def format_cf(config: Config) -> str: | |
| return stream.getvalue() | ||
|
|
||
|
|
||
| def save(config: Config, epoch: int | None): | ||
| def save(config: Config, mini_epoch: int | None): | ||
| """Save current config into the current runs model directory.""" | ||
| path_models = Path(config.model_path) | ||
| # save in directory with model files | ||
| dirname = path_models / config.run_id | ||
| dirname.mkdir(exist_ok=True, parents=True) | ||
|
|
||
| fname = dirname / _get_model_config_file_name(config.run_id, epoch) | ||
| fname = dirname / _get_model_config_file_name(config.run_id, mini_epoch) | ||
|
|
||
| json_str = json.dumps(OmegaConf.to_container(config)) | ||
| with fname.open("w") as f: | ||
| f.write(json_str) | ||
|
|
||
|
|
||
| def load_model_config(run_id: str, epoch: int | None, model_path: str | None) -> Config: | ||
| def load_model_config(run_id: str, mini_epoch: int | None, model_path: str | None) -> Config: | ||
| """ | ||
| Load a configuration file from a given run_id and epoch. | ||
| 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. | ||
| """ | ||
| if Path(run_id).exists(): # load from the full path if a full path is provided | ||
|
|
@@ -84,13 +84,13 @@ def load_model_config(run_id: str, epoch: int | None, model_path: str | None) -> | |
| config=pconf, attribute_name="model_path", fallback="models" | ||
| ) | ||
| path = Path(model_path) | ||
| fname = path / run_id / _get_model_config_file_name(run_id, epoch) | ||
| fname = path / run_id / _get_model_config_file_name(run_id, mini_epoch) | ||
| assert fname.exists(), ( | ||
| "The fallback path to the model does not exist. Please provide a `model_path`.", | ||
| fname, | ||
| ) | ||
|
|
||
| _logger.info(f"Loading config from specified run_id and epoch: {fname}") | ||
| _logger.info(f"Loading config from specified run_id and mini_epoch: {fname}") | ||
|
|
||
| with fname.open() as f: | ||
| json_str = f.read() | ||
|
|
@@ -100,22 +100,22 @@ def load_model_config(run_id: str, epoch: int | None, model_path: str | None) -> | |
| return _apply_fixes(config) | ||
|
|
||
|
|
||
| def _get_model_config_file_name(run_id: str, epoch: int | None): | ||
| if epoch is None: | ||
| epoch_str = "" | ||
| elif epoch == -1: | ||
| epoch_str = "_latest" | ||
| def _get_model_config_file_name(run_id: str, mini_epoch: int | None): | ||
| if mini_epoch is None: | ||
| mini_epoch_str = "" | ||
| elif mini_epoch == -1: | ||
| mini_epoch_str = "_latest" | ||
| else: | ||
| epoch_str = f"_epoch{epoch:05d}" | ||
| return f"model_{run_id}{epoch_str}.json" | ||
| mini_epoch_str = f"_chkpt{mini_epoch:05d}" | ||
| return f"model_{run_id}{mini_epoch_str}.json" | ||
|
|
||
|
|
||
| def get_model_results(run_id: str, epoch: int, rank: int) -> Path: | ||
| def get_model_results(run_id: str, mini_epoch: int, rank: int) -> Path: | ||
| """ | ||
| Get the path to the model results zarr store from a given run_id and epoch. | ||
| Get the path to the model results zarr store from a given run_id and mini_epoch. | ||
| """ | ||
| run_results = Path(_load_private_conf(None)["path_shared_working_dir"]) / f"results/{run_id}" | ||
| zarr_path = run_results / f"validation_epoch{epoch:05d}_rank{rank:04d}.zarr" | ||
| zarr_path = run_results / f"validation_chkpt{mini_epoch:05d}_rank{rank:04d}.zarr" | ||
| if not zarr_path.exists() or not zarr_path.is_dir(): | ||
| raise FileNotFoundError(f"Zarr file {zarr_path} does not exist or is not a directory.") | ||
| return zarr_path | ||
|
|
@@ -150,7 +150,7 @@ def _check_logging(config: Config) -> Config: | |
| def load_config( | ||
| private_home: Path | None, | ||
| from_run_id: str | None, | ||
| epoch: int | None, | ||
| mini_epoch: int | None, | ||
| *overwrites: Path | dict | Config, | ||
| ) -> Config: | ||
| """ | ||
|
|
@@ -161,7 +161,7 @@ def load_config( | |
| private_home: Configuration file containing platform dependent information and secretes | ||
| from_run_id: Run id of the pretrained WeatherGenerator model | ||
| to continue training or inference | ||
| epoch: epoch of the checkpoint to load. -1 indicates last checkpoint available. | ||
| mini_epoch: mini_epoch of the checkpoint to load. -1 indicates last checkpoint available. | ||
| *overwrites: Additional overwrites from different sources | ||
|
|
||
| Note: The order of precendence for merging the final config is in ascending order: | ||
|
|
@@ -191,7 +191,9 @@ def load_config( | |
| if from_run_id is None: | ||
| base_config = _load_default_conf() | ||
| else: | ||
| base_config = load_model_config(from_run_id, epoch, private_config.get("model_path", None)) | ||
| base_config = load_model_config( | ||
| from_run_id, mini_epoch, private_config.get("model_path", None) | ||
| ) | ||
| from_run_id = base_config.run_id | ||
| with open_dict(base_config): | ||
| base_config.from_run_id = from_run_id | ||
|
|
@@ -456,9 +458,9 @@ def get_path_model(config: Config) -> Path: | |
| return Path(config.model_path) / config.run_id | ||
|
|
||
|
|
||
| def get_path_output(config: Config, epoch: int) -> Path: | ||
| def get_path_output(config: Config, mini_epoch: int) -> Path: | ||
| base_path = get_path_run(config) | ||
| fname = f"validation_epoch{epoch:05d}_rank{config.rank:04d}.zarr" | ||
| fname = f"validation_chkpt{mini_epoch:05d}_rank{config.rank:04d}.zarr" | ||
|
Contributor
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. Backward compatibility? |
||
|
|
||
| return base_path / fname | ||
|
|
||
|
|
@@ -523,7 +525,7 @@ def validate_forecast_policy_and_steps(cf: OmegaConf): | |
| valid_forecast_policies = ( | ||
| "Valid values for 'forecast_policy' are, e.g., 'fixed' when using constant " | ||
| "forecast steps throughout the training, or 'sequential' when varying the forecast " | ||
| "steps over epochs, such as, e.g., 'forecast_steps: [2, 2, 4, 4]'. " | ||
| "steps over mini_epochs, such as, e.g., 'forecast_steps: [2, 2, 4, 4]'. " | ||
| ) | ||
| valid_forecast_steps = ( | ||
| "'forecast_steps' must be a positive integer or a non-empty list of positive integers. " | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -304,7 +304,7 @@ def __init__(self, eval_cfg: dict, run_id: str, private_paths: dict | None = Non | |
|
|
||
| super().__init__(eval_cfg, run_id, private_paths) | ||
|
|
||
| self.epoch = eval_cfg.epoch | ||
| self.mini_epoch = eval_cfg.mini_epoch | ||
| self.rank = eval_cfg.rank | ||
|
|
||
| # Load model configuration and set (run-id specific) directories | ||
|
|
@@ -334,7 +334,7 @@ def __init__(self, eval_cfg: dict, run_id: str, private_paths: dict | None = Non | |
| ) | ||
|
|
||
| self.fname_zarr = self.results_dir.joinpath( | ||
| f"validation_epoch{self.epoch:05d}_rank{self.rank:04d}.zarr" | ||
| f"validation_chkpt{self.mini_epoch:05d}_rank{self.rank:04d}.zarr" | ||
|
Contributor
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. Backward compatibility |
||
| ) | ||
|
|
||
| if not self.fname_zarr.exists() or not self.fname_zarr.is_dir(): | ||
|
|
@@ -356,12 +356,12 @@ def get_inference_config(self): | |
| _logger.info( | ||
| f"Loading config for run {self.run_id} from private paths: {self.private_paths}" | ||
| ) | ||
| config = load_config(self.private_paths, self.run_id, self.epoch) | ||
| config = load_config(self.private_paths, self.run_id, self.mini_epoch) | ||
| else: | ||
| _logger.info( | ||
| f"Loading config for run {self.run_id} from model directory: {self.model_base_dir}" | ||
| ) | ||
| config = load_model_config(self.run_id, self.epoch, self.model_base_dir) | ||
| config = load_model_config(self.run_id, self.mini_epoch, self.model_base_dir) | ||
|
|
||
| if type(config) not in [dict, oc.DictConfig]: | ||
| _logger.warning("Model config not found. inference config will be empty.") | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have this backwards-compatible? Something like (not tested)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you check if this method is still in use? Ideally the knowledge of the specifics of the path should be encapsulated in
get_output_pathand anywhere this information is requiredget_output_pathshould be used instead. A simple backward compatibility mechanism such as @MatKbauer describes can be then implemented there.