Skip to content

Commit dff5cf4

Browse files
committed
fix
1 parent 782d17b commit dff5cf4

3 files changed

Lines changed: 17 additions & 16 deletions

File tree

deepmd/dpmodel/utils/learning_rate.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,12 @@ def __init__(
118118
self.warmup_start_lr = warmup_start_factor * start_lr
119119

120120
# === Step 7. Store core parameters ===
121-
self.start_lr = start_lr
121+
self._start_lr = start_lr
122122
self.num_steps = num_steps
123123
# Decay phase covers (num_steps - warmup_steps) steps
124124
self.decay_num_steps = num_steps - self.warmup_steps
125125

126+
@property
126127
def start_lr(self) -> float:
127128
"""
128129
Get the starting learning rate.
@@ -132,7 +133,7 @@ def start_lr(self) -> float:
132133
float
133134
The starting learning rate.
134135
"""
135-
return self.start_lr
136+
return self._start_lr
136137

137138
@abstractmethod
138139
def _decay_value(self, step: int | Array) -> Array:
@@ -184,7 +185,7 @@ def value(self, step: int | Array) -> Array | float:
184185
warmup_progress = xp.astype(step, xp.float64) / self.warmup_steps
185186
warmup_lr = (
186187
self.warmup_start_lr
187-
+ (self.start_lr - self.warmup_start_lr) * warmup_progress
188+
+ (self._start_lr - self.warmup_start_lr) * warmup_progress
188189
)
189190

190191
# === Step 3. Decay phase ===
@@ -338,7 +339,7 @@ def __init__(
338339
self.decay_rate = 1.0 # No decay
339340
else:
340341
self.decay_rate = np.exp(
341-
np.log(clamped_stop_lr / self.start_lr)
342+
np.log(clamped_stop_lr / self._start_lr)
342343
/ (decay_total / self.decay_steps)
343344
).item()
344345

@@ -367,7 +368,7 @@ def _decay_value(self, step: int | Array) -> Array:
367368
exponent = xp.astype(step, xp.float64) / self.decay_steps
368369
else:
369370
exponent = xp.astype(step // self.decay_steps, xp.float64)
370-
step_lr = self.start_lr * xp.pow(
371+
step_lr = self._start_lr * xp.pow(
371372
xp.asarray(self.decay_rate, device=array_api_compat.device(step)),
372373
exponent,
373374
)
@@ -472,11 +473,11 @@ def _decay_value(self, step: int | Array) -> Array:
472473
if not array_api_compat.is_array_api_obj(step):
473474
step = np.asarray(step)
474475
xp = array_api_compat.array_namespace(step)
475-
min_lr = self.start_lr * self.lr_min_factor
476+
min_lr = self._start_lr * self.lr_min_factor
476477
# Handle decay_num_steps=0 (no training steps) - return start_lr
477478
if self.decay_num_steps == 0:
478-
return xp.full_like(step, self.start_lr, dtype=xp.float64)
479-
step_lr = self.start_lr * (
479+
return xp.full_like(step, self._start_lr, dtype=xp.float64)
480+
step_lr = self._start_lr * (
480481
self.lr_min_factor
481482
+ 0.5
482483
* (1 - self.lr_min_factor)

deepmd/pd/train/training.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,9 +580,9 @@ def single_model_finetune(
580580
# author: iProzd
581581
if self.opt_type == "Adam":
582582
self.scheduler = paddle.optimizer.lr.LambdaDecay(
583-
learning_rate=self.lr_exp.start_lr(),
583+
learning_rate=self.lr_exp.start_lr,
584584
lr_lambda=lambda step: self.lr_exp.value(step + self.start_step)
585-
/ self.lr_exp.start_lr(),
585+
/ self.lr_exp.start_lr,
586586
)
587587
self.optimizer = paddle.optimizer.Adam(
588588
learning_rate=self.scheduler, parameters=self.wrapper.parameters()

deepmd/pt/train/training.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -688,13 +688,13 @@ def single_model_finetune(
688688
if self.opt_type == "Adam":
689689
self.optimizer = torch.optim.Adam(
690690
self.wrapper.parameters(),
691-
lr=self.lr_exp.start_lr(),
691+
lr=self.lr_exp.start_lr,
692692
fused=False if DEVICE.type == "cpu" else True,
693693
)
694694
else:
695695
self.optimizer = torch.optim.AdamW(
696696
self.wrapper.parameters(),
697-
lr=self.lr_exp.start_lr(),
697+
lr=self.lr_exp.start_lr,
698698
weight_decay=float(self.opt_param["weight_decay"]),
699699
fused=False if DEVICE.type == "cpu" else True,
700700
)
@@ -703,7 +703,7 @@ def single_model_finetune(
703703
self.scheduler = torch.optim.lr_scheduler.LambdaLR(
704704
self.optimizer,
705705
lambda step: self.lr_exp.value(step + self.start_step)
706-
/ self.lr_exp.start_lr(),
706+
/ self.lr_exp.start_lr,
707707
)
708708
elif self.opt_type == "LKF":
709709
self.optimizer = LKFOptimizer(
@@ -712,7 +712,7 @@ def single_model_finetune(
712712
elif self.opt_type == "AdaMuon":
713713
self.optimizer = AdaMuonOptimizer(
714714
self.wrapper.parameters(),
715-
lr=self.lr_exp.start_lr(),
715+
lr=self.lr_exp.start_lr,
716716
momentum=float(self.opt_param["momentum"]),
717717
weight_decay=float(self.opt_param["weight_decay"]),
718718
adam_betas=(
@@ -725,7 +725,7 @@ def single_model_finetune(
725725
elif self.opt_type == "HybridMuon":
726726
self.optimizer = HybridMuonOptimizer(
727727
self.wrapper.parameters(),
728-
lr=self.lr_exp.start_lr(),
728+
lr=self.lr_exp.start_lr,
729729
momentum=float(self.opt_param["momentum"]),
730730
weight_decay=float(self.opt_param["weight_decay"]),
731731
adam_betas=(
@@ -742,7 +742,7 @@ def single_model_finetune(
742742
self.scheduler = torch.optim.lr_scheduler.LambdaLR(
743743
self.optimizer,
744744
lambda step: self.lr_exp.value(step + self.start_step)
745-
/ self.lr_exp.start_lr(),
745+
/ self.lr_exp.start_lr,
746746
)
747747
else:
748748
raise ValueError(f"Not supported optimizer type '{self.opt_type}'")

0 commit comments

Comments
 (0)