-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Description
TrainExtension has a setup() but not a tear_down() / end() / terminate() / whatever(). That's probably because it is not needed most of the time.
One use case for it would be with the LiveMonitoring that binds to ports but never unbinds. It can be easily re-factored to bind in setup() and unbind in tear_down().
(one may argue that, in an yaml file, LiveMonitoring instance can be shared).
The implementation would change train.py:
def tear_down(self):
"""
Called at the end of main loop.
"""
self.tear_down_extensions()
# Does the algorithm also needs one?
#if self.algorithm is not None:
# self.algorithm.tear_down()
def tear_down_extensions(self):
""" Calls tear_down on all extensions."""
for ext in self.extensions:
ext.tear_down(self.model, self.dataset, self.algorithm)self.tear_down() would then be called at the end of main loop.
Bonus points
How would you feel about wrapping the main loop in a try ... except like so:
def main_loop(self, time_budget=None):
t0 = datetime.now()
self.setup()
try:
if self.algorithm is None:
# ...
if self.save_freq > 0:
self.save()
except:
raise
finally:
self.tear_down()?
Metadata
Metadata
Assignees
Labels
No labels