-
Notifications
You must be signed in to change notification settings - Fork 16
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
Implement Cyclic Learning Rate and Step-wise Learning Rate Scheduler #213
Changes from 8 commits
5208228
d00eefc
d3de3d4
4798d93
11400fd
acc69b0
7215141
8cb2338
57c44ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ def __init__( | |
self.model = model.to(self.device) | ||
self.optimizer = get_optimizer(model_param=self.model.parameters(), **train_options["optimizer"]) | ||
self.lr_scheduler = get_lr_scheduler(optimizer=self.optimizer, **train_options["lr_scheduler"]) # add optmizer | ||
self.update_lr_per_step_flag = train_options["update_lr_per_step_flag"] | ||
self.common_options = common_options | ||
self.train_options = train_options | ||
|
||
|
@@ -129,6 +130,11 @@ def iteration(self, batch, ref_batch=None): | |
loss.backward() | ||
#TODO: add clip large gradient | ||
self.optimizer.step() | ||
if self.update_lr_per_step_flag: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 没太理解这个开关的作用 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 学习率更新需要显式的使用 self.lr_scheduler.step()。添加这个开关可以在每个 iteration 里调用,否则是每个 epoch 调用一次 |
||
if isinstance(self.lr_scheduler, torch.optim.lr_scheduler.ReduceLROnPlateau): | ||
self.lr_scheduler.step(self.stats["train_loss"]["epoch_mean"]) | ||
else: | ||
self.lr_scheduler.step() | ||
|
||
state = {'field':'iteration', "train_loss": loss.detach(), "lr": self.optimizer.state_dict()["param_groups"][0]['lr']} | ||
self.call_plugins(queue_name='iteration', time=self.iter, **state) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
{ | ||
"common_options": { | ||
"basis": { | ||
"C": "5s4p1d", | ||
"H": "3s1p", | ||
"O": "5s4p1d" | ||
}, | ||
"device": "cuda", | ||
"overlap": true | ||
}, | ||
"model_options": { | ||
"embedding": { | ||
"method": "lem", | ||
"irreps_hidden": "4x0e+4x1o+4x2e+4x3o+4x4e", | ||
"n_layers": 5, | ||
"avg_num_neighbors": 80, | ||
"r_max": { | ||
"C": 7, | ||
"O": 7, | ||
"H": 3 | ||
}, | ||
"tp_radial_emb": true | ||
}, | ||
"prediction": { | ||
"method": "e3tb", | ||
"neurons": [ | ||
64, | ||
64 | ||
] | ||
} | ||
}, | ||
"train_options": { | ||
"num_epoch": 10, | ||
"batch_size": 1, | ||
"optimizer": { | ||
"lr": 0.005, | ||
"type": "Adam" | ||
}, | ||
"lr_scheduler": { | ||
"type": "cyclic", | ||
"max_lr": 0.005, | ||
"base_lr": 1e-06, | ||
"step_size_up": 3, | ||
"step_size_down": 7, | ||
"mode": "exp_range", | ||
"scale_mode": "cycle" | ||
}, | ||
"loss_options": { | ||
"train": { | ||
"method": "hamil_abs" | ||
} | ||
}, | ||
"save_freq": 100, | ||
"validation_freq": 10, | ||
"display_freq": 1, | ||
"use_tensorboard": true, | ||
"update_lr_per_step_flag": false | ||
}, | ||
"data_options": { | ||
"train": { | ||
"root": "./data_10", | ||
"prefix": "data", | ||
"type": "LMDBDataset", | ||
"get_Hamiltonian": true, | ||
"get_overlap": true | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
{ | ||
"common_options": { | ||
"basis": { | ||
"C": "5s4p1d", | ||
"H": "3s1p", | ||
"O": "5s4p1d" | ||
}, | ||
"device": "cuda", | ||
"overlap": true | ||
}, | ||
"model_options": { | ||
"embedding": { | ||
"method": "lem", | ||
"irreps_hidden": "4x0e+4x1o+4x2e+4x3o+4x4e", | ||
"n_layers": 5, | ||
"avg_num_neighbors": 80, | ||
"r_max": { | ||
"C": 7, | ||
"O": 7, | ||
"H": 3 | ||
}, | ||
"tp_radial_emb": true | ||
}, | ||
"prediction": { | ||
"method": "e3tb", | ||
"neurons": [ | ||
64, | ||
64 | ||
] | ||
} | ||
}, | ||
"train_options": { | ||
"num_epoch": 10, | ||
"batch_size": 1, | ||
"optimizer": { | ||
"lr": 0.005, | ||
"type": "Adam" | ||
}, | ||
"lr_scheduler": { | ||
"type": "cyclic", | ||
"max_lr": 0.005, | ||
"base_lr": 1e-06, | ||
"step_size_up": 3, | ||
"step_size_down": 7, | ||
"mode": "exp_range", | ||
"scale_mode": "iterations" | ||
}, | ||
"loss_options": { | ||
"train": { | ||
"method": "hamil_abs" | ||
} | ||
}, | ||
"save_freq": 100, | ||
"validation_freq": 10, | ||
"display_freq": 1, | ||
"use_tensorboard": true, | ||
"update_lr_per_step_flag": true | ||
}, | ||
"data_options": { | ||
"train": { | ||
"root": "./data_10", | ||
"prefix": "data", | ||
"type": "LMDBDataset", | ||
"get_Hamiltonian": true, | ||
"get_overlap": true | ||
} | ||
} | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个file可以再小一点吗? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
{ | ||
"common_options": { | ||
"basis": { | ||
"C": "5s4p1d", | ||
"H": "3s1p", | ||
"O": "5s4p1d" | ||
}, | ||
"device": "cuda", | ||
"overlap": true | ||
}, | ||
"model_options": { | ||
"embedding": { | ||
"method": "lem", | ||
"irreps_hidden": "4x0e+4x1o+4x2e+4x3o+4x4e", | ||
"n_layers": 5, | ||
"avg_num_neighbors": 80, | ||
"r_max": { | ||
"C": 7, | ||
"O": 7, | ||
"H": 3 | ||
}, | ||
"tp_radial_emb": true | ||
}, | ||
"prediction": { | ||
"method": "e3tb", | ||
"neurons": [ | ||
64, | ||
64 | ||
] | ||
} | ||
}, | ||
"train_options": { | ||
"num_epoch": 10, | ||
"batch_size": 1, | ||
"optimizer": { | ||
"lr": 0.005, | ||
"type": "Adam" | ||
}, | ||
"lr_scheduler": { | ||
"type": "exp", | ||
"gamma": 0.8 | ||
}, | ||
"loss_options": { | ||
"train": { | ||
"method": "hamil_abs" | ||
} | ||
}, | ||
"save_freq": 100, | ||
"validation_freq": 10, | ||
"display_freq": 1, | ||
"use_tensorboard": true, | ||
"update_lr_per_step_flag": false | ||
}, | ||
"data_options": { | ||
"train": { | ||
"root": "./data_10", | ||
"prefix": "data", | ||
"type": "LMDBDataset", | ||
"get_Hamiltonian": true, | ||
"get_overlap": true | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果这个flag为false就不更新LR了?