LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
selu_dropout.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_LAYER_REGULARIZER_SELU_DROPOUT_HPP_INCLUDED
28 #define LBANN_LAYER_REGULARIZER_SELU_DROPOUT_HPP_INCLUDED
29 
31 #include "lbann/layers/layer.hpp"
32 
33 namespace lbann {
34 
43 template <typename TensorDataType, data_layout T_layout, El::Device Dev>
44 class selu_dropout final : public data_type_layer<TensorDataType>
45 {
46 public:
48 
51  using AbsDistMatrixType = El::AbstractDistMatrix<TensorDataType>;
52 
54  using CPUMatrixType = El::Matrix<TensorDataType, El::Device::CPU>;
55 
57 
58 public:
60  selu_dropout(TensorDataType keep_prob = El::To<TensorDataType>(0.95),
61  TensorDataType alpha =
62  El::To<TensorDataType>(1.6732632423543772848170429916717),
63  TensorDataType scale =
64  El::To<TensorDataType>(1.0507009873554804934193349852946));
65 
66  selu_dropout(const selu_dropout& other);
67 
68  selu_dropout& operator=(const selu_dropout& other);
69 
70  ~selu_dropout() final;
71 
72  selu_dropout* copy() const final;
73 
74  std::string get_type() const final;
75 
76  data_layout get_data_layout() const final;
77 
78  El::Device get_device_allocation() const final;
79 
80  bool can_run_inplace() const override { return true; }
81 
82  int get_backprop_requirements() const override { return ERROR_SIGNALS; }
83 
84  void setup_dims() final;
85 
86  void setup_data(size_t max_mini_batch_size) final;
87 
89 
91  template <typename ArchiveT>
92  void serialize(ArchiveT& ar);
93 
95 
96 protected:
98  void write_specific_proto(lbann_data::Layer& proto) const final;
99 
100 private:
102  void fp_compute() final;
103 
105  void bp_compute() final;
106 
107 private:
109  TensorDataType m_alpha_prime;
111  TensorDataType m_a;
113  TensorDataType m_b;
115  TensorDataType m_keep_prob;
118 };
119 
121 
122 #ifndef LBANN_SELU_DROPOUT_LAYER_INSTANTIATE
123 #define PROTO_DEVICE(T, Device) \
124  extern template class selu_dropout<T, data_layout::DATA_PARALLEL, Device>; \
125  extern template class selu_dropout<T, data_layout::MODEL_PARALLEL, Device>
126 
128 #undef PROTO_DEVICE
129 #endif // LBANN_SELU_DROPOUT_LAYER_INSTANTIATE
130 
131 } // namespace lbann
132 
133 #endif // LBANN_LAYER_REGULARIZER_SELU_DROPOUT_HPP_INCLUDED
bool can_run_inplace() const override
If True, the computation can run in-place (feeding each input activations tensor as the corresponding...
Scaled dropout for use with SELU activations.
void setup_data(size_t max_mini_batch_size) final
Setup layer data. Called by the &#39;setup&#39; function. Memory is allocated for distributed matrices...
data_layout get_data_layout() const final
Get data layout of the data tensors. We assume that the data layouts of the previous activations...
constexpr El::Device Device
void serialize(ArchiveT &ar)
TensorDataType m_alpha_prime
void setup_dims() final
Setup tensor dimensions Called by the &#39;setup&#39; function. If there are any input tensors, the base method sets all uninitialized output tensor dimensions equal to the first input tensor dimensions.
selu_dropout(TensorDataType keep_prob=El::To< TensorDataType >(0.95), TensorDataType alpha=El::To< TensorDataType >(1.6732632423543772848170429916717), TensorDataType scale=El::To< TensorDataType >(1.0507009873554804934193349852946))
El::Matrix< TensorDataType, El::Device::CPU > CPUMatrixType
The tensor type expected in this object.
TensorDataType m_b
TensorDataType m_a
selu_dropout & operator=(const selu_dropout &other)
AbsDistMatrixType * m_mask
void bp_compute() final
TensorDataType m_keep_prob
selu_dropout * copy() const final
Copy function. This function dynamically allocates memory for a layer instance and instantiates a cop...
data_layout
Data layout that is optimized for different modes of parallelism.
Definition: base.hpp:218
void write_specific_proto(lbann_data::Layer &proto) const final
El::AbstractDistMatrix< TensorDataType > AbsDistMatrixType
The tensor type expected in this object.
void fp_compute() final
int get_backprop_requirements() const override
Returns the necessary tensors for computing backpropagation.
El::Device get_device_allocation() const final
Get the device allocation for the data tensors. We assume that the decice allocation of the previous ...
LBANN_DEFINE_LAYER_BUILDER(elu)
std::string get_type() const final
Get the layer type&#39;s name.