LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
alternate_updates.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 //
27 
28 #ifndef LBANN_CALLBACKS_CALLBACK_ALTERNATE_UPDATES_HPP_INCLUDED
29 #define LBANN_CALLBACKS_CALLBACK_ALTERNATE_UPDATES_HPP_INCLUDED
30 
31 #include <utility>
32 
34 
35 namespace lbann {
36 namespace callback {
37 
45 {
46 public:
47  alternate_updates(std::vector<std::string> layers_1,
48  std::vector<std::string> layers_2,
49  int iters_1 = 1,
50  int iters_2 = 1)
51  : callback_base(1),
52  m_layer_names_1(std::move(layers_1)),
53  m_layer_names_2(std::move(layers_2)),
54  m_iters_1(iters_1),
55  m_iters_tot(iters_1 + iters_2)
56  {}
57 
58  alternate_updates(const alternate_updates&) = default;
60  alternate_updates* copy() const override
61  {
62  return new alternate_updates(*this);
63  }
64  void setup(model* m) override;
65  void on_batch_begin(model* m) override;
66  std::string name() const override { return "alternate updates"; }
67 
68 private:
69  void write_specific_proto(lbann_data::Callback& proto) const final;
70  std::vector<std::string> m_layer_names_1, m_layer_names_2;
71  std::vector<Layer*> freeze_layers, unfreeze_layers;
73 };
74 
75 // Builder function
76 std::unique_ptr<callback_base> build_alternate_updates_callback_from_pbuf(
77  const google::protobuf::Message&,
78  std::shared_ptr<lbann_summary> const&);
79 
80 } // namespace callback
81 } // namespace lbann
82 
83 #endif // LBANN_CALLBACKS_CALLBACK_ALTERNATE_UPDATES_HPP_INCLUDED
void setup(model *m) override
Called once to set up the callback on the model (after all layers are set up).
std::vector< std::string > m_layer_names_2
std::string name() const override
Return this callback&#39;s name.
std::vector< std::string > m_layer_names_1
std::vector< Layer * > unfreeze_layers
Base class for callbacks during training/testing.
Definition: callback.hpp:76
Abstract base class for neural network models.
Definition: model.hpp:83
void on_batch_begin(model *m) override
Called at the beginning of a (mini-)batch.
alternate_updates & operator=(const alternate_updates &)=default
std::unique_ptr< callback_base > build_alternate_updates_callback_from_pbuf(const google::protobuf::Message &, std::shared_ptr< lbann_summary > const &)
void write_specific_proto(lbann_data::Callback &proto) const final
Add callback specific data to prototext.
alternate_updates(std::vector< std::string > layers_1, std::vector< std::string > layers_2, int iters_1=1, int iters_2=1)
alternate_updates * copy() const override