Skip to content

Commit

Permalink
fixed double logged train loss and boolean parser
Browse files Browse the repository at this point in the history
  • Loading branch information
MarognaLorenzo committed May 25, 2024
1 parent b4b45c0 commit a087911
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 0 additions & 1 deletion micromind/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,6 @@ def train(
self.accelerator.backward(loss)
self.opt.step()

loss_epoch += loss.item()
if hasattr(self, "lr_sched"):
# ok for cos_lr
self.lr_sched.step()
Expand Down
14 changes: 12 additions & 2 deletions micromind/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ def override_conf(hparams: Dict):
"""
parser = argparse.ArgumentParser(description="MicroMind experiment configuration.")
for key, value in hparams.items():
parser.add_argument(f"--{key}", type=type(value), default=value)

parser.add_argument(f"--{key}", type=str2bool if isinstance(value, bool) else type(value), default=value)
args, extra_args = parser.parse_known_args()
for key, value in vars(args).items():
if value is not None:
Expand Down Expand Up @@ -78,3 +77,14 @@ def get_logger():
logger.add(sys.stderr, format=fmt)

return logger


def str2bool(v):
if isinstance(v, bool):
return v
if v.lower() in ('yes', 'true', 't', 'y', '1'):
return True
elif v.lower() in ('no', 'false', 'f', 'n', '0'):
return False
else:
raise argparse.ArgumentTypeError('Boolean value expected.')

0 comments on commit a087911

Please sign in to comment.