Skip to content

Commit

Permalink
feat: configurations in separate config file in single template (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Yang committed Apr 3, 2021
1 parent 07b1115 commit 8d1227e
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 43 deletions.
12 changes: 6 additions & 6 deletions app/streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
}

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


Expand Down
9 changes: 0 additions & 9 deletions templates/_base/_find_and_replace.sh

This file was deleted.

16 changes: 3 additions & 13 deletions templates/single/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ Table of Contents

## Getting Started

- 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).

<details>
<summary>
Detailed Directory List
Expand Down Expand Up @@ -51,15 +49,7 @@ single

</details>

- Folder names must be renamed by using `mv` command in Unix/macOS and Linux and `move` in Windows. Or simply rename them.

- 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:

```sh
bash find_and_replace.sh old_pkg_name new_pkg_name
```

- Install the dependencies with `pip` and install the package in `editable` mode:
- Install the dependencies with `pip` and install the project in `editable` mode:

```sh
pip install -r requirements.txt --progress-bar off -U
Expand All @@ -75,8 +65,8 @@ single
- Edit `datasets.py` for your custom datasets and dataloaders.
- Edit `models.py` for your custom models.
- Extend `utils.py` for additional command line arguments.
- Extend `engines.py` for your custom models' forward pass, backward pass, and evaluation.
- Extend `config.py` for additional command line arguments.
- Extend `trainers.py` for your custom models' forward pass, backward pass, and evaluation.
- Extend `handlers.py` for your custom handlers. _(**OPTIONAL**)_

## Training
Expand Down
1 change: 0 additions & 1 deletion templates/single/find_and_replace.sh

This file was deleted.

1 change: 1 addition & 0 deletions templates/single/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
setuptools
torch>=1.7.0
pytorch-ignite>=0.4.4
{{ handler_deps }}
Expand Down
1 change: 1 addition & 0 deletions templates/single/single/config.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% include "_argparse.pyi" %}
1 change: 0 additions & 1 deletion templates/single/single/events.pyi

This file was deleted.

8 changes: 4 additions & 4 deletions templates/single/single/main.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import ignite.distributed as idist
from ignite.engine.events import Events
from ignite.utils import manual_seed

from {{project_name}}.engines import create_engines
from {{project_name}}.events import TrainEvents
from {{project_name}}.trainers import create_trainers, TrainEvents
from {{project_name}}.handlers import get_handlers, get_logger
from {{project_name}}.utils import get_default_parser, setup_logging, log_metrics, log_basic_info, initialize, resume_from
from {{project_name}}.utils import setup_logging, log_metrics, log_basic_info, initialize, resume_from
from {{project_name}}.config import get_default_parser


def run(local_rank: int, config: Any, *args: Any, **kwargs: Any):
Expand Down Expand Up @@ -43,7 +43,7 @@ def run(local_rank: int, config: Any, *args: Any, **kwargs: Any):
# train_engine and eval_engine
# -----------------------------

train_engine, eval_engine = create_engines(
train_engine, eval_engine = create_trainers(
config=config,
model=model,
optimizer=optimizer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ from ignite.engine import Engine
from torch.cuda.amp import autocast
from torch.optim.optimizer import Optimizer

from {{project_name}}.events import TrainEvents, train_events_to_attr

{% include "_events.pyi" %}


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

# function for creating engines which will be used in main.py
# any necessary arguments can be provided.
def create_engines(**kwargs) -> Tuple[Engine, Engine]:
def create_trainers(**kwargs) -> Tuple[Engine, Engine]:
"""Create Engines for training and evaluation.
Parameters
Expand Down
2 changes: 0 additions & 2 deletions templates/single/single/utils.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ from torch.nn import Module
from torch.optim.lr_scheduler import _LRScheduler
from torch.optim.optimizer import Optimizer

{% include "_argparse.pyi" %}


# we can use `idist.auto_model` to handle distributed configurations
# for your model : https://pytorch.org/ignite/distributed.html#ignite.distributed.auto.auto_model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ from unittest.mock import MagicMock
import ignite.distributed as idist
import torch
from ignite.engine.engine import Engine
from {{project_name}}.engines import create_engines, evaluate_function, train_function
from {{project_name}}.events import TrainEvents, train_events_to_attr
from {{project_name}}.trainers import create_trainers, evaluate_function, train_function, TrainEvents, train_events_to_attr
from torch import nn, optim


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

def test_create_engines(self):
train_engine, eval_engine = create_engines(
def test_create_trainers(self):
train_engine, eval_engine = create_trainers(
config=Namespace(use_amp=True),
model=self.model,
loss_fn=self.loss_fn,
Expand Down
2 changes: 1 addition & 1 deletion templates/single/tests/test_utils.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ from tempfile import TemporaryDirectory
import torch
from ignite.engine import Engine
from ignite.utils import setup_logger
from {{project_name}}.config import get_default_parser
from {{project_name}}.utils import (
get_default_parser,
hash_checkpoint,
log_metrics,
resume_from,
Expand Down

0 comments on commit 8d1227e

Please sign in to comment.