LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
progress_bar.hpp
Go to the documentation of this file.
1 // Copyright (c) 2014-2023, Lawrence Livermore National Security, LLC.
3 // Produced at the Lawrence Livermore National Laboratory.
4 // Written by the LBANN Research Team (B. Van Essen, et al.) listed in
5 // the CONTRIBUTORS file. <lbann-dev@llnl.gov>
6 //
7 // LLNL-CODE-697807.
8 // All rights reserved.
9 //
10 // This file is part of LBANN: Livermore Big Artificial Neural Network
11 // Toolkit. For details, see http://software.llnl.gov/LBANN or
12 // https://github.com/LLNL/LBANN.
13 //
14 // Licensed under the Apache License, Version 2.0 (the "Licensee"); you
15 // may not use this file except in compliance with the License. You may
16 // obtain a copy of the License at:
17 //
18 // http://www.apache.org/licenses/LICENSE-2.0
19 //
20 // Unless required by applicable law or agreed to in writing, software
21 // distributed under the License is distributed on an "AS IS" BASIS,
22 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
23 // implied. See the License for the specific language governing
24 // permissions and limitations under the license.
25 //
26 // progress_bar .hpp .cpp - Callback that prints a progress bar during epochs.
28 
29 #ifndef LBANN_CALLBACKS_CALLBACK_PROGRESS_BAR_HPP_INCLUDED
30 #define LBANN_CALLBACKS_CALLBACK_PROGRESS_BAR_HPP_INCLUDED
31 
33 #include <array>
34 
35 #define LBANN_PBAR_MOVING_AVERAGE_LENGTH 10
36 #define LBANN_PBAR_WIDTH 20
37 
38 namespace lbann {
39 namespace callback {
40 
45 {
46 public:
49 
53  progress_bar(int batch_interval = 1, int newline_interval = 0)
54  : callback_base(batch_interval), m_newline_interval(newline_interval)
55  {}
56  progress_bar(const progress_bar&) = default;
57  progress_bar& operator=(const progress_bar&) = default;
58  progress_bar* copy() const override { return new progress_bar(*this); }
59 
60  void on_epoch_begin(model* m) override;
61  void on_forward_prop_begin(model* m) override;
62 
63  std::string name() const override { return "progress bar"; }
64 
66 
69  template <class Archive>
70  void serialize(Archive& ar);
71 
73 
74 private:
76  void write_specific_proto(lbann_data::Callback& proto) const final;
77 
78  friend class cereal::access;
79 
80  // Settings
82 
83  // Cached values for epochs
84  bool m_print;
87 
89  std::array<double, LBANN_PBAR_MOVING_AVERAGE_LENGTH> m_moving_avg_time;
90 
92  double m_last_time;
93 };
94 
95 // Builder function
96 std::unique_ptr<callback_base>
97 build_progress_bar_callback_from_pbuf(const google::protobuf::Message&,
98  std::shared_ptr<lbann_summary> const&);
99 
100 } // namespace callback
101 } // namespace lbann
102 
103 #endif // LBANN_CALLBACKS_CALLBACK_PROGRESS_BAR_HPP_INCLUDED
progress_bar & operator=(const progress_bar &)=default
virtual void on_epoch_begin(model *m)
Called at the beginning of each epoch.
Definition: callback.hpp:124
friend class cereal::access
prints a progress bar during training
progress_bar(int batch_interval=1, int newline_interval=0)
progress_bar * copy() const override
void serialize(Archive &ar)
Store state to archive for checkpoint and restart.
Base class for callbacks during training/testing.
Definition: callback.hpp:76
Abstract base class for neural network models.
Definition: model.hpp:83
void on_forward_prop_begin(model *m) override
Called when a model begins forward propagation.
std::array< double, LBANN_PBAR_MOVING_AVERAGE_LENGTH > m_moving_avg_time
std::string name() const override
Return this callback&#39;s name.
void on_epoch_begin(model *m) override
Called at the beginning of each epoch.
virtual void on_forward_prop_begin(model *m)
Called when a model begins forward propagation.
Definition: callback.hpp:140
std::unique_ptr< callback_base > build_progress_bar_callback_from_pbuf(const google::protobuf::Message &, std::shared_ptr< lbann_summary > const &)
void write_specific_proto(lbann_data::Callback &proto) const final