Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed double logged train loss and boolean parser #91

Merged
merged 2 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

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: 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
18 changes: 16 additions & 2 deletions micromind/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ 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 +81,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.")
Loading