27 #ifndef LBANN_OPTIMIZERS_OPTIMIZER_HPP_INCLUDED 28 #define LBANN_OPTIMIZERS_OPTIMIZER_HPP_INCLUDED 36 #endif // LBANN_HAS_GPU 43 #include <unordered_set> 97 virtual std::string get_type()
const = 0;
101 virtual double get_learning_rate()
const = 0;
102 virtual void set_learning_rate(
double) = 0;
107 virtual void setup(
weights* w) = 0;
121 template <
typename TensorDataType>
122 void add_to_gradient(El::AbstractDistMatrix<TensorDataType>
const& contrib,
123 TensorDataType scale = 1.f,
127 void clear_gradient();
131 El::Int get_num_gradient_sources()
const;
139 void add_gradient_source(
const void* source);
148 void remove_gradient_source(
const void* source);
151 virtual void step() = 0;
176 template <
typename TensorDataType>
177 El::AbstractDistMatrix<TensorDataType>&
178 get_gradient_buffer(TensorDataType& buf_scale,
179 TensorDataType& in_scale,
207 template <
class Archive>
213 virtual void write_proto(lbann_data::Optimizer& proto)
const = 0;
222 virtual El::BaseDistMatrix& gradient() noexcept = 0;
223 virtual El::BaseDistMatrix
const& gradient()
const noexcept = 0;
224 virtual void start_allreduce(
lbann_comm&) = 0;
225 virtual void complete_allreduce(
lbann_comm&) = 0;
226 virtual void clear() = 0;
232 template <
typename TensorDataType>
240 : gradient_{AbsDistMatType::Instantiate(dist_data)}
242 El::Zeros(*gradient_, height, width);
249 void start_allreduce(
lbann_comm& comm)
override;
250 void complete_allreduce(
lbann_comm& comm)
override;
251 void clear()
override;
265 return m_gradient_status;
269 m_gradient_status = status;
273 return m_gradient_sources;
281 virtual std::tuple<El::Int, El::Int, El::DistData>
282 get_matrix_info()
const = 0;
284 template <
typename TensorDataType>
285 void accumulate_all_gradient_contributions(
286 El::AbstractDistMatrix<TensorDataType>& gradient);
293 void start_gradient_allreduce();
300 void finish_gradient_allreduce();
320 optimizer_gradient_status::cleared;
330 std::unordered_map<std::type_index, gradient_manager_ptr>
gradients_;
335 #endif // LBANN_OPTIMIZERS_OPTIMIZER_HPP_INCLUDED lbann_comm * m_comm
LBANN communicator.
void set_status(optimizer_gradient_status s) noexcept
std::unordered_map< std::type_index, gradient_manager_ptr > gradients_
std::unordered_set< const void * > & get_gradient_sources()
Inject polymorphic clone functions into hierarchies.
Values have been cleared.
void set_comm(lbann_comm &comm)
void set_gradient_status(const optimizer_gradient_status status)
GradientHelperImpl(El::Int height, El::Int width, El::DistData dist_data)
Al::request allreduce_req_
void serialize(std::ostream &os, google::protobuf::Message const &msg)
Serialize the protobuf message to a stream.
Generates nicely formatted description messages.
Abstract base class for gradient-based optimization algorithms.
Values can be accessed immediately.
void set_step_time(EvalType time)
El::AbstractDistMatrix< TensorDataType > AbsDistMatType
std::unique_ptr< AbsDistMatType > gradient_
std::unordered_set< const void * > m_gradient_sources
Sources of gradient contributions.
AbsDistMatType const & gradient() const noexcept override
Manage gradient information.
virtual void reset_counters()
Reset stats counters.
lbann_comm & get_comm()
Communicator access.
Allreduce is needed before accessing values.
const lbann_comm & get_comm() const
Access LBANN communicator.
optimizer_gradient_status get_status() const noexcept
EvalType get_step_time() const
Statistics access and management.
optimizer_gradient_status get_gradient_status() const
Return the current gradient status.
std::unique_ptr< gradient_manager_type > gradient_manager_ptr
void inc_step_time(EvalType time)
optimizer_gradient_status
Status of values in objective function gradient.
AbsDistMatType & gradient() noexcept override
Allreduce on values is in progress.
std::string to_string(optimizer_gradient_status status)
Human-readable string for status of gradient in optimizer.