sandeep-krishnamurthy closed pull request #12467: Add PolyScheduler which
mimics the caffe polynomial lr scheduler
URL: https://github.com/apache/incubator-mxnet/pull/12467
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/cpp-package/include/mxnet-cpp/lr_scheduler.h
b/cpp-package/include/mxnet-cpp/lr_scheduler.h
index cffd1c7576e..cceb19a142d 100644
--- a/cpp-package/include/mxnet-cpp/lr_scheduler.h
+++ b/cpp-package/include/mxnet-cpp/lr_scheduler.h
@@ -91,6 +91,32 @@ class FactorScheduler : public LRScheduler {
float stop_factor_lr_;
};
+class PolyScheduler : public LRScheduler {
+ public:
+ explicit PolyScheduler(unsigned warmup_steps, unsigned max_update, float
power = 2.f,
+ float final_lr = 0)
+ : LRScheduler(), warmup_steps_(warmup_steps),
max_update_(max_update),
+ max_udpate_(static_cast<float>(max_update)), power_(power),
final_lr_(final_lr) {}
+
+ float GetLR(unsigned num_update) override {
+ if (num_update <= max_update_) {
+ current_lr_ = final_lr_ + (base_lr_ - final_lr_) *
+ powf((1.f - static_cast<float>(num_update -
warmup_steps_)/max_update_), power_);
+ LG << "Update[" << num_update << "]: Learning rate has arrived at "
+ << current_lr_ << "\n";
+ }
+ return current_lr_;
+ }
+
+ private:
+ unsigned warmup_steps_;
+ unsigned max_update_;
+ float max_udpate_;
+ float power_;
+ float final_lr_;
+ float current_lr_;
+};
+
} // namespace cpp
} // namespace mxnet
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services