27 #ifndef LBANN_LAYER_WEIGHTED_SUM_HPP_INCLUDED 28 #define LBANN_LAYER_WEIGHTED_SUM_HPP_INCLUDED 37 template <
typename TensorDataType,
48 :
data_type_layer<TensorDataType>(comm), m_scaling_factors(scaling_factors)
61 template <
typename ArchiveT>
66 std::string
get_type()
const override {
return "weighted sum"; }
76 for (
size_t i = 0; i < m_scaling_factors.size(); ++i) {
77 ss << (i > 0 ?
", " :
"") << m_scaling_factors[i];
79 desc.add(
"Scaling factors", ss.str());
93 std::stringstream err;
96 <<
"has no parent layers";
101 <<
"has an invalid number of scaling factors " 102 <<
"(found " << m_scaling_factors.size() <<
", " 118 std::stringstream err;
120 <<
"has input tensors with incompatible dimensions (";
123 err << (j > 0 ?
", " :
"") <<
"layer \"" << parents[j]->
get_name()
125 for (
size_t k = 0; k < dims.size(); ++k) {
126 err << (k > 0 ?
" x " :
"") << dims[k];
143 El::Scale(m_scaling_factors[0], output);
155 El::Zero(gradient_wrt_input);
156 El::Axpy(m_scaling_factors[i], gradient_wrt_output, gradient_wrt_input);
166 #ifndef LBANN_WEIGHTED_SUM_LAYER_INSTANTIATE 167 #define PROTO_DEVICE(T, Device) \ 168 extern template class weighted_sum_layer<T, \ 169 data_layout::DATA_PARALLEL, \ 171 extern template class weighted_sum_layer<T, \ 172 data_layout::MODEL_PARALLEL, \ 177 #endif // LBANN_WEIGHTED_SUM_LAYER_INSTANTIATE 181 #endif // LBANN_LAYER_WEIGHTED_SUM_HPP_INCLUDED void write_specific_proto(lbann_data::Layer &proto) const final
void bp_compute() override
Compute objective funciton gradients. Called by the 'back_prop' function. Given the input...
virtual void setup_dims()
Setup tensor dimensions Called by the 'setup' function. If there are any input tensors, the base method sets all uninitialized output tensor dimensions equal to the first input tensor dimensions.
weighted_sum_layer(lbann_comm *comm, std::vector< DataType > scaling_factors)
void setup_dims() override
Setup tensor dimensions Called by the 'setup' function. If there are any input tensors, the base method sets all uninitialized output tensor dimensions equal to the first input tensor dimensions.
Add tensors with scaling factors.
bool m_runs_inplace
If true, the layer will run in-place (the input and output activations point to the same tensor)...
int get_num_parents() const noexcept
Get number of parent layers.
int get_backprop_requirements() const override
Returns the necessary tensors for computing backpropagation.
std::vector< int > get_input_dims(size_t input_index=0) const
Get input tensor dimensions.
Generates nicely formatted description messages.
friend class cereal::access
virtual description get_description() const
Human-readable description.
void serialize(ArchiveT &ar)
constexpr El::Device Device
OutputAbsDistMatrixType & get_prev_error_signals(int child_index=0)
InputAbsDistMatrixType & get_prev_activations(int parent_index=0)
description get_description() const override
Human-readable description.
const OutputAbsDistMatrixType & get_activations(const Layer &child) const override
bool can_run_inplace() const override
If True, the computation can run in-place (feeding each input activations tensor as the corresponding...
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.
void set_output_dims(std::vector< int > dims, size_t output_index=0)
Set output tensor dimensions.
std::vector< const Layer * > get_parent_layers() const
std::string get_name() const
Get the layer instance's name.
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
Data layout that is optimized for different modes of parallelism.
void setup_pointers() override
Setup layer pointers. Called by the 'setup' function. Pointers to parent/child layers are assumed to ...
weighted_sum_layer * copy() const override
Copy function. This function dynamically allocates memory for a layer instance and instantiates a cop...
std::string get_type() const override
Get the layer type's name.
virtual void setup_pointers()
Setup layer pointers. Called by the 'setup' function. Pointers to parent/child layers are assumed to ...
std::vector< int > get_output_dims(size_t output_index=0) const
Get output tensor dimensions.
data_layout get_data_layout() const override
Get data layout of the data tensors. We assume that the data layouts of the previous activations...
std::vector< DataType > m_scaling_factors
int m_expected_num_parent_layers
const InputAbsDistMatrixType & get_error_signals(const Layer &parent) const override