LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
timeline.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 // callback_timeline .hpp .cpp - Callback hooks to record a timeline of runtime
28 
29 #ifndef LBANN_CALLBACKS_CALLBACK_TIMELINE_HPP_INCLUDED
30 #define LBANN_CALLBACKS_CALLBACK_TIMELINE_HPP_INCLUDED
31 
33 #include "lbann/utils/timer.hpp"
34 
35 #include <unordered_map>
36 #include <vector>
37 
38 namespace lbann {
39 namespace callback {
40 
48 class timeline : public callback_base
49 {
50 public:
51  timeline(std::string outdir) : callback_base(1), m_outdir(outdir) {}
52  timeline(const timeline&) = default;
53  timeline& operator=(const timeline&) = default;
54  timeline* copy() const override { return new timeline(*this); }
55  std::string name() const override { return "timeline"; }
56  void on_train_begin(model* m) override;
57  void on_train_end(model* m) override;
58 
65 
66  void on_forward_prop_begin(model* m, Layer* l) override;
67  void on_forward_prop_end(model* m, Layer* l) override;
68  void on_backward_prop_begin(model* m, Layer* l) override;
69  void on_backward_prop_end(model* m, Layer* l) override;
70  void on_optimize_begin(model* m, weights* w) override;
71  void on_optimize_end(model* m, weights* w) override;
72 
74 
77  template <class Archive>
78  void serialize(Archive& ar);
79 
81 
82 private:
84  void write_specific_proto(lbann_data::Callback& proto) const final;
85 
86  friend class cereal::access;
87  timeline();
88 
90  EvalType get_rel_time() const { return get_time() - m_start_time; }
91 
93  std::string m_outdir;
103  std::unordered_map<std::string, std::vector<std::pair<EvalType, EvalType>>>
105  std::unordered_map<std::string, std::vector<std::pair<EvalType, EvalType>>>
107  std::unordered_map<std::string, std::vector<std::pair<EvalType, EvalType>>>
109 };
110 
111 // Builder function
112 std::unique_ptr<callback_base>
113 build_timeline_callback_from_pbuf(const google::protobuf::Message&,
114  std::shared_ptr<lbann_summary> const&);
115 
116 } // namespace callback
117 } // namespace lbann
118 
119 #endif // LBANN_CALLBACKS_CALLBACK_TIMELINE_HPP_INCLUDED
void on_backward_prop_begin(model *m, Layer *l) override
Called when a layer begins backward propagation.
virtual void on_optimize_begin(model *m)
Called when a model begins optimization.
Definition: callback.hpp:156
timeline * copy() const override
Definition: timeline.hpp:54
void on_optimize_end(model *m, weights *w) override
Called when weights ends optimization.
EvalType m_fp_start_time
Time the current layer&#39;s forward pass started.
Definition: timeline.hpp:97
EvalType m_start_time
Time training started; all times are relative to this.
Definition: timeline.hpp:95
std::unordered_map< std::string, std::vector< std::pair< EvalType, EvalType > > > m_fp_times
Store (relative) timing information.
Definition: timeline.hpp:104
void on_backward_prop_end(model *m, Layer *l) override
Called when a layer ends backward propagation.
void on_forward_prop_begin(model *m, Layer *l) override
Called when a layer begins forward propagation.
void on_optimize_begin(model *m, weights *w) override
Called when weights begins optimization.
Neural network tensor operation.
Definition: layer.hpp:285
virtual void on_backward_prop_begin(model *m)
Called when a model begins backward propagation.
Definition: callback.hpp:148
void on_train_end(model *m) override
Called at the end of training.
std::string m_outdir
Directory to write output to.
Definition: timeline.hpp:93
Base class for callbacks during training/testing.
Definition: callback.hpp:76
std::unordered_map< std::string, std::vector< std::pair< EvalType, EvalType > > > m_opt_times
Definition: timeline.hpp:108
Abstract base class for neural network models.
Definition: model.hpp:83
virtual void on_forward_prop_end(model *m)
Called when a model ends forward propagation.
Definition: callback.hpp:144
void on_forward_prop_end(model *m, Layer *l) override
Called when a layer ends forward propagation.
virtual void on_optimize_end(model *m)
Called when a model ends optimization.
Definition: callback.hpp:160
void on_train_begin(model *m) override
Called at the beginning of training.
std::string name() const override
Return this callback&#39;s name.
Definition: timeline.hpp:55
void serialize(Archive &ar)
Store state to archive for checkpoint and restart.
EvalType m_opt_start_time
Time the current weights&#39; optimization pass started.
Definition: timeline.hpp:101
timeline(std::string outdir)
Definition: timeline.hpp:51
EvalType m_bp_start_time
Time the current layer&#39;s backward pass started.
Definition: timeline.hpp:99
virtual void on_backward_prop_end(model *m)
Called when a model ends backward propagation.
Definition: callback.hpp:152
friend class cereal::access
Definition: timeline.hpp:86
virtual void on_forward_prop_begin(model *m)
Called when a model begins forward propagation.
Definition: callback.hpp:140
double get_time()
Return time in fractional seconds since an epoch.
Definition: utils/timer.hpp:37
std::unique_ptr< callback_base > build_timeline_callback_from_pbuf(const google::protobuf::Message &, std::shared_ptr< lbann_summary > const &)
std::unordered_map< std::string, std::vector< std::pair< EvalType, EvalType > > > m_bp_times
Definition: timeline.hpp:106
void write_specific_proto(lbann_data::Callback &proto) const final
timeline & operator=(const timeline &)=default
EvalType get_rel_time() const
Get time relative to the start time.
Definition: timeline.hpp:90
double EvalType
Definition: base.hpp:189