LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
check_gradients.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.
26 
27 #ifndef LBANN_CALLBACKS_CALLBACK_CHECK_GRADIENTS_HPP_INCLUDED
28 #define LBANN_CALLBACKS_CALLBACK_CHECK_GRADIENTS_HPP_INCLUDED
29 
31 
32 #include <google/protobuf/message.h>
33 
34 #include <set>
35 
36 namespace lbann {
37 namespace callback {
38 
49 {
50 public:
64  check_gradients(std::set<execution_mode> modes = {},
65  DataType step_size = DataType(0),
66  bool verbose = false,
67  bool error_on_failure = false);
68  check_gradients* copy() const override { return new check_gradients(*this); }
69  std::string name() const override { return "check gradients"; }
70  void on_train_end(model* m) override { do_check_gradients(*m); }
71  void on_validation_end(model* m) override { do_check_gradients(*m); }
72  void on_test_end(model* m) override { do_check_gradients(*m); }
73 
75 
78  template <class Archive>
79  void serialize(Archive& ar);
80 
82 
83 private:
85  void write_specific_proto(lbann_data::Callback& proto) const final;
86 
88  std::set<execution_mode> m_modes;
92  bool m_verbose;
95 
97  void do_check_gradients(model& m) const;
98 };
99 
100 // Builder function
101 std::unique_ptr<callback_base>
102 build_check_gradients_callback_from_pbuf(const google::protobuf::Message&,
103  std::shared_ptr<lbann_summary> const&);
104 
105 } // namespace callback
106 } // namespace lbann
107 
108 #endif // LBANN_CALLBACKS_CALLBACK_CHECK_GRADIENTS_HPP_INCLUDED
void on_validation_end(model *m) override
Called immediately after the end of validation.
check_gradients(std::set< execution_mode > modes={}, DataType step_size=DataType(0), bool verbose=false, bool error_on_failure=false)
std::string name() const override
Return this callback&#39;s name.
Gradient checking callback.
void write_specific_proto(lbann_data::Callback &proto) const final
void on_train_end(model *m) override
Called at the end of training.
Base class for callbacks during training/testing.
Definition: callback.hpp:76
std::unique_ptr< callback_base > build_check_gradients_callback_from_pbuf(const google::protobuf::Message &, std::shared_ptr< lbann_summary > const &)
Abstract base class for neural network models.
Definition: model.hpp:83
void do_check_gradients(model &m) const
std::set< execution_mode > m_modes
void serialize(Archive &ar)
Store state to archive for checkpoint and restart.
check_gradients * copy() const override
void on_test_end(model *m) override
Called immediately after the end of testing.
double EvalType
Definition: base.hpp:189