Skip to content
Closed
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
de9ff13
Added pythion-fire as default argument parser
guptaaryan16 Jul 20, 2023
4067218
Added Python-Fire as Default Argument Parser
guptaaryan16 Jul 20, 2023
cdf63cd
Merge branch 'python-fire' of https://github.com/guptaaryan16/code-ge…
guptaaryan16 Jul 20, 2023
8c00268
Add fire to requirements.txt
guptaaryan16 Jul 20, 2023
6d18005
Fix tests
guptaaryan16 Jul 20, 2023
38b54be
Added fire as a requirement in templates
guptaaryan16 Jul 21, 2023
8a7da4d
Add fire as requirement in CI
guptaaryan16 Jul 24, 2023
884f329
Changed error for output dir
guptaaryan16 Jul 24, 2023
4a06b83
fix setup_loggings function in utils.py
guptaaryan16 Jul 24, 2023
d0c1595
Changed some file
guptaaryan16 Jul 24, 2023
066bc3b
Change settings for config.output_dir
guptaaryan16 Jul 25, 2023
8f8093a
Adding option for Different ArgumentParsers and Reverting tests fixes
guptaaryan16 Jul 27, 2023
d663808
Introducing UI features for selecting ArgParsers in templates
guptaaryan16 Jul 28, 2023
69f26bc
Format files and fix bugs for python-fire
guptaaryan16 Jul 28, 2023
182e0d6
Updated the 'python-fire' to fire
guptaaryan16 Jul 30, 2023
afded70
Added changes to the main file
guptaaryan16 Jul 31, 2023
6b7162b
changed the fmt
guptaaryan16 Jul 31, 2023
465e08d
Update ci.yml
guptaaryan16 Jul 31, 2023
bff5afd
Made some formatting changes and added necessary import conditions
guptaaryan16 Jul 31, 2023
4fad607
Update ci.yml
guptaaryan16 Jul 31, 2023
7dcd79f
Made the change for if condition in python-fire
guptaaryan16 Aug 1, 2023
bceeff3
Made some formatting changes and added the shutil option
guptaaryan16 Aug 1, 2023
8030856
Made changes to imports according to python-fire
guptaaryan16 Aug 1, 2023
ee89b15
Added a change in the configuration
guptaaryan16 Aug 1, 2023
03b4736
Update ci.yml
guptaaryan16 Aug 1, 2023
0c777d0
Fix CI
guptaaryan16 Aug 1, 2023
778fcb0
Merge branch 'test_python_fire' of https://github.com/guptaaryan16/co…
guptaaryan16 Aug 1, 2023
ac071a2
Some formatting for dist_lint
guptaaryan16 Aug 1, 2023
a22d8c9
Fix tests for CI
guptaaryan16 Aug 1, 2023
19132b7
Update ci.yml
guptaaryan16 Aug 1, 2023
4cb90e6
Merge branch 'python-fire' of https://github.com/guptaaryan16/code-ge…
guptaaryan16 Aug 2, 2023
ba86a8f
Try to edit formatting for the PR
guptaaryan16 Aug 2, 2023
8ff8357
Merge branch 'pytorch-ignite:main' into python-fire
guptaaryan16 Aug 10, 2023
156ab1b
Merge branch 'python-fire' of https://github.com/guptaaryan16/code-ge…
guptaaryan16 Aug 10, 2023
916ff6f
Fix brackets in config.output_dir/config-lock.yaml
guptaaryan16 Aug 10, 2023
e72e9b9
Changed `pnpm run test` script and CI to add option for text based ma…
guptaaryan16 Aug 10, 2023
7ceb6a1
Add test files for python-fire based arguments
guptaaryan16 Aug 10, 2023
5d198e9
Added script and CI workflow for Python fire
guptaaryan16 Aug 10, 2023
a97ef74
fix fmt
guptaaryan16 Aug 10, 2023
c73c817
Made some refactoring of tests and add argparser keyword in normal te…
guptaaryan16 Aug 10, 2023
168951e
fix port in templates
guptaaryan16 Aug 10, 2023
36ac5f0
fix bugs in ci.yaml and utils.yaml
guptaaryan16 Aug 10, 2023
e5f82b3
fix `pnpm run dist_lint` for argparse and python-fire
guptaaryan16 Aug 10, 2023
cd4a310
bug fixes
guptaaryan16 Aug 11, 2023
fdbbd93
try to fix ci.yaml
guptaaryan16 Aug 11, 2023
4b572d4
fix tests for argparser
guptaaryan16 Aug 11, 2023
45028d5
fix bugs
guptaaryan16 Aug 11, 2023
07d5dd7
fix ci pnpm dist_lint and few bugs
guptaaryan16 Aug 11, 2023
d797f79
made some changes
guptaaryan16 Aug 11, 2023
c1936fe
Fix bugs and parametrize tests
guptaaryan16 Aug 11, 2023
e7191d2
fix utils.py for argparse
guptaaryan16 Aug 11, 2023
aadcdd3
fix bugs
guptaaryan16 Aug 12, 2023
ae02110
Made changes for spawn in templates accorging to https://pytorch-igni…
guptaaryan16 Aug 14, 2023
981bb25
added bug fixes and removed DotDict for easydict
guptaaryan16 Aug 14, 2023
0193479
fmt fix
guptaaryan16 Aug 14, 2023
b664423
Revert "fmt fix"
guptaaryan16 Aug 14, 2023
d7b5655
Added DictConfig(OmegaConfig) as a substitute to easydict
guptaaryan16 Aug 14, 2023
f582019
lint fix
guptaaryan16 Aug 14, 2023
374befe
add omegaconf to requirements.txt in CI
guptaaryan16 Aug 14, 2023
e189d65
Merge branch 'main' into python-fire
vfdev-5 Aug 14, 2023
0f43798
Removed unzip_all function from run_tests_fire.sh
guptaaryan16 Aug 14, 2023
c291955
Added None check in python-fire config storage and docs link in the R…
guptaaryan16 Aug 15, 2023
034fcf6
Merge branch 'python-fire' of https://github.com/guptaaryan16/code-ge…
guptaaryan16 Aug 15, 2023
4a30ad6
Update src/templates/template-text-classification/main.py
guptaaryan16 Aug 15, 2023
1f6a93e
fmt fix and "value is not None" fix for main.py files in templates
guptaaryan16 Aug 15, 2023
8df0609
Changed the config copy logic in templates
guptaaryan16 Aug 15, 2023
5927270
Fix fmt dist_lint issues
guptaaryan16 Aug 15, 2023
2ed5929
Bug fixes
guptaaryan16 Aug 16, 2023
0386877
fmt fix
guptaaryan16 Aug 16, 2023
507995c
Fix bugs
guptaaryan16 Aug 16, 2023
6137c01
fmt fix
guptaaryan16 Aug 16, 2023
0497bd8
Made necessary changes
guptaaryan16 Aug 16, 2023
dfb64d6
removed unncessary code in store config-lock.yaml
guptaaryan16 Aug 16, 2023
97c1151
Make omegaconfig default requirement in all templates
guptaaryan16 Aug 16, 2023
dc4e5b0
Revert the TrainingTab.vue change from 'Configuration Options' to 'Tr…
guptaaryan16 Aug 16, 2023
5083908
add 'setup_config_saving' in utils.py
guptaaryan16 Aug 17, 2023
568f42a
fix bug in setup_config_saving
guptaaryan16 Aug 17, 2023
548b3d2
bugs fix in templates
guptaaryan16 Aug 17, 2023
f88980f
Merge branch 'main' of https://github.com/guptaaryan16/code-generator…
guptaaryan16 Aug 17, 2023
1d71dff
fix default argparser import
guptaaryan16 Aug 17, 2023
7f99957
fix bugs in templates
guptaaryan16 Aug 17, 2023
47edf95
Merge branch 'main' of https://github.com/guptaaryan16/code-generator…
guptaaryan16 Aug 17, 2023
72add75
fix `from argparse import ArgumentParser
guptaaryan16 Aug 17, 2023
fc311d7
Add docs and links to argument parsers in TabTraining.vue
guptaaryan16 Aug 17, 2023
5e4ebc6
changed description of TrainingTab.vue Training options
guptaaryan16 Aug 17, 2023
6bd1841
Changed save_config API for utils.py
guptaaryan16 Aug 18, 2023
4822e98
fmt fix
guptaaryan16 Aug 18, 2023
0f96ca5
Revert str method use in 'setup_output_dir' in utils.py
guptaaryan16 Aug 18, 2023
d324180
Update utils.py
guptaaryan16 Aug 18, 2023
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scripts/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ pytest
transformers
datasets
tensorboard
fire
8 changes: 8 additions & 0 deletions src/components/TabTraining.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<template>
<div class="tab training">
<h1>Training Options</h1>
<h2>Argument Parser</h2>
<FormSelect
:label="argparser.description"
:options="argparser.options"
:saveKey="argparser.name"
:defaultV="argparser.default"
/>
<h2 class="training">Deterministic Training</h2>
<FormCheckbox
:label="deterministic.description"
Expand Down Expand Up @@ -80,6 +87,7 @@ export default {
saveConfig(deterministic.name, isDeterministic.value)
})
return {
...training,
store,
deterministic,
backend,
Expand Down
7 changes: 7 additions & 0 deletions src/metadata/metadata.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{
"training": {
"argparser": {
"name": "argparser",
"type": "array",
"description": "Select the argument parser for training",
"options": ["argparse", "python-fire"],
"default": "argparse"
},
"deterministic": {
"name": "deterministic",
"type": "checkbox",
Expand Down
8 changes: 8 additions & 0 deletions src/templates/template-common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ nproc_per_node: #:::= it.nproc_per_node :::#
```

```sh
#::: if (['python-fire'].includes(it.argparser)) { :::#
python main.py config.yaml --backend #:::= it.backend :::# [--override_arg=value]
#::: } else { :::#
python main.py config.yaml --backend #:::= it.backend :::#
#::: } :::#
```

#::: } :::#
Expand All @@ -155,7 +159,11 @@ python main.py config.yaml --backend #:::= it.backend :::#
### 1 GPU Training

```sh
#::: if (['python-fire'].includes(it.argparser)) { :::#
python main.py config.yaml [--override_arg=value]
#::: } else { :::#
python main.py config.yaml
#::: } :::#
```

#::: } :::#
19 changes: 16 additions & 3 deletions src/templates/template-common/main.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
# main entrypoint
#::: if (['python-fire'].includes(it.argparser)) { :::#
def main(config_path, output_path="./runs", render_mode=None, **kwargs):
config_path = Path(config_path)
assert config_path.exists(), config_path
config = setup_config(config_path, **kwargs)


#::: } else { :::#
def main():
config = setup_config()
#::: } :::#
#::: if (it.dist === 'spawn') { :::#
#::: if (it.nproc_per_node && it.nnodes > 1 && it.master_addr && it.master_port) { :::#
kwargs = {
kwargs_backend = {
"nproc_per_node": config.nproc_per_node,
"nnodes": config.nnodes,
"node_rank": config.node_rank,
"master_addr": config.master_addr,
"master_port": config.master_port,
}
#::: } else if (it.nproc_per_node) { :::#
kwargs = {"nproc_per_node": config.nproc_per_node}
kwargs_backend = {"nproc_per_node": config.nproc_per_node}
#::: } :::#
with idist.Parallel(config.backend, **kwargs) as p:
with idist.Parallel(config.backend, **kwargs_backend) as p:
p.run(run, config=config)
#::: } else { :::#
with idist.Parallel(config.backend) as p:
Expand All @@ -22,4 +31,8 @@ def main():


if __name__ == "__main__":
#::: if (['python-fire'].includes(it.argparser)) { :::#
fire.Fire(main)
#::: } else { :::#
main()
#::: } :::#
3 changes: 3 additions & 0 deletions src/templates/template-common/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ torch>=1.10.2
torchvision>=0.11.3
pytorch-ignite>=0.4.8
pyyaml
#::: if (['python-fire'].includes(it.argparser)) { :::#
#:::= it.argparser :::#
#::: } :::#

#::: if (['neptune', 'polyaxon'].includes(it.logger)) { :::#

Expand Down
41 changes: 35 additions & 6 deletions src/templates/template-common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,37 @@
from ignite.utils import setup_logger


#::: if (['python-fire'].includes(it.argparser)) { :::#


class DotDict(dict):
"""
Dictionary subclass that allows dot notation access to keys.
"""

def __getattr__(self, attr):
value = self.get(attr)
if isinstance(value, dict):
return DotDict(value)
return value


def setup_config(config_path, **kwargs):
with open(config_path, "r") as f:
config = yaml.safe_load(f.read())
for k, v in kwargs.items():
if k in config:
print(f"Override parameter {k}: {config[k]} -> {v}")
else:
print(f"{k} parameter not in {config_path}")
config[k] = v

return DotDict(config)


#::: } else { :::#


def get_default_parser():
parser = ArgumentParser()
parser.add_argument("config", type=Path, help="Config file path")
Expand All @@ -53,13 +84,8 @@ def get_default_parser():
def setup_config(parser=None):
if parser is None:
parser = get_default_parser()

args = parser.parse_args()
args = parser.parse_args()
config_path = args.config

with open(config_path, "r") as f:
config = yaml.safe_load(f.read())

optional_attributes = ["train_epoch_length", "eval_epoch_length"]
for attr in optional_attributes:
config[attr] = config.get(attr, None)
Expand All @@ -70,6 +96,9 @@ def setup_config(parser=None):
return args


#::: } :::#


def log_metrics(engine: Engine, tag: str) -> None:
"""Log `engine.state.metrics` with given `engine` and `tag`.

Expand Down
9 changes: 6 additions & 3 deletions src/templates/template-text-classification/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
from pprint import pformat
from shutil import copy
from typing import Any

import ignite.distributed as idist
Expand All @@ -13,6 +12,8 @@
from torch import nn, optim
from trainers import setup_evaluator, setup_trainer
from utils import *
import fire


os.environ["TOKENIZERS_PARALLELISM"] = "false" # remove tokenizer paralleism warning

Expand All @@ -25,7 +26,9 @@ def run(local_rank: int, config: Any):
# create output folder and copy config file to output dir
config.output_dir = setup_output_dir(config, rank)
if rank == 0:
copy(config.config, f"{config.output_dir}/config-lock.yaml")
with open(f"{config.output_dir}/config-lock.yaml", "a+") as f:
for key, value in config.items():
f.write(f"{key}: {value}\n")

# donwload datasets and create dataloaders
dataloader_train, dataloader_eval = setup_data(config)
Expand Down Expand Up @@ -69,7 +72,7 @@ def run(local_rank: int, config: Any):
# setup engines logger with python logging
# print training configurations
logger = setup_logging(config)
logger.info("Configuration: \n%s", pformat(vars(config)))
logger.info("Configuration: \n%s", pformat(config))
trainer.logger = evaluator.logger = logger

trainer.add_event_handler(Events.ITERATION_COMPLETED, lr_scheduler)
Expand Down
3 changes: 3 additions & 0 deletions src/templates/template-text-classification/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ pytorch-ignite>=0.4.8
pyyaml
transformers
datasets
#::: if (['python-fire'].includes(it.argparser)) { :::#
#:::= it.argparser :::#
#::: } :::#

#::: if (['neptune', 'polyaxon'].includes(it.logger)) { :::#

Expand Down
8 changes: 5 additions & 3 deletions src/templates/template-vision-classification/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from pprint import pformat
from shutil import copy
from typing import Any

import ignite.distributed as idist
Expand All @@ -12,6 +11,7 @@
from torch import nn, optim
from trainers import setup_evaluator, setup_trainer
from utils import *
import fire


def run(local_rank: int, config: Any):
Expand All @@ -22,7 +22,9 @@ def run(local_rank: int, config: Any):
# create output folder and copy config file to output dir
config.output_dir = setup_output_dir(config, rank)
if rank == 0:
copy(config.config, f"{config.output_dir}/config-lock.yaml")
with open(f"{config.output_dir}/config-lock.yaml", "a+") as f:
for key, value in config.items():
f.write(f"{key}: {value}\n")

# donwload datasets and create dataloaders
dataloader_train, dataloader_eval = setup_data(config)
Expand Down Expand Up @@ -59,7 +61,7 @@ def run(local_rank: int, config: Any):
# setup engines logger with python logging
# print training configurations
logger = setup_logging(config)
logger.info("Configuration: \n%s", pformat(vars(config)))
logger.info("Configuration: \n%s", pformat(config))
trainer.logger = evaluator.logger = logger

trainer.add_event_handler(Events.ITERATION_COMPLETED, lr_scheduler)
Expand Down
3 changes: 3 additions & 0 deletions src/templates/template-vision-classification/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ torch>=1.10.2
torchvision>=0.11.3
pytorch-ignite>=0.4.8
pyyaml
#::: if (['python-fire'].includes(it.argparser)) { :::#
#:::= it.argparser :::#
#::: } :::#

#::: if (['neptune', 'polyaxon'].includes(it.logger)) { :::#

Expand Down
12 changes: 9 additions & 3 deletions src/templates/template-vision-dcgan/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from pprint import pformat
from shutil import copy
from typing import Any

import ignite.distributed as idist
Expand All @@ -13,6 +12,11 @@
from trainers import setup_evaluator, setup_trainer
from utils import *

#::: if (it.
# ) { :::#
import fire


FAKE_IMG_FNAME = "fake_sample_epoch_{:04d}.png"
REAL_IMG_FNAME = "real_sample_epoch_{:04d}.png"

Expand All @@ -25,7 +29,9 @@ def run(local_rank: int, config: Any):
# create output folder and copy config file to output dir
config.output_dir = setup_output_dir(config, rank)
if rank == 0:
copy(config.config, f"{config.output_dir}/config-lock.yaml")
with open(f"{config.output_dir}/config-lock.yaml", "a+") as f:
for key, value in config.items():
f.write(f"{key}: {value}\n")

# donwload datasets and create dataloaders
dataloader_train, dataloader_eval, num_channels = setup_data(config)
Expand Down Expand Up @@ -74,7 +80,7 @@ def run(local_rank: int, config: Any):
# setup engines logger with python logging
# print training configurations
logger = setup_logging(config)
logger.info("Configuration: \n%s", pformat(vars(config)))
logger.info("Configuration: \n%s", pformat(config))
trainer.logger = evaluator.logger = logger

#::: if (it.save_training || it.save_evaluation) { :::#
Expand Down
3 changes: 3 additions & 0 deletions src/templates/template-vision-dcgan/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ torch>=1.10.2
torchvision>=0.11.3
pytorch-ignite>=0.4.8
pyyaml
#::: if (['python-fire'].includes(it.argparser)) { :::#
#:::= it.argparser :::#
#::: } :::#

#::: if (['neptune', 'polyaxon'].includes(it.logger)) { :::#

Expand Down
9 changes: 6 additions & 3 deletions src/templates/template-vision-segmentation/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from functools import partial
from pprint import pformat
from shutil import copy
from typing import Any, cast

import ignite.distributed as idist
Expand All @@ -14,8 +13,10 @@
from torch.optim.lr_scheduler import LambdaLR
from trainers import setup_evaluator, setup_trainer
from utils import *
import fire
from vis import predictions_gt_images_handler


try:
from torch.optim.lr_scheduler import LRScheduler as PyTorchLRScheduler
except ImportError:
Expand All @@ -30,7 +31,9 @@ def run(local_rank: int, config: Any):
# create output folder and copy config file to output dir
config.output_dir = setup_output_dir(config, rank)
if rank == 0:
copy(config.config, f"{config.output_dir}/config-lock.yaml")
with open(f"{config.output_dir}/config-lock.yaml", "a+") as f:
for key, value in config.items():
f.write(f"{key}: {value}\n")

# donwload datasets and create dataloaders
dataloader_train, dataloader_eval = setup_data(config)
Expand Down Expand Up @@ -72,7 +75,7 @@ def run(local_rank: int, config: Any):
# setup engines logger with python logging
# print training configurations
logger = setup_logging(config)
logger.info("Configuration: \n%s", pformat(vars(config)))
logger.info("Configuration: \n%s", pformat(config))
trainer.logger = evaluator.logger = logger

if isinstance(lr_scheduler, PyTorchLRScheduler):
Expand Down
5 changes: 5 additions & 0 deletions src/templates/template-vision-segmentation/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ pytorch-ignite>=0.4.8
pyyaml
albumentations>=1.3.0
image_dataset_viz
#::: if (['python-fire'].includes(it.argparser)) { :::#

#:::= it.argparser :::#

#::: } :::#

#::: if (['neptune', 'polyaxon'].includes(it.logger)) { :::#

Expand Down