LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
gaussian.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_GAUSSIAN_HPP_INCLUDED
28 #define LBANN_LAYER_GAUSSIAN_HPP_INCLUDED
29 
31 #include "lbann/models/model.hpp"
32 #include "lbann/utils/random.hpp"
33 
34 namespace lbann {
35 
37 template <typename TensorDataType,
39  El::Device Dev = El::Device::CPU>
40 class gaussian_layer : public data_type_layer<TensorDataType>
41 {
42 private:
44  TensorDataType m_mean;
46  TensorDataType m_stdev;
53 
54 public:
56  const std::vector<int>& dims,
57  TensorDataType mean = El::TypeTraits<TensorDataType>::Zero(),
58  TensorDataType stdev = El::TypeTraits<TensorDataType>::One(),
59  bool training_only = false)
60  : data_type_layer<TensorDataType>(comm),
61  m_mean(mean),
62  m_stdev(stdev),
63  m_training_only(training_only)
64  {
65  this->set_output_dims(dims);
67  }
68  gaussian_layer* copy() const override { return new gaussian_layer(*this); }
69 
71 
73  template <typename ArchiveT>
74  void serialize(ArchiveT& ar);
75 
77 
78  std::string get_type() const override { return "Gaussian"; }
79  data_layout get_data_layout() const override { return T_layout; }
80  El::Device get_device_allocation() const override { return Dev; }
81  bool can_run_inplace() const override { return false; }
82  int get_backprop_requirements() const override { return ERROR_SIGNALS; }
83 
84  description get_description() const override
85  {
87  desc.add("Mean", m_mean);
88  desc.add("Standard deviation", m_stdev);
89  desc.add("Training only", m_training_only);
90  return desc;
91  }
92 
93 protected:
95  void write_specific_proto(lbann_data::Layer& proto) const final;
96 
97  friend class cereal::access;
98  gaussian_layer() : gaussian_layer(nullptr, {1}) {}
99 
100  void fp_compute() override;
101 };
102 
103 #ifndef LBANN_GAUSSIAN_LAYER_INSTANTIATE
104 #define PROTO_DEVICE(T, Device) \
105  extern template class gaussian_layer<T, data_layout::DATA_PARALLEL, Device>; \
106  extern template class gaussian_layer<T, data_layout::MODEL_PARALLEL, Device>
107 
109 #undef PROTO_DEVICE
110 #endif // LBANN_GAUSSIAN_LAYER_INSTANTIATE
111 
112 } // namespace lbann
113 
114 #endif // LBANN_LAYER_GAUSSIAN_HPP_INCLUDED
gaussian_layer(lbann_comm *comm, const std::vector< int > &dims, TensorDataType mean=El::TypeTraits< TensorDataType >::Zero(), TensorDataType stdev=El::TypeTraits< TensorDataType >::One(), bool training_only=false)
Definition: gaussian.hpp:55
description get_description() const override
Human-readable description.
Definition: gaussian.hpp:84
gaussian_layer * copy() const override
Copy function. This function dynamically allocates memory for a layer instance and instantiates a cop...
Definition: gaussian.hpp:68
Generates nicely formatted description messages.
Definition: description.hpp:49
std::string get_type() const override
Get the layer type&#39;s name.
Definition: gaussian.hpp:78
TensorDataType m_stdev
Gaussian distribution standard deviation.
Definition: gaussian.hpp:46
virtual description get_description() const
Human-readable description.
friend class cereal::access
Definition: gaussian.hpp:97
constexpr El::Device Device
void set_output_dims(std::vector< int > dims, size_t output_index=0)
Set output tensor dimensions.
Random tensor with Gaussian/normal distribution.
Definition: gaussian.hpp:40
El::Device get_device_allocation() const override
Get the device allocation for the data tensors. We assume that the decice allocation of the previous ...
Definition: gaussian.hpp:80
TensorDataType m_mean
Gaussian distribution mean.
Definition: gaussian.hpp:44
int get_backprop_requirements() const override
Returns the necessary tensors for computing backpropagation.
Definition: gaussian.hpp:82
data_layout
Data layout that is optimized for different modes of parallelism.
Definition: base.hpp:218
bool can_run_inplace() const override
If True, the computation can run in-place (feeding each input activations tensor as the corresponding...
Definition: gaussian.hpp:81
void fp_compute() override
Apply layer operation. Called by the &#39;forward_prop&#39; function. Given the input tensors, the output tensors are populated with computed values.
bool m_training_only
Whether to have deterministic output when not training.
Definition: gaussian.hpp:52
int m_expected_num_parent_layers
Definition: layer.hpp:838
void serialize(ArchiveT &ar)
data_layout get_data_layout() const override
Get data layout of the data tensors. We assume that the data layouts of the previous activations...
Definition: gaussian.hpp:79
void write_specific_proto(lbann_data::Layer &proto) const final