Skip to content

Commit 5b2cbae

Browse files
author
Jeff Yang
authored
feat(handlers): add common training handlers template (#26)
* feat(handlers): add common training handlers template * extract each section into function, include template in main.py * fix: add to_save, string quote, trainer * chore: common training handlers default value
1 parent 9b7d661 commit 5b2cbae

11 files changed

+223
-646
lines changed

app/codegen.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ def __init__(self, templates_dir: str = "./templates", dist_dir: str = "./dist")
1717
def render_templates(self, template_name: str, config: dict):
1818
"""Renders all the templates files from template folder for the given config."""
1919
self.rendered_code[template_name] = {} # clean up the rendered code for given template
20-
# loading the template files based on given template
20+
# loading the template files based on given template and from the _base folder
21+
# since we are using some templates from _base folder
22+
loader = FileSystemLoader([self.templates_dir / "_base", self.templates_dir / template_name])
2123
env = Environment(
22-
loader=FileSystemLoader(self.templates_dir / template_name),
24+
loader=loader,
2325
trim_blocks=True,
2426
lstrip_blocks=True,
2527
)

templates/_base/_handlers.pyi

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from ignite.contrib.engines import common
2+
{% if setup_common_training_handlers %}
3+
common.setup_common_training_handlers(
4+
trainer=trainer,
5+
train_sampler=None,
6+
to_save=to_save,
7+
output_path='{{ output_path }}',
8+
save_every_iters={{ save_every_iters }},
9+
n_saved={{ n_saved }},
10+
log_every_iters={{ log_every_iters }},
11+
with_pbars={{ with_pbars }},
12+
with_pbar_on_iters={{ with_pbar_on_iters }},
13+
stop_on_nan={{ stop_on_nan }},
14+
clear_cuda_cache={{ clear_cuda_cache }},
15+
lr_scheduler=None,
16+
with_gpu_stats=False,
17+
output_names=None,
18+
)
19+
{% endif %}

templates/_base/datasets.py.jinja

-21
This file was deleted.

templates/_base/fn.py.jinja

-66
This file was deleted.

templates/_base/main.py.jinja

-139
This file was deleted.

templates/_base/models.py.jinja

-8
This file was deleted.

0 commit comments

Comments
 (0)