Skip to content

Commit

Permalink
feat(handlers): add common training handlers template (#26)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Jeff Yang committed Mar 26, 2021
1 parent 9b7d661 commit 5b2cbae
Show file tree
Hide file tree
Showing 11 changed files with 223 additions and 646 deletions.
6 changes: 4 additions & 2 deletions app/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ def __init__(self, templates_dir: str = "./templates", dist_dir: str = "./dist")
def render_templates(self, template_name: str, config: dict):
"""Renders all the templates files from template folder for the given config."""
self.rendered_code[template_name] = {} # clean up the rendered code for given template
# loading the template files based on given template
# loading the template files based on given template and from the _base folder
# since we are using some templates from _base folder
loader = FileSystemLoader([self.templates_dir / "_base", self.templates_dir / template_name])
env = Environment(
loader=FileSystemLoader(self.templates_dir / template_name),
loader=loader,
trim_blocks=True,
lstrip_blocks=True,
)
Expand Down
19 changes: 19 additions & 0 deletions templates/_base/_handlers.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from ignite.contrib.engines import common
{% if setup_common_training_handlers %}
common.setup_common_training_handlers(
trainer=trainer,
train_sampler=None,
to_save=to_save,
output_path='{{ output_path }}',
save_every_iters={{ save_every_iters }},
n_saved={{ n_saved }},
log_every_iters={{ log_every_iters }},
with_pbars={{ with_pbars }},
with_pbar_on_iters={{ with_pbar_on_iters }},
stop_on_nan={{ stop_on_nan }},
clear_cuda_cache={{ clear_cuda_cache }},
lr_scheduler=None,
with_gpu_stats=False,
output_names=None,
)
{% endif %}
21 changes: 0 additions & 21 deletions templates/_base/datasets.py.jinja

This file was deleted.

66 changes: 0 additions & 66 deletions templates/_base/fn.py.jinja

This file was deleted.

139 changes: 0 additions & 139 deletions templates/_base/main.py.jinja

This file was deleted.

8 changes: 0 additions & 8 deletions templates/_base/models.py.jinja

This file was deleted.

0 comments on commit 5b2cbae

Please sign in to comment.