:github_url: https://github.com/pytorch/pytorch .. _program_listing_file_torch_csrc_api_include_torch_optim_schedulers_lr_scheduler.h: Program Listing for File lr_scheduler.h ======================================= |exhale_lsh| :ref:`Return to documentation for file ` (``torch/csrc/api/include/torch/optim/schedulers/lr_scheduler.h``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #pragma once #include #include namespace torch::optim { class TORCH_API LRScheduler { public: // This class needs to take a reference of an optimizer from outside such that // it can modify its learning rates; due to this the lifetime of said // optimizer must be maintained LRScheduler(torch::optim::Optimizer& optimizer); virtual ~LRScheduler() = default; void step(); protected: // A vector of learning rates is calculated and returned from the specific // subclass. A vector is returned with each element being a separate learning // rate for each param group - although the normal use case would be to return // a vector of identical elements. virtual std::vector get_lrs() = 0; // Get current learning rates from the optimizer std::vector get_current_lrs() const; unsigned step_count_{}; private: void set_optimizer_lrs(const std::vector& learning_rates); // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members) torch::optim::Optimizer& optimizer_; }; } // namespace torch::optim