-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #115 from mila-iqia/add_aim
Add aimlogger
- Loading branch information
Showing
12 changed files
with
171 additions
and
12 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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.idea | ||
mlruns | ||
.aim | ||
|
||
examples/data/ | ||
examples/*/output*/ | ||
|
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,4 @@ | ||
TENSORBOARD = 'tensorboard' | ||
AIM = 'aim' | ||
LOG_FOLDER = 'log_folder' | ||
EXP_LOGGERS = 'experiment_loggers' |
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,83 @@ | ||
import os | ||
|
||
import yaml | ||
|
||
if os.name != 'nt': | ||
# not using AIM on Windows | ||
from aim.pytorch_lightning import AimLogger | ||
|
||
from amlrt_project.data.constants import LOG_FOLDER | ||
|
||
AIM_INFO_FILE_NAME = "aim_info.yaml" | ||
|
||
|
||
def prepare_aim_logger(hyper_params, options, output): | ||
"""Create the aim logger - make sure to track on the same experiment if resuming one.""" | ||
if LOG_FOLDER not in options: | ||
raise ValueError('please set log_folder in config file to use aim') | ||
aim_run_info_dict = retrieve_aim_run_info( | ||
output, hyper_params["exp_name"], options[LOG_FOLDER], | ||
) | ||
aim_logger = AimLogger( | ||
run_name=aim_run_info_dict["run_name"] if aim_run_info_dict else None, | ||
run_hash=aim_run_info_dict["run_hash"] if aim_run_info_dict else None, | ||
experiment=hyper_params["exp_name"], | ||
repo=options[LOG_FOLDER], | ||
train_metric_prefix="train__", | ||
val_metric_prefix="val__", | ||
) | ||
# get orion trail id if using orion - if yes, this will be used as the run name | ||
orion_trial_id = os.environ.get("ORION_TRIAL_ID") | ||
if orion_trial_id: | ||
aim_logger.experiment.name = orion_trial_id | ||
save_aim_run_info( | ||
aim_logger.experiment.name, | ||
aim_logger.experiment.hash, | ||
output, | ||
hyper_params["exp_name"], | ||
options[LOG_FOLDER], | ||
) | ||
return aim_logger | ||
|
||
|
||
def save_aim_run_info( | ||
run_name: str, | ||
run_hash: str, | ||
output: str, | ||
experiment: str, | ||
repo: str, | ||
): | ||
"""Save aim_run_info_dict to output dir.""" | ||
aim_run_info_dict = { | ||
"experiment": experiment, | ||
"aim_dir": repo, | ||
"run_name": run_name, | ||
"run_hash": run_hash, | ||
} | ||
with open(os.path.join(output, AIM_INFO_FILE_NAME), "w") as file: | ||
yaml.dump(aim_run_info_dict, file) | ||
|
||
|
||
def retrieve_aim_run_info( | ||
output: str, | ||
experiment: str, | ||
repo: str, | ||
): | ||
"""Retrieve aim_run_info_dict from previous run's output dir.""" | ||
if os.path.exists(os.path.join(output, AIM_INFO_FILE_NAME)): | ||
# output exist and aim_info.yaml exists under output | ||
# this means current run is not starting from scratch | ||
# so we will try to load aim_info.yaml to resume the previous run | ||
with open(os.path.join(output, AIM_INFO_FILE_NAME), "r") as file: | ||
aim_run_info_dict = yaml.load(file, Loader=yaml.FullLoader) | ||
if (experiment != aim_run_info_dict["experiment"]) or ( | ||
repo != aim_run_info_dict["aim_dir"] | ||
): | ||
# if the experiment changes or the aim logging directory changes | ||
# either of these means the run is differently | ||
# so will not resume the previous run for aim | ||
aim_run_info_dict = None | ||
else: | ||
aim_run_info_dict = None | ||
|
||
return aim_run_info_dict |
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,2 +1,3 @@ | ||
set -e | ||
amlrt-train --data ../data --output output --config config.yaml --start-from-scratch | ||
amlrt-eval --data ../data --config config.yaml --ckpt-path output/best_model/model.ckpt |
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,3 +1,4 @@ | ||
set -e | ||
export ORION_DB_ADDRESS='orion_db.pkl' | ||
export ORION_DB_TYPE='pickleddb' | ||
|
||
|
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