Skip to content

Commit 8d1227e

Browse files
author
Jeff Yang
authored
feat: configurations in separate config file in single template (#38)
1 parent 07b1115 commit 8d1227e

12 files changed

+22
-43
lines changed

app/streamlit_app.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
}
1616

1717
TIP = """
18-
> **💡 TIP**
19-
>
20-
> To quickly adapt to the generated code structure, there are TODOs in the files that are needed to be edited.
21-
> [PyCharm TODO comments](https://www.jetbrains.com/help/pycharm/using-todo.html) or
22-
> [VSCode Todo Tree](https://marketplace.visualstudio.com/items?itemName=Gruntfuggly.todo-tree)
23-
> can help you find them easily.
18+
**💡 TIP**
19+
20+
To quickly adapt to the generated code structure, there are TODOs in the files that are needed to be edited.
21+
[PyCharm TODO comments](https://www.jetbrains.com/help/pycharm/using-todo.html) or
22+
[VSCode Todo Tree](https://marketplace.visualstudio.com/items?itemName=Gruntfuggly.todo-tree)
23+
can help you find them easily.
2424
"""
2525

2626

templates/_base/_find_and_replace.sh

-9
This file was deleted.

templates/single/README.md

+3-13
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ Table of Contents
1818

1919
## Getting Started
2020

21-
- After downloaded and extracted an archive, there will be a folder named `single` (directory name). Inside that there will be an another folder named `single_cg` (package name).
22-
2321
<details>
2422
<summary>
2523
Detailed Directory List
@@ -51,15 +49,7 @@ single
5149

5250
</details>
5351

54-
- Folder names must be renamed by using `mv` command in Unix/macOS and Linux and `move` in Windows. Or simply rename them.
55-
56-
- Since the generated code are using absolute imports, the package name must be renamed to the name you have changed in the above step. There is a `find_and_replace.sh` script (Unix and Linux only) to easily find and replace the package name in the generated code. Usage is:
57-
58-
```sh
59-
bash find_and_replace.sh old_pkg_name new_pkg_name
60-
```
61-
62-
- Install the dependencies with `pip` and install the package in `editable` mode:
52+
- Install the dependencies with `pip` and install the project in `editable` mode:
6353

6454
```sh
6555
pip install -r requirements.txt --progress-bar off -U
@@ -75,8 +65,8 @@ single
7565
7666
- Edit `datasets.py` for your custom datasets and dataloaders.
7767
- Edit `models.py` for your custom models.
78-
- Extend `utils.py` for additional command line arguments.
79-
- Extend `engines.py` for your custom models' forward pass, backward pass, and evaluation.
68+
- Extend `config.py` for additional command line arguments.
69+
- Extend `trainers.py` for your custom models' forward pass, backward pass, and evaluation.
8070
- Extend `handlers.py` for your custom handlers. _(**OPTIONAL**)_
8171

8272
## Training

templates/single/find_and_replace.sh

-1
This file was deleted.

templates/single/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
setuptools
12
torch>=1.7.0
23
pytorch-ignite>=0.4.4
34
{{ handler_deps }}

templates/single/single/config.pyi

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{% include "_argparse.pyi" %}

templates/single/single/events.pyi

-1
This file was deleted.

templates/single/single/main.pyi

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import ignite.distributed as idist
1010
from ignite.engine.events import Events
1111
from ignite.utils import manual_seed
1212

13-
from {{project_name}}.engines import create_engines
14-
from {{project_name}}.events import TrainEvents
13+
from {{project_name}}.trainers import create_trainers, TrainEvents
1514
from {{project_name}}.handlers import get_handlers, get_logger
16-
from {{project_name}}.utils import get_default_parser, setup_logging, log_metrics, log_basic_info, initialize, resume_from
15+
from {{project_name}}.utils import setup_logging, log_metrics, log_basic_info, initialize, resume_from
16+
from {{project_name}}.config import get_default_parser
1717

1818

1919
def run(local_rank: int, config: Any, *args: Any, **kwargs: Any):
@@ -43,7 +43,7 @@ def run(local_rank: int, config: Any, *args: Any, **kwargs: Any):
4343
# train_engine and eval_engine
4444
# -----------------------------
4545

46-
train_engine, eval_engine = create_engines(
46+
train_engine, eval_engine = create_trainers(
4747
config=config,
4848
model=model,
4949
optimizer=optimizer,

templates/single/single/engines.pyi renamed to templates/single/single/trainers.pyi

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ from ignite.engine import Engine
88
from torch.cuda.amp import autocast
99
from torch.optim.optimizer import Optimizer
1010

11-
from {{project_name}}.events import TrainEvents, train_events_to_attr
11+
12+
{% include "_events.pyi" %}
1213

1314

1415
# Edit below functions the way how the model will be training
@@ -116,7 +117,7 @@ def evaluate_function(
116117

117118
# function for creating engines which will be used in main.py
118119
# any necessary arguments can be provided.
119-
def create_engines(**kwargs) -> Tuple[Engine, Engine]:
120+
def create_trainers(**kwargs) -> Tuple[Engine, Engine]:
120121
"""Create Engines for training and evaluation.
121122
122123
Parameters

templates/single/single/utils.pyi

-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ from torch.nn import Module
1919
from torch.optim.lr_scheduler import _LRScheduler
2020
from torch.optim.optimizer import Optimizer
2121

22-
{% include "_argparse.pyi" %}
23-
2422

2523
# we can use `idist.auto_model` to handle distributed configurations
2624
# for your model : https://pytorch.org/ignite/distributed.html#ignite.distributed.auto.auto_model

templates/single/tests/test_engines.pyi renamed to templates/single/tests/test_trainers.pyi

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ from unittest.mock import MagicMock
66
import ignite.distributed as idist
77
import torch
88
from ignite.engine.engine import Engine
9-
from {{project_name}}.engines import create_engines, evaluate_function, train_function
10-
from {{project_name}}.events import TrainEvents, train_events_to_attr
9+
from {{project_name}}.trainers import create_trainers, evaluate_function, train_function, TrainEvents, train_events_to_attr
1110
from torch import nn, optim
1211

1312

@@ -110,8 +109,8 @@ class TestEngines(unittest.TestCase):
110109
output = evaluate_function(config, engine, self.batch, self.model, self.loss_fn, self.device)
111110
self.assertIsInstance(output, Number)
112111

113-
def test_create_engines(self):
114-
train_engine, eval_engine = create_engines(
112+
def test_create_trainers(self):
113+
train_engine, eval_engine = create_trainers(
115114
config=Namespace(use_amp=True),
116115
model=self.model,
117116
loss_fn=self.loss_fn,

templates/single/tests/test_utils.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ from tempfile import TemporaryDirectory
77
import torch
88
from ignite.engine import Engine
99
from ignite.utils import setup_logger
10+
from {{project_name}}.config import get_default_parser
1011
from {{project_name}}.utils import (
11-
get_default_parser,
1212
hash_checkpoint,
1313
log_metrics,
1414
resume_from,

0 commit comments

Comments
 (0)