halib 0.2.4__py3-none-any.whl → 0.2.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- halib/exp/core/base_exp.py +22 -32
- {halib-0.2.4.dist-info → halib-0.2.5.dist-info}/METADATA +2 -2
- {halib-0.2.4.dist-info → halib-0.2.5.dist-info}/RECORD +6 -6
- {halib-0.2.4.dist-info → halib-0.2.5.dist-info}/WHEEL +0 -0
- {halib-0.2.4.dist-info → halib-0.2.5.dist-info}/licenses/LICENSE.txt +0 -0
- {halib-0.2.4.dist-info → halib-0.2.5.dist-info}/top_level.txt +0 -0
halib/exp/core/base_exp.py
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
from abc import ABC, abstractmethod
|
|
2
2
|
from typing import Tuple, Any, Optional
|
|
3
|
-
from base_config import ExpBaseCfg
|
|
3
|
+
from .base_config import ExpBaseCfg
|
|
4
4
|
from ..perf.perfcalc import PerfCalc
|
|
5
5
|
from ..perf.perfmetrics import MetricsBackend
|
|
6
6
|
|
|
7
|
+
|
|
8
|
+
class ExpHook:
|
|
9
|
+
"""Base interface for all experiment hooks."""
|
|
10
|
+
def on_before_run(self, exp): pass
|
|
11
|
+
def on_after_run(self, exp, results): pass
|
|
12
|
+
|
|
13
|
+
|
|
7
14
|
# ! SEE https://github.com/hahv/base_exp for sample usage
|
|
8
15
|
class BaseExp(PerfCalc, ABC):
|
|
9
16
|
"""
|
|
@@ -16,6 +23,16 @@ class BaseExp(PerfCalc, ABC):
|
|
|
16
23
|
self.metric_backend = None
|
|
17
24
|
# Flag to track if init_general/prepare_dataset has run
|
|
18
25
|
self._is_env_ready = False
|
|
26
|
+
self.hooks = []
|
|
27
|
+
|
|
28
|
+
def register_hook(self, hook: ExpHook):
|
|
29
|
+
self.hooks.append(hook)
|
|
30
|
+
|
|
31
|
+
def _trigger_hooks(self, method_name: str, *args, **kwargs):
|
|
32
|
+
for hook in self.hooks:
|
|
33
|
+
method = getattr(hook, method_name, None)
|
|
34
|
+
if callable(method):
|
|
35
|
+
method(*args, **kwargs)
|
|
19
36
|
|
|
20
37
|
# -----------------------
|
|
21
38
|
# PerfCalc Required Methods
|
|
@@ -52,11 +69,6 @@ class BaseExp(PerfCalc, ABC):
|
|
|
52
69
|
"""
|
|
53
70
|
pass
|
|
54
71
|
|
|
55
|
-
@abstractmethod
|
|
56
|
-
def before_exec_exp_once(self, *args, **kwargs):
|
|
57
|
-
"""Optional: any setup before exec_exp. Note this is called once per run_exp."""
|
|
58
|
-
pass
|
|
59
|
-
|
|
60
72
|
@abstractmethod
|
|
61
73
|
def exec_exp(self, *args, **kwargs) -> Optional[Tuple[Any, Any]]:
|
|
62
74
|
"""Run experiment process, e.g.: training/evaluation loop.
|
|
@@ -64,13 +76,6 @@ class BaseExp(PerfCalc, ABC):
|
|
|
64
76
|
"""
|
|
65
77
|
pass
|
|
66
78
|
|
|
67
|
-
@abstractmethod
|
|
68
|
-
def exec_eval(self, *args, **kwargs) -> Optional[Tuple[Any, Any]]:
|
|
69
|
-
"""Run evaluation process.
|
|
70
|
-
Return: either `None` or a tuple of (raw_metrics_data, extra_data) for calc_and_save_exp_perfs
|
|
71
|
-
"""
|
|
72
|
-
pass
|
|
73
|
-
|
|
74
79
|
# -----------------------
|
|
75
80
|
# Internal Helpers
|
|
76
81
|
# -----------------------
|
|
@@ -121,8 +126,8 @@ class BaseExp(PerfCalc, ABC):
|
|
|
121
126
|
"""
|
|
122
127
|
self._prepare_environment(force_reload=reload_env)
|
|
123
128
|
|
|
124
|
-
|
|
125
|
-
|
|
129
|
+
self._trigger_hooks("before_run", self)
|
|
130
|
+
|
|
126
131
|
# Save config before running
|
|
127
132
|
self.config.save_to_outdir()
|
|
128
133
|
|
|
@@ -135,23 +140,8 @@ class BaseExp(PerfCalc, ABC):
|
|
|
135
140
|
perf_results = self.calc_perfs(
|
|
136
141
|
raw_metrics_data=metrics_data, extra_data=extra_data, *args, **kwargs
|
|
137
142
|
)
|
|
143
|
+
self._trigger_hooks("after_run", self, perf_results)
|
|
138
144
|
return perf_results
|
|
139
145
|
else:
|
|
146
|
+
self._trigger_hooks("after_run", self, results)
|
|
140
147
|
return results
|
|
141
|
-
|
|
142
|
-
# -----------------------
|
|
143
|
-
# Main Experiment Evaluator
|
|
144
|
-
# -----------------------
|
|
145
|
-
def eval_exp(self, reload_env=False, *args, **kwargs):
|
|
146
|
-
"""
|
|
147
|
-
Run evaluation only.
|
|
148
|
-
:param reload_env: If True, forces dataset/general init to run again.
|
|
149
|
-
"""
|
|
150
|
-
self._prepare_environment(force_reload=reload_env)
|
|
151
|
-
results = self.exec_eval(*args, **kwargs)
|
|
152
|
-
if results is not None:
|
|
153
|
-
metrics_data, extra_data = self._validate_and_unpack(results)
|
|
154
|
-
return self.calc_perfs(
|
|
155
|
-
raw_metrics_data=metrics_data, extra_data=extra_data, *args, **kwargs
|
|
156
|
-
)
|
|
157
|
-
return None
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: halib
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.5
|
|
4
4
|
Summary: Small library for common tasks
|
|
5
5
|
Author: Hoang Van Ha
|
|
6
6
|
Author-email: hoangvanhauit@gmail.com
|
|
@@ -53,7 +53,7 @@ Dynamic: summary
|
|
|
53
53
|
|
|
54
54
|
# Helper package for coding and automation
|
|
55
55
|
|
|
56
|
-
**Version 0.2.
|
|
56
|
+
**Version 0.2.5**
|
|
57
57
|
+ reorganize packages with most changes in `research` package; also rename `research` to `exp` (package for experiment management and utilities)
|
|
58
58
|
|
|
59
59
|
**Version 0.2.1**
|
|
@@ -22,7 +22,7 @@ halib/common/rich_color.py,sha256=tyK5fl3Dtv1tKsfFzt_5Rco4Fj72QliA-w5aGXaVuqQ,63
|
|
|
22
22
|
halib/exp/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
23
23
|
halib/exp/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
24
24
|
halib/exp/core/base_config.py,sha256=MtkbToF078imMcsna5Dlv9q4ORKRKkOUCERX7JbVdzM,4180
|
|
25
|
-
halib/exp/core/base_exp.py,sha256=
|
|
25
|
+
halib/exp/core/base_exp.py,sha256=fknJVmW6ubbapOggbkrbNWgc1ZXcUz_FE3wMyuIGX7M,5180
|
|
26
26
|
halib/exp/core/param_gen.py,sha256=I9JHrDCaep4CjvApDoX0QzFuw38zMC2PsDFueuA7pjM,4271
|
|
27
27
|
halib/exp/core/wandb_op.py,sha256=powL2QyLBqF-6PUGAOqd60s1npHLLKJxPns3S4hKeNo,4160
|
|
28
28
|
halib/exp/data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -101,8 +101,8 @@ halib/utils/list.py,sha256=BM-8sRhYyqF7bh4p7TQtV7P_gnFruUCA6DTUOombaZg,337
|
|
|
101
101
|
halib/utils/listop.py,sha256=Vpa8_2fI0wySpB2-8sfTBkyi_A4FhoFVVvFiuvW8N64,339
|
|
102
102
|
halib/utils/tele_noti.py,sha256=-4WXZelCA4W9BroapkRyIdUu9cUVrcJJhegnMs_WpGU,5928
|
|
103
103
|
halib/utils/video.py,sha256=zLoj5EHk4SmP9OnoHjO8mLbzPdtq6gQPzTQisOEDdO8,3261
|
|
104
|
-
halib-0.2.
|
|
105
|
-
halib-0.2.
|
|
106
|
-
halib-0.2.
|
|
107
|
-
halib-0.2.
|
|
108
|
-
halib-0.2.
|
|
104
|
+
halib-0.2.5.dist-info/licenses/LICENSE.txt,sha256=qZssdna4aETiR8znYsShUjidu-U4jUT9Q-EWNlZ9yBQ,1100
|
|
105
|
+
halib-0.2.5.dist-info/METADATA,sha256=AHNT2TyfsLLTRvf81f-Uc5lcPDE5AeSRAKfwp_te-DI,6714
|
|
106
|
+
halib-0.2.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
107
|
+
halib-0.2.5.dist-info/top_level.txt,sha256=7AD6PLaQTreE0Fn44mdZsoHBe_Zdd7GUmjsWPyQ7I-k,6
|
|
108
|
+
halib-0.2.5.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|