LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
mutation_strategy.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 #ifndef LBANN_EXECUTION_ALGORITHMS_LTFB_MUTATION_STRATEGY_HPP_INCLUDED
27 #define LBANN_EXECUTION_ALGORITHMS_LTFB_MUTATION_STRATEGY_HPP_INCLUDED
28 
30 
31 #include <google/protobuf/message.h>
32 
33 #include "lbann/models/model.hpp"
35 
36 namespace lbann {
37 namespace ltfb {
38 
39 class MutationStrategy : public Cloneable<HasAbstractFunction<MutationStrategy>>
40 {
41 public:
43  virtual ~MutationStrategy() = default;
44 
49  virtual void mutate(model& m, const int& step) = 0;
50 };
51 
52 // No Mutation
53 class NullMutation final : public Cloneable<NullMutation, MutationStrategy>
54 {
55 
56 public:
57  NullMutation() = default;
58  void mutate(model& m, const int& step) final {}
59 };
60 
61 // Replace activation layers
62 class ReplaceActivation final
63  : public Cloneable<ReplaceActivation, MutationStrategy>
64 {
65 public:
66  ReplaceActivation() = default;
67  void mutate(model& m, const int& step) final;
68 };
69 
70 // Replace Convolution layers
71 class ReplaceConvolution final
72  : public Cloneable<ReplaceConvolution, MutationStrategy>
73 {
74 public:
75  ReplaceConvolution() = default;
76  void mutate(model& m, const int& step) final;
77 };
78 
79 // Hybrid mutation for Regularized Evolution mutation
80 // Alternates between ReplaceActivation and ReplaceConvolution randomly
81 class HybridMutation final : public Cloneable<HybridMutation, MutationStrategy>
82 {
83 public:
84  HybridMutation() = default;
85  void mutate(model& m, const int& step) final;
86 };
87 
88 } // namespace ltfb
89 } // namespace lbann
90 
91 template <>
92 std::unique_ptr<lbann::ltfb::MutationStrategy>
93 lbann::make_abstract<lbann::ltfb::MutationStrategy>(
94  google::protobuf::Message const& params);
95 
96 #endif // LBANN_EXECUTION_ALGORITHMS_LTFB_MUTATION_STRATEGY_HPP_INCLUDED
Inject polymorphic clone functions into hierarchies.
Definition: cloneable.hpp:94
void mutate(model &m, const int &step) final
virtual void mutate(model &m, const int &step)=0
Apply a change to the model.
Abstract base class for neural network models.
Definition: model.hpp:83
virtual ~MutationStrategy()=default