[cpp-package] add lr scheduler (#6885)

* add lr scheduler

* Update lr_scheduler.h

* Update mlp_gpu.cpp

* Update test_score.cpp

* update optimizer.hpp
This commit is contained in:
CNevd authored and Eric Junyuan Xie committed 2017-08-03 13:18:07 -07:00
1 parent 8519eafd1d
commit 76dee53dc4
15 files changed
+257 -96

No files matched your search

+9 -2
View File
@@ -451,6 +451,8 @@ void train(const string file, int batch_size, int max_epoch, int start_epoch) {
mx_float learning_rate = 0.0002;
mx_float weight_decay = 0.000002;
Optimizer* opt = OptimizerRegistry::Find("ccsgd");
opt->SetParam("lr", learning_rate)
->SetParam("wd", weight_decay);
// opt->SetParam("momentum", 0.9)->SetParam("rescale_grad", 1.0 / batch_size)
// ->SetParam("clip_gradient", 10);
@@ -470,7 +472,10 @@ void train(const string file, int batch_size, int max_epoch, int start_epoch) {
exe->Forward(true);
exe->Backward();
exe->UpdateAll(opt, learning_rate, weight_decay);
for (size_t i = 0; i < exe->arg_arrays.size(); ++i) {
opt->Update(i, exe->arg_arrays[i], exe->grad_arrays[i]);
}
NDArray::WaitAll();
}
auto toc = chrono::system_clock::now();
@@ -547,7 +552,9 @@ void trainWithBuiltInRNNOp(const string file, int batch_size, int max_epoch, int
exe->Forward(true);
exe->Backward();
exe->UpdateAll(opt, learning_rate, weight_decay);
for (size_t i = 0; i < exe->arg_arrays.size(); ++i) {
opt->Update(i, exe->arg_arrays[i], exe->grad_arrays[i]);
}
NDArray::WaitAll();
}
auto toc = chrono::system_clock::now();