From 2cb53811a52e071fbf2be1727c554ad0f26e17ab Mon Sep 17 00:00:00 2001 From: matteowohlrapp Date: Fri, 22 Mar 2024 14:58:19 +0100 Subject: [PATCH 1/3] Logging the duration through an additional attribute in the experiment class --- domainlab/exp/exp_main.py | 2 +- domainlab/exp/exp_utils.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/domainlab/exp/exp_main.py b/domainlab/exp/exp_main.py index 51397131b..e6339bdbb 100755 --- a/domainlab/exp/exp_main.py +++ b/domainlab/exp/exp_main.py @@ -10,7 +10,6 @@ from domainlab.tasks.zoo_tasks import TaskChainNodeGetter from domainlab.utils.logger import Logger from domainlab.utils.sanity_check import SanityCheck - os.environ["CUDA_LAUNCH_BLOCKING"] = "1" # debug @@ -96,6 +95,7 @@ def execute(self, num_epochs=None): f"Experiment finished at epoch: {self.epoch_counter} " f"with time: {t_c - t_0} at {t_c}" ) + self.experiment_duration = t_c - t_0 self.trainer.post_tr() def clean_up(self): diff --git a/domainlab/exp/exp_utils.py b/domainlab/exp/exp_utils.py index 2af681731..95c130553 100644 --- a/domainlab/exp/exp_utils.py +++ b/domainlab/exp/exp_utils.py @@ -179,6 +179,11 @@ def _gen_line(self, dict_metric): confmat_filename = dict_cols.get("mname", None) # return None if not found # @FIXME: strong dependency on host attribute name dict_cols.update({epos_name: self.host.epoch_counter}) + if hasattr(self.host, "experiment_duration"): + dict_cols.update({"experiment_duration": self.host.experiment_duration}) + else: + print("Does not have attribute") + print(self.host) if not self.has_first_line: self.first_line(dict_cols) list_str = [str(dict_cols[key]) for key in self.list_cols] From b4698309ba765270719f1f5e503b7897f4757622 Mon Sep 17 00:00:00 2001 From: matteowohlrapp Date: Fri, 22 Mar 2024 17:36:59 +0100 Subject: [PATCH 2/3] Moved declaration of attribute to constructor --- domainlab/exp/exp_main.py | 1 + domainlab/exp/exp_utils.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/domainlab/exp/exp_main.py b/domainlab/exp/exp_main.py index e6339bdbb..28f8ce40a 100755 --- a/domainlab/exp/exp_main.py +++ b/domainlab/exp/exp_main.py @@ -56,6 +56,7 @@ def __init__(self, args, task=None, model=None, observer=None, visitor=AggWriter self.trainer.init_business(self.model, self.task, observer, device, args) self.visitor = visitor(self) # visitor depends on task initialization first # visitor must be initialized last after trainer is initialized + self.experiment_duration = None self.model.set_saver(self.visitor) def execute(self, num_epochs=None): diff --git a/domainlab/exp/exp_utils.py b/domainlab/exp/exp_utils.py index 95c130553..256a8be68 100644 --- a/domainlab/exp/exp_utils.py +++ b/domainlab/exp/exp_utils.py @@ -179,7 +179,7 @@ def _gen_line(self, dict_metric): confmat_filename = dict_cols.get("mname", None) # return None if not found # @FIXME: strong dependency on host attribute name dict_cols.update({epos_name: self.host.epoch_counter}) - if hasattr(self.host, "experiment_duration"): + if self.host.experiment_duration is not None: dict_cols.update({"experiment_duration": self.host.experiment_duration}) else: print("Does not have attribute") From ec5ead8e91fe28dfafe547d490e9ce62bf2086be Mon Sep 17 00:00:00 2001 From: smilesun Date: Sat, 23 Mar 2024 07:48:35 +0100 Subject: [PATCH 3/3] fix codacy --- domainlab/exp/exp_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/domainlab/exp/exp_utils.py b/domainlab/exp/exp_utils.py index 256a8be68..22a609b2c 100644 --- a/domainlab/exp/exp_utils.py +++ b/domainlab/exp/exp_utils.py @@ -179,9 +179,9 @@ def _gen_line(self, dict_metric): confmat_filename = dict_cols.get("mname", None) # return None if not found # @FIXME: strong dependency on host attribute name dict_cols.update({epos_name: self.host.epoch_counter}) - if self.host.experiment_duration is not None: + if self.host.experiment_duration is not None: dict_cols.update({"experiment_duration": self.host.experiment_duration}) - else: + else: print("Does not have attribute") print(self.host) if not self.has_first_line: