-
Notifications
You must be signed in to change notification settings - Fork 676
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename "pipelines" to "tasks" (#311)
- Loading branch information
Showing
8 changed files
with
57 additions
and
58 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 @@ | ||
from src.tasks._task_wrapper import task_wrapper |
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,47 @@ | ||
import time | ||
|
||
from omegaconf import DictConfig | ||
from pytorch_lightning.utilities import rank_zero_only | ||
|
||
from src import utils | ||
|
||
log = utils.get_logger(__name__) | ||
|
||
|
||
def task_wrapper(task_func): | ||
"""Optional decorator that wraps the task function in extra utilities: | ||
- logging the total time of execution | ||
- enabling repeating task execution on failure | ||
- calling the utils.extras() before the task is started | ||
- calling the utils.finish() after the task is finished | ||
""" | ||
|
||
def wrap(cfg: DictConfig): | ||
start = time.time() | ||
|
||
# applies optional config utilities | ||
utils.extras(cfg) | ||
|
||
# TODO: repeat call if fails... | ||
result = task_func(cfg=cfg) | ||
metric_value, object_dict = result | ||
|
||
# make sure everything closed properly | ||
utils.finish(object_dict) | ||
|
||
end = time.time() | ||
save_exec_time(task_name=task_func.__name__, time_in_seconds=end - start) | ||
|
||
assert isinstance(metric_value, float) or metric_value is None | ||
assert isinstance(object_dict, dict) | ||
return metric_value, object_dict | ||
|
||
return wrap | ||
|
||
|
||
@rank_zero_only | ||
def save_exec_time(task_name, time_in_seconds): | ||
with open("execution_time.log", "w+") as file: | ||
file.write("Total execution time.\n") | ||
file.write(task_name + ": " + str(time_in_seconds) + "\n") |
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