-
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.
- Loading branch information
tamoyan
committed
Jan 21, 2025
1 parent
bda2c5c
commit 9720f9e
Showing
23 changed files
with
155 additions
and
1,823 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 |
---|---|---|
|
@@ -185,6 +185,7 @@ ipython_config.py | |
.logs | ||
.aim | ||
outputs | ||
runs | ||
models--* | ||
.DS_Store | ||
Icon* | ||
|
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
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 |
---|---|---|
@@ -1 +1 @@ | ||
2.0.28 | ||
3.0.0 |
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 |
---|---|---|
@@ -1,4 +1,117 @@ | ||
from .commands import main | ||
import os | ||
import sys | ||
import logging | ||
import secrets | ||
|
||
if __name__ == "__main__": | ||
main() | ||
from aim import Run | ||
from hydra import compose, initialize | ||
from hydra.core.plugins import Plugins | ||
from hydra.core.hydra_config import HydraConfig | ||
from omegaconf import OmegaConf | ||
from pathlib import Path | ||
from datetime import datetime | ||
|
||
from urartu.utils.launcher import launch, launch_on_slurm | ||
from urartu.utils.hydra_plugin import UrartuPlugin | ||
|
||
Plugins.instance().register(UrartuPlugin) | ||
|
||
|
||
import hydra | ||
from omegaconf import DictConfig | ||
|
||
|
||
@hydra.main(version_base=None, config_path="config", config_name="main") | ||
def main(cfg: DictConfig) -> None: | ||
hydra_cfg = HydraConfig.get() | ||
cfg = OmegaConf.create(OmegaConf.to_container(cfg, resolve=True, enum_to_str=True)) | ||
|
||
cwd = Path.cwd() | ||
|
||
is_module = cwd.joinpath('__init__.py').exists() | ||
if not is_module: | ||
logging.error( | ||
f"The directory '{cwd}' is not recognized as a Python module because it lacks an '__init__.py' file." | ||
" To resolve this issue, ensure that an '__init__.py' file exists in the directory if it's intended to be a Python module." | ||
) | ||
raise FileNotFoundError("Missing '__init__.py' file.") | ||
|
||
are_actions = cwd.joinpath('actions').is_dir() | ||
if not are_actions: | ||
logging.error( | ||
f"The required 'actions' subdirectory does not exist in the directory '{cwd}'." | ||
" Please ensure that an 'actions' directory is created within the current directory to proceed." | ||
) | ||
raise FileNotFoundError("Missing 'actions' directory.") | ||
|
||
action_file_path = cwd.joinpath('actions', f"{cfg.action_name}.py") | ||
if action_file_path.exists(): | ||
logging.info(f"The action file '{action_file_path}' is located and is ready to be used!") | ||
else: | ||
logging.error( | ||
f"The action file '{action_file_path}' does not exist." | ||
" Please ensure that the file is correctly named and located in the 'actions' directory." | ||
) | ||
raise FileNotFoundError("Missing action file.") | ||
|
||
is_multirun = hydra_cfg.mode.name == "MULTIRUN" | ||
|
||
if is_multirun: | ||
run_dir = Path(hydra_cfg.runtime.output_dir, hydra_cfg.job.id).parent | ||
else: | ||
run_dir = cwd.joinpath(".runs", datetime.now().strftime("%Y-%m-%d_%H-%M-%S")) | ||
os.makedirs(run_dir, exist_ok=True) | ||
|
||
run_hash = secrets.token_hex(8) | ||
|
||
log_file = run_dir / "output.log" | ||
logging.basicConfig( | ||
level=logging.INFO, | ||
format="%(asctime)s - %(levelname)s - %(message)s", | ||
handlers=[logging.FileHandler(log_file), logging.StreamHandler()], | ||
) | ||
|
||
# Redirect stdout and stderr to log file | ||
sys.stdout = open(log_file, 'a') | ||
sys.stderr = sys.stdout | ||
|
||
cfg.action_config.run_dir = str(run_dir) | ||
cfg.action_config.run_hash = run_hash | ||
|
||
with open(run_dir / "notes.md", "w") as f: | ||
pass | ||
|
||
with open(run_dir / "cfg.yaml", "w") as f: | ||
OmegaConf.save(config=cfg, f=f) | ||
|
||
aim_run = None | ||
if cfg.aim.use_aim: | ||
aim_run = Run( | ||
repo=cfg.aim.repo, | ||
experiment=cfg.action_config.experiment_name, | ||
log_system_params=cfg.aim.log_system_params, | ||
) | ||
aim_run.set("cfg", cfg, strict=False) | ||
|
||
if cfg.slurm.use_slurm: | ||
try: | ||
import submitit # NOQA | ||
except ImportError: | ||
raise ImportError("Please 'pip install submitit' to schedule jobs on SLURM") | ||
|
||
launch_on_slurm( | ||
module=cwd, | ||
action_name=cfg.action_name, | ||
cfg=cfg, | ||
aim_run=aim_run, | ||
) | ||
else: | ||
launch( | ||
module=cwd, | ||
action_name=cfg.action_name, | ||
cfg=cfg, | ||
aim_run=aim_run, | ||
) | ||
|
||
if cfg.aim.use_aim and aim_run.active: | ||
aim_run.close() |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.