LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
mean_absolute_error.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_LAYERS_LOSS_MEAN_ABSOLUTE_ERROR_HPP_INCLUDED
28 #define LBANN_LAYERS_LOSS_MEAN_ABSOLUTE_ERROR_HPP_INCLUDED
29 
32 #include "lbann/proto/layers.pb.h"
33 
34 namespace lbann {
35 
44 template <typename TensorDataType, data_layout T_layout, El::Device Dev>
45 class mean_absolute_error_layer : public data_type_layer<TensorDataType>
46 {
47 public:
49 
52  using AbsDistMatrixType = El::AbstractDistMatrix<TensorDataType>;
53 
55 
56 public:
58  : data_type_layer<TensorDataType>(comm)
59  {
61  }
62 
64  : data_type_layer<TensorDataType>(other)
65  {
66  m_workspace.reset(other.m_workspace ? other.m_workspace->Copy() : nullptr);
67  }
68 
70  {
72  m_workspace.reset(other.m_workspace ? other.m_workspace->Copy() : nullptr);
73  return *this;
74  }
75 
76  mean_absolute_error_layer* copy() const override
77  {
78  return new mean_absolute_error_layer(*this);
79  }
80 
82 
84  template <typename ArchiveT>
85  void serialize(ArchiveT& ar);
86 
88 
89  std::string get_type() const override { return "mean absolute error"; }
90  data_layout get_data_layout() const override { return T_layout; }
91  El::Device get_device_allocation() const override { return Dev; }
92  bool can_run_inplace() const override { return false; }
93  int get_backprop_requirements() const override
94  {
96  }
97 
98  void setup_dims() override;
99 
100  void setup_data(size_t max_mini_batch_size) override;
101 
102  void fp_compute() override;
103 
104  void bp_compute() override;
105 
106 protected:
108  void write_specific_proto(lbann_data::Layer& proto) const final;
109 
110  friend class cereal::access;
112 
113 private:
115  void local_fp_compute();
117  void local_bp_compute();
118 
120  std::unique_ptr<AbsDistMatrixType> m_workspace;
121 };
122 
123 template <typename T, data_layout L, El::Device D>
125  lbann_data::Layer& proto) const
126 {
127  proto.set_datatype(proto::ProtoDataType<T>);
128  proto.mutable_mean_absolute_error();
129 }
130 
131 #ifndef LBANN_MEAN_ABSOLUTE_ERROR_LAYER_INSTANTIATE
132 
133 #define PROTO_DEVICE(T, Device) \
134  extern template class mean_absolute_error_layer<T, \
135  data_layout::DATA_PARALLEL, \
136  Device>; \
137  extern template class mean_absolute_error_layer<T, \
138  data_layout::MODEL_PARALLEL, \
139  Device>
140 
142 #undef PROTO_DEVICE
143 
144 #endif // LBANN_MEAN_ABSOLUTE_ERROR_LAYER_INSTANTIATE
145 
146 } // namespace lbann
147 
148 #endif // LBANN_LAYERS_LOSS_MEAN_ABSOLUTE_ERROR_HPP_INCLUDED
data_layout get_data_layout() const override
Get data layout of the data tensors. We assume that the data layouts of the previous activations...
void write_specific_proto(lbann_data::Layer &proto) const final
void setup_data(size_t max_mini_batch_size) override
Setup layer data. Called by the &#39;setup&#39; function. Memory is allocated for distributed matrices...
std::unique_ptr< AbsDistMatrixType > m_workspace
int get_backprop_requirements() const override
Returns the necessary tensors for computing backpropagation.
mean_absolute_error_layer & operator=(const mean_absolute_error_layer &other)
El::Device get_device_allocation() const override
Get the device allocation for the data tensors. We assume that the decice allocation of the previous ...
constexpr El::Device Device
void bp_compute() override
Compute objective funciton gradients. Called by the &#39;back_prop&#39; function. Given the input...
El::AbstractDistMatrix< TensorDataType > AbsDistMatrixType
The tensor type expected in this object.
mean_absolute_error_layer(const mean_absolute_error_layer &other)
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.
data_layout
Data layout that is optimized for different modes of parallelism.
Definition: base.hpp:218
std::string get_type() const override
Get the layer type&#39;s name.
bool can_run_inplace() const override
If True, the computation can run in-place (feeding each input activations tensor as the corresponding...
void setup_dims() override
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.
mean_absolute_error_layer * copy() const override
Copy function. This function dynamically allocates memory for a layer instance and instantiates a cop...
int m_expected_num_parent_layers
Definition: layer.hpp:838
data_type_layer & operator=(data_type_layer &&other)=default