| 543 | |
| 544 | template <typename TensorDataType, data_layout Layout, El::Device Device> |
| 545 | void channelwise_fully_connected_layer<TensorDataType, Layout, Device>:: |
| 546 | setup_data(size_t max_mini_batch_size) |
| 547 | { |
| 548 | data_type_layer<TensorDataType>::setup_data(max_mini_batch_size); |
| 549 | |
| 550 | // Tensor dimensions |
| 551 | const auto& input_dims = this->get_input_dims(); |
| 552 | const auto& output_dims = this->get_output_dims(); |
| 553 | const std::vector<size_t> input_channel_dims(input_dims.begin() + 1, |
| 554 | input_dims.end()); |
| 555 | const std::vector<size_t> output_channel_dims(output_dims.begin() + 1, |
| 556 | output_dims.end()); |
| 557 | const auto& input_channel_size = std::accumulate(input_channel_dims.begin(), |
| 558 | input_channel_dims.end(), |
| 559 | 1, |
| 560 | std::multiplies<size_t>()); |
| 561 | const auto& output_channel_size = std::accumulate(output_channel_dims.begin(), |
| 562 | output_channel_dims.end(), |
| 563 | 1, |
| 564 | std::multiplies<size_t>()); |
| 565 | |
| 566 | // Set number of weights |
| 567 | using WeightsType = data_type_weights<TensorDataType>; |
| 568 | if ((m_has_bias && this->num_weights() > 2) || |
| 569 | (!m_has_bias && this->num_weights() > 1)) { |
| 570 | LBANN_ERROR("attempted to setup ", |
| 571 | this->get_type(), |
| 572 | " layer \"", |
| 573 | this->get_name(), |
| 574 | "\" ", |
| 575 | "with an invalid number of weights ", |
| 576 | "(", |
| 577 | this->num_weights(), |
| 578 | ")"); |
| 579 | } |
| 580 | this->set_num_weights(m_has_bias ? 2 : 1); |
| 581 | |
| 582 | // Create default linearity weights if needed |
| 583 | if (!this->has_weights(0)) { |
| 584 | auto w = std::make_shared<WeightsType>(*this->get_comm()); |
| 585 | auto init = std::make_unique<he_initializer<TensorDataType>>( |
| 586 | probability_distribution::gaussian); |
| 587 | auto opt = this->m_model->template create_optimizer<TensorDataType>(); |
| 588 | w->set_name(this->get_name() + "_linearity_weights"); |
| 589 | w->set_initializer(std::move(init)); |
| 590 | w->set_optimizer(std::move(opt)); |
| 591 | this->set_weights(0, w); |
| 592 | this->m_model->add_weights(std::move(w)); |
| 593 | } |
| 594 | |
| 595 | // Setup linearity weights |
| 596 | { |
| 597 | auto& linearity_weights = this->get_weights(0); |
| 598 | auto dist = this->get_prev_activations().DistData(); |
| 599 | if (dist.colDist != El::MC || dist.rowDist != El::MR) { |
| 600 | dist.colDist = El::STAR; |
| 601 | dist.rowDist = El::STAR; |
| 602 | } |
nothing calls this directly
no test coverage detected