27 #ifndef LBANN_LAYER_LEARNING_ENTRYWISE_SCALE_BIAS_HPP_INCLUDED 28 #define LBANN_LAYER_LEARNING_ENTRYWISE_SCALE_BIAS_HPP_INCLUDED 33 #include "lbann/proto/layers.pb.h" 54 template <
typename TensorDataType,
85 std::string
get_type()
const override {
return "entry-wise scale/bias"; }
97 template <
typename ArchiveT>
102 void setup_data(
size_t max_mini_batch_size)
override;
118 template <
typename T, data_layout L, El::Device D>
120 lbann_data::Layer& proto)
const 122 proto.set_datatype(proto::ProtoDataType<T>);
123 proto.mutable_entrywise_scale_bias();
126 template <
typename TensorDataType, data_layout Layout, El::Device Dev>
132 template <
typename TensorDataType, data_layout Layout, El::Device Dev>
140 template <
typename TensorDataType, data_layout Layout, El::Device Dev>
146 other.m_weights_gradient ? other.m_weights_gradient->Copy() :
nullptr);
150 template <
typename TensorDataType, data_layout Layout, El::Device Dev>
152 size_t max_mini_batch_size)
159 std::vector<size_t> output_dims(output_dims_.begin(), output_dims_.end());
165 auto w = std::make_shared<WeightsType>(*this->
get_comm());
166 std::vector<TensorDataType> vals(2 * output_size,
167 El::TypeTraits<TensorDataType>::Zero());
169 vals.begin() + output_size,
170 El::TypeTraits<TensorDataType>::One());
171 auto init = std::make_unique<value_initializer<TensorDataType>>(vals);
172 auto opt = this->
m_model->template create_optimizer<TensorDataType>();
174 w->set_initializer(std::move(init));
175 w->set_optimizer(std::move(opt));
185 "with an invalid number of weights ",
186 "(expected 1, found ",
193 dist.rowDist = El::STAR;
205 #ifndef LBANN_ENTRYWISE_SCALE_BIAS_LAYER_INSTANTIATE 207 #define PROTO_DEVICE(T, Device) \ 208 extern template class entrywise_scale_bias_layer<T, \ 209 data_layout::DATA_PARALLEL, \ 211 extern template class entrywise_scale_bias_layer< \ 213 data_layout::MODEL_PARALLEL, \ 219 #endif // LBANN_ENTRYWISE_SCALE_BIAS_LAYER_INSTANTIATE 223 #endif // LBANN_LAYER_LEARNING_ENTRYWISE_SCALE_BIAS_HPP_INCLUDED
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.
El::AbstractDistMatrix< TensorDataType > AbsDistMatrixType
The tensor type expected in this object.
void fill(std::istream &is, google::protobuf::Message &msg)
Fill the protobuf message from a binary stream.
std::string get_type() const override
Get the layer type's name.
void serialize(ArchiveT &ar)
lbann_comm * get_comm() const
entrywise_scale_bias_layer & operator=(const entrywise_scale_bias_layer &other)
std::unique_ptr< AbsDistMatrixType > m_weights_gradient
Objective function gradient w.r.t. weights.
int get_output_size(size_t output_index=0) const
Get output tensor size.
void bp_compute() override
Compute objective funciton gradients. Called by the 'back_prop' function. Given the input...
entrywise_scale_bias_layer(lbann_comm *comm=nullptr)
El::Device get_device_allocation() const override
Get the device allocation for the data tensors. We assume that the decice allocation of the previous ...
std::vector< int > get_input_dims(size_t input_index=0) const
Get input tensor dimensions.
bool can_run_inplace() const override
If True, the computation can run in-place (feeding each input activations tensor as the corresponding...
entrywise_scale_bias_layer * copy() const override
Copy function. This function dynamically allocates memory for a layer instance and instantiates a cop...
void add_weights(OwningWeightsPtr &&w)
Add weights to model.
constexpr El::Device Device
InputAbsDistMatrixType & get_prev_activations(int parent_index=0)
weights const & get_weights(size_t idx) const
void set_name(std::string name)
Metadata Accessors.
void set_output_dims(std::vector< int > dims, size_t output_index=0)
Set output tensor dimensions.
size_t num_weights() const noexcept
bool has_weights() const noexcept
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 set_matrix_distribution(El::DistData dist)
std::string get_name() const
Get the layer instance's name.
data_layout
Data layout that is optimized for different modes of parallelism.
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
void setup_data(size_t max_mini_batch_size) override
Setup layer data. Called by the 'setup' function. Memory is allocated for distributed matrices...
LBANN_DEFINE_LAYER_BUILDER(elu)
Apply entry-wise scale and bias.
std::vector< int > get_output_dims(size_t output_index=0) const
Get output tensor dimensions.
int get_backprop_requirements() const override
Returns the necessary tensors for computing backpropagation.
void add_weights(ViewingWeightsPtr w)
data_type_layer & operator=(data_type_layer &&other)=default
void write_specific_proto(lbann_data::Layer &proto) const final
model * m_model
Reference to model managing this layer.