Skip to content
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
23 changes: 16 additions & 7 deletions deepmd/pt/train/training.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
"kf_limit_pref_e": params.get("kf_limit_pref_e", 1),
"kf_start_pref_f": params.get("kf_start_pref_f", 1),
"kf_limit_pref_f": params.get("kf_limit_pref_f", 1),
"weight_decay": params.get("weight_decay", 0.001),
}
return opt_type, opt_param

Expand Down Expand Up @@ -609,12 +610,20 @@

# TODO add optimizers for multitask
# author: iProzd
if self.opt_type == "Adam":
self.optimizer = torch.optim.Adam(
self.wrapper.parameters(),
lr=self.lr_exp.start_lr,
fused=False if DEVICE.type == "cpu" else True,
)
if self.opt_type in ["Adam", "AdamW"]:
if self.opt_type == "Adam":
self.optimizer = torch.optim.Adam(
self.wrapper.parameters(),
lr=self.lr_exp.start_lr,
fused=False if DEVICE.type == "cpu" else True,
)
else:
self.optimizer = torch.optim.AdamW(

Check warning on line 621 in deepmd/pt/train/training.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/train/training.py#L621

Added line #L621 was not covered by tests
Comment thread
iProzd marked this conversation as resolved.
self.wrapper.parameters(),
lr=self.lr_exp.start_lr,
weight_decay=float(self.opt_param["weight_decay"]),
fused=False if DEVICE.type == "cpu" else True,
)
if optimizer_state_dict is not None and self.restart_training:
self.optimizer.load_state_dict(optimizer_state_dict)
self.scheduler = torch.optim.lr_scheduler.LambdaLR(
Expand Down Expand Up @@ -710,7 +719,7 @@
print_str = f"Step {_step_id}: sample system{log_dict['sid']} frame{log_dict['fid']}\n"
fout1.write(print_str)
fout1.flush()
if self.opt_type == "Adam":
if self.opt_type in ["Adam", "AdamW"]:
cur_lr = self.scheduler.get_last_lr()[0]
if _step_id < self.warmup_steps:
pref_lr = _lr.start_lr
Expand Down
1 change: 1 addition & 0 deletions deepmd/utils/argcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -3177,6 +3177,7 @@ def training_args(
"opt_type",
choices=[
Argument("Adam", dict, [], [], optional=True),
Argument("AdamW", dict, [], [], optional=True),
Argument(
"LKF",
dict,
Expand Down