MCPcopy Create free account
hub / github.com/LBANN/lbann / setup_data

Method setup_data

src/layers/transform/weights.cpp:90–146  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88
89template <typename TensorDataType, data_layout Layout, El::Device Device>
90void weights_layer<TensorDataType, Layout, Device>::setup_data(
91 size_t max_mini_batch_size)
92{
93 data_type_layer<TensorDataType>::setup_data(max_mini_batch_size);
94
95 // Initialize default weights if none are provided
96 if (!this->has_weights()) {
97 auto w = std::make_shared<WeightsType>(*this->get_comm());
98 auto init = std::make_unique<constant_initializer<DataType>>(DataType(0));
99 auto opt = this->m_model->template create_optimizer<TensorDataType>();
100 w->set_name(this->get_name() + "_weights");
101 w->set_initializer(std::move(init));
102 w->set_optimizer(std::move(opt));
103 this->add_weights(w);
104 this->m_model->add_weights(std::move(w));
105 }
106 if (this->num_weights() != 1) {
107 LBANN_ERROR("attempted to setup ",
108 this->get_type(),
109 " layer \"",
110 this->get_name(),
111 "\" ",
112 "with an invalid number of weights ",
113 "(expected at most 1, ",
114 "but found ",
115 this->num_weights(),
116 ")");
117 }
118
119 // Setup weights
120 const auto& output_dims_ = this->get_output_dims();
121 std::vector<size_t> output_dims(output_dims_.begin(), output_dims_.end());
122 auto dist = this->get_activations().DistData();
123 dist.rowDist = El::STAR;
124 this->get_weights(0).set_dims(output_dims);
125 this->get_weights(0).set_matrix_distribution(dist);
126
127 // Initialize freeze state
128 if (this->m_frozen) {
129 this->get_weights(0).freeze();
130 }
131 else {
132 this->get_weights(0).unfreeze();
133 }
134 if (this->get_weights(0).is_frozen() != this->m_frozen) {
135 LBANN_ERROR((this->m_frozen ? "" : "un"),
136 "frozen ",
137 "layer \"",
138 this->get_name(),
139 "\" has ",
140 (this->get_weights(0).is_frozen() ? "" : "un"),
141 "frozen ",
142 "weights \"",
143 this->get_weights(0).get_name(),
144 "\"");
145 }
146}
147

Callers

nothing calls this directly

Calls 15

get_typeMethod · 0.95
has_weightsMethod · 0.80
set_initializerMethod · 0.80
set_optimizerMethod · 0.80
num_weightsMethod · 0.80
get_output_dimsMethod · 0.80
beginMethod · 0.80
endMethod · 0.80
get_activationsMethod · 0.80
get_commMethod · 0.45
set_nameMethod · 0.45

Tested by

no test coverage detected