27 #ifndef LBANN_LAYER_LEARNING_CHANNELWISE_SCALE_BIAS_HPP_INCLUDED 28 #define LBANN_LAYER_LEARNING_CHANNELWISE_SCALE_BIAS_HPP_INCLUDED 33 #include "lbann/proto/layers.pb.h" 57 template <
typename TensorDataType,
63 "channelwise_mean_layer only supports " 64 "data-parallel data layout");
92 std::string
get_type()
const override {
return "channel-wise scale/bias"; }
101 void setup_data(
size_t max_mini_batch_size)
override;
106 template <
typename ArchiveT>
125 template <
typename T, data_layout L, El::Device D>
127 lbann_data::Layer& proto)
const 129 proto.set_datatype(proto::ProtoDataType<T>);
130 proto.mutable_channelwise_scale_bias();
133 template <
typename TensorDataType, data_layout Layout, El::Device Dev>
139 template <
typename TensorDataType, data_layout Layout, El::Device Dev>
147 template <
typename TensorDataType, data_layout Layout, El::Device Dev>
153 other.m_weights_gradient ? other.m_weights_gradient->Copy() :
nullptr);
157 template <
typename TensorDataType, data_layout Layout, El::Device Dev>
159 size_t max_mini_batch_size)
167 auto w = std::make_shared<WeightsType>(*this->
get_comm());
168 std::vector<TensorDataType> vals(2 * num_channels,
169 El::TypeTraits<TensorDataType>::Zero());
171 vals.begin() + num_channels,
172 El::TypeTraits<TensorDataType>::One());
173 auto init = std::make_unique<value_initializer<TensorDataType>>(vals);
174 auto opt = this->
m_model->template create_optimizer<TensorDataType>();
176 w->set_initializer(std::move(init));
177 w->set_optimizer(std::move(opt));
187 "with an invalid number of weights ",
188 "(expected 1, found ",
195 dist.colDist = El::STAR;
196 dist.rowDist = El::STAR;
208 #ifndef LBANN_CHANNELWISE_SCALE_BIAS_LAYER_INSTANTIATE 210 #define PROTO_DEVICE(T, Device) \ 211 extern template class channelwise_scale_bias_layer< \ 213 data_layout::DATA_PARALLEL, \ 219 #endif // LBANN_CHANNELWISE_SCALE_BIAS_LAYER_INSTANTIATE 223 #endif // LBANN_LAYER_LEARNING_CHANNELWISE_SCALE_BIAS_HPP_INCLUDED
void fill(std::istream &is, google::protobuf::Message &msg)
Fill the protobuf message from a binary stream.
void fp_compute() override
Apply layer operation. Called by the 'forward_prop' function. Given the input tensors, the output tensors are populated with computed values.
bool can_run_inplace() const override
If True, the computation can run in-place (feeding each input activations tensor as the corresponding...
lbann_comm * get_comm() const
El::Device get_device_allocation() const override
Get the device allocation for the data tensors. We assume that the decice allocation of the previous ...
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 add_weights(OwningWeightsPtr &&w)
Add weights to model.
void serialize(ArchiveT &ar)
constexpr El::Device Device
channelwise_scale_bias_layer & operator=(const channelwise_scale_bias_layer &other)
InputAbsDistMatrixType & get_prev_activations(int parent_index=0)
weights const & get_weights(size_t idx) const
void set_name(std::string name)
Metadata Accessors.
size_t num_weights() const noexcept
bool has_weights() const noexcept
void set_matrix_distribution(El::DistData dist)
El::AbstractDistMatrix< TensorDataType > AbsDistMatrixType
The tensor type expected in this object.
std::string get_name() const
Get the layer instance's name.
std::string get_type() const override
Get the layer type's name.
std::unique_ptr< AbsDistMatrixType > m_weights_gradient
Objective function gradient w.r.t. weights.
Apply per-channel scale and bias.
data_layout
Data layout that is optimized for different modes of parallelism.
channelwise_scale_bias_layer(lbann_comm *comm=nullptr)
void set_dims(std::vector< size_t > matrix_height_dims, std::vector< size_t > matrix_width_dims={})
void setup_data(size_t max_mini_batch_size) override
LBANN_DEFINE_LAYER_BUILDER(elu)
std::vector< int > get_output_dims(size_t output_index=0) const
Get output tensor dimensions.
void write_specific_proto(lbann_data::Layer &proto) const final
channelwise_scale_bias_layer * copy() const override
Copy function. This function dynamically allocates memory for a layer instance and instantiates a cop...
void add_weights(ViewingWeightsPtr w)
void bp_compute() override
Compute objective funciton gradients. Called by the 'back_prop' function. Given the input...
data_type_layer & operator=(data_type_layer &&other)=default
model * m_model
Reference to model managing this layer.
int get_backprop_requirements() const override
Returns the necessary tensors for computing backpropagation.
void setup_data(size_t max_mini_batch_size) override
Setup layer data. Called by the 'setup' function. Memory is allocated for distributed matrices...