Skip to content

Commit

Permalink
Updated for logger.
Browse files Browse the repository at this point in the history
  • Loading branch information
sraashis committed Dec 6, 2023
1 parent dd0e0e2 commit ebdf8f9
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 12 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ class MNISTTrainer(ETRunner):

def new_meter(self):
return ETMeter(
cfm=ConfusionMatrix(num_classes=10, device=self.device['gpu'])
cfm=ConfusionMatrix(num_classes=10),
device=self.device['gpu']
)


Expand Down Expand Up @@ -105,7 +106,8 @@ class MyTrainer(ETRunner):
return ETMeter(
num_averages=1,
prf1a=Prf1a(),
auc=AUCROCMetrics()
auc=AUCROCMetrics(),
device=self.device['gpu']
)

def init_cache(self):
Expand Down
18 changes: 13 additions & 5 deletions easytorch/easytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def _run_test(self, data_split, engine, dataset_cls, distributed=False) -> dict:
""" Run and save experiment test scores """
engine.cache[
'output_csv_TEST'
] = f"{engine.conf['save_dir']}{_sep}test_results_{engine.conf['RUN-ID']}.csv"
] = f"{engine.conf['save_dir']}{_sep}{engine.conf['RUN-ID']}_test_results.csv"
with open(engine.cache[f'output_csv_TEST'], 'w') as rw:
test_out = engine.evaluation(dataloader=dataloader, mode=Phase.TEST,
save_predictions=True, results_writer=rw)
Expand All @@ -251,7 +251,7 @@ def _inference(self, data_split, engine, dataset_cls):

engine.cache[
'output_csv_INFERENCE'
] = f"{engine.conf['save_dir']}{_sep}inference_results_{engine.conf['RUN-ID']}.csv"
] = f"{engine.conf['save_dir']}{_sep}{engine.conf['RUN-ID']}_inference_results.csv"
with open(engine.cache[f'output_csv_INFERENCE'], 'w') as rw:
engine.inference(dataloader=dataloader, results_writer=rw)

Expand All @@ -274,7 +274,13 @@ def run(self, runner_cls: typing.Type[ETRunner],
self._run(runner_cls, dataset_cls, data_handle_cls)

def _run(self, runner_cls, dataset_cls, data_handle_cls):
self.conf['RUN-ID'] = f"RUN{self.conf.get('world_rank', 0)}-" + _uuid.uuid4().hex[:8].upper()
run_id_parts = [
_dtime.now().strftime(f'%Y-%m-%d_%H%M%S'),
f"R{self.conf.get('world_rank', 0)}",
_uuid.uuid4().hex[:8].upper()
]

self.conf['RUN-ID'] = "-".join(run_id_parts)

engine = runner_cls(
conf=self.conf,
Expand All @@ -285,7 +291,8 @@ def _run(self, runner_cls, dataset_cls, data_handle_cls):
)

engine.cache['START-TIME'] = _dtime.now().strftime("%Y-%m-%d %H:%M:%S")
_utils.save_cache(self.conf, {}, name=f"{self.conf['name']}_{self.conf['phase']}".upper())
_utils.save_cache(self.conf, {},
name=f"{engine.conf['RUN-ID']}_{self.conf['name']}_{self.conf['phase']}")

self._prepare_nn_engine(engine)

Expand All @@ -303,4 +310,5 @@ def _run(self, runner_cls, dataset_cls, data_handle_cls):
self._inference(data_split, engine, dataset_cls)
_cleanup(engine, engine.data_handle)
engine.cache['END-TIME'] = _dtime.now().strftime("%Y-%m-%d %H:%M:%S")
_utils.save_cache(self.conf, engine.cache, name=f"{engine.conf['name']}_{self.conf['phase']}".upper())
_utils.save_cache(self.conf, engine.cache,
name=f"{engine.conf['RUN-ID']}_{self.conf['name']}_{self.conf['phase']}")
6 changes: 5 additions & 1 deletion easytorch/metrics/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,13 @@ def dist_gather(self, device='cpu'):


class ETMeter:
def __init__(self, num_averages=1, **kw):
def __init__(self, num_averages=1, device='cpu', **kw):
self.averages = ETAverages(num_averages)
self.device = device
self.metrics = {**kw}
for mk in self.metrics:
self.metrics[mk].device = self.device
self.metrics[mk].reset()

def get(self):
res = self.averages.get()
Expand Down
5 changes: 3 additions & 2 deletions examples/MNIST_easytorch_CNN.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,9 @@
" def new_meter(self):\n",
" return ETMeter(\n",
" num_averages=2, # Since we are tracing two losses\n",
" cmf=ConfusionMatrix(num_classes=10, device=self.device['gpu']),\n",
" auc=AUCROCMetrics()\n",
" cmf=ConfusionMatrix(num_classes=10),\n",
" auc=AUCROCMetrics(),\n",
" device=self.device['gpu']\n",
" )"
]
},
Expand Down
3 changes: 2 additions & 1 deletion examples/MNIST_easytorch_CNN.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ def init_cache(self):
def new_meter(self):
return ETMeter(
num_averages=2, # Since we are tracing two losses
cmf=ConfusionMatrix(num_classes=10, device=self.device['gpu']),
cmf=ConfusionMatrix(num_classes=10),
auc=AUCROCMetrics(),
device=self.device['gpu']
)


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# This call to setup() does all the work
setup(
name="easytorch",
version="3.8.4",
version="3.8.5",
description="Easy Neural Network Experiments with pytorch",
long_description=_README,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit ebdf8f9

Please sign in to comment.