Skip to content

Commit

Permalink
[Update] Removed SmartReply property and added nnlayergolden files
Browse files Browse the repository at this point in the history
Addressed multiple review comments
Removed unnecessary code
Added nnlayer golden files

Signed-off-by: Yash Singh <[email protected]>
  • Loading branch information
yashSingh0723 committed Dec 3, 2024
1 parent 3c37aa8 commit 2d8c2e8
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 74 deletions.
3 changes: 2 additions & 1 deletion nntrainer/layers/cl_layers/custom_vocab_selection.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
/**
* Copyright (C) 2024 Yash Singh <[email protected]>>
* Copyright (C) 2024 Hyeonseok Lee <[email protected]>
* Copyright (C) 2024 Yash Singh <[email protected]>
*
* @file custom_vocab_selection.cpp
* @date 1 Oct 2024
Expand Down
3 changes: 2 additions & 1 deletion nntrainer/layers/cl_layers/custom_vocab_selection.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
/**
* Copyright (C) 2024 Yash Singh <[email protected]>>
* Copyright (C) 2024 Hyeonseok Lee <[email protected]>
* Copyright (C) 2024 Yash Singh <[email protected]>
*
* @file custom_vocab_selection.h
* @date 1 Oct 2024
Expand Down
35 changes: 8 additions & 27 deletions nntrainer/layers/cl_layers/lm_head_layer_cl.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: Apache-2.0
/**
* Copyright (C) 2024 Yash Singh <[email protected]>>
* Copyright (C) 2024 Yash Singh <[email protected]>
*
* @file lm_head_layer_cl.cpp
* @date 1 Oct 2024
Expand All @@ -26,7 +26,7 @@ enum LMHeadParams { weight, bias, candidate_weight, candidate_hidden_step };
CustomLMHeadLayerCl::CustomLMHeadLayerCl() :
LayerImpl(),
custom_lm_head_props(nntrainer::props::Unit(), props::UseVocabSelection(),
props::LshChoices(), props::SmartReply()) {
props::LshChoices()) {
weight_idx.fill(std::numeric_limits<unsigned>::max());
}

Expand All @@ -36,8 +36,6 @@ void CustomLMHeadLayerCl::finalize(nntrainer::InitLayerContext &context) {
auto &weight_regularizer_constant =
std::get<nntrainer::props::WeightRegularizerConstant>(*layer_impl_props);
auto weight_initializer = nntrainer::props::InitializerInfo::Enum::ZEROS;
// auto &weight_initializer =
// std::get<nntrainer::props::WeightInitializer>(*layer_impl_props);
auto &weight_decay =
std::get<nntrainer::props::WeightDecay>(*layer_impl_props);
auto &bias_decay = std::get<nntrainer::props::BiasDecay>(*layer_impl_props);
Expand Down Expand Up @@ -170,14 +168,14 @@ void CustomLMHeadLayerCl::incremental_forwarding(
hidden_step_dim.batch(1);
hidden_step_dim.height(1);

bool smart_reply = std::get<props::SmartReply>(custom_lm_head_props).get();
// bool smart_reply = std::get<props::SmartReply>(custom_lm_head_props).get();

unsigned int b_size = input_dim.batch();
unsigned omp_num = 4;
if (smart_reply && !_from) {
b_size = 1;
omp_num = 1;
}
// if (smart_reply && !_from) {
// b_size = 1;
// omp_num = 1;
// }

// #pragma omp parallel for num_threads(omp_num)
for (unsigned int b = 0; b < b_size; ++b) {
Expand Down Expand Up @@ -228,7 +226,7 @@ void CustomLMHeadLayerCl::incremental_forwarding(
nntrainer::Tensor &bias =
context.getWeight(weight_idx[LMHeadParams::bias]);

add_i_cl(bias, hidden_step);
add_i_cl(hidden_step, bias);
}
}
}
Expand All @@ -239,21 +237,4 @@ void CustomLMHeadLayerCl::setProperty(const std::vector<std::string> &values) {
auto remain_props = loadProperties(values, custom_lm_head_props);
LayerImpl::setProperty(remain_props);
}

#ifdef PLUGGABLE

nntrainer::Layer *create_custom_lm_head_layer() {
auto layer = new CustomLMHeadLayerCl();
return layer;
}

void destroy_custom_lm_head_layer(nntrainer::Layer *layer) { delete layer; }

extern "C" {
nntrainer::LayerPluggable ml_train_layer_pluggable{
create_custom_lm_head_layer, destroy_custom_lm_head_layer};
}

#endif

} // namespace nntrainer
4 changes: 1 addition & 3 deletions nntrainer/layers/cl_layers/lm_head_layer_cl.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#ifndef __CUSTOM_LM_HEAD_LAYER_H__
#define __CUSTOM_LM_HEAD_LAYER_H__

#include <custom_properties.h>
#include <custom_vocab_selection.h>
#include <layer_context.h>
#include <layer_impl.h>
Expand Down Expand Up @@ -152,13 +151,12 @@ class CustomLMHeadLayerCl : public LayerImpl {

private:
std::tuple<nntrainer::props::Unit, props::UseVocabSelection,
props::LshChoices, props::SmartReply>
props::LshChoices>
custom_lm_head_props;
std::array<unsigned int, 4> weight_idx; /**< indices of the weights */
std::unique_ptr<nntrainer::Tensor>
weight_T; // temporary weight. will be removed
};

} // namespace nntrainer

#endif /* __LM_HEAD_LAYER_CL_H__ */
42 changes: 0 additions & 42 deletions nntrainer/utils/custom_properties.h

This file was deleted.

Binary file modified packaging/unittest_layers.tar.gz
Binary file not shown.

0 comments on commit 2d8c2e8

Please sign in to comment.