};
PositionalEncodingLayer::PositionalEncodingLayer() :
- isPEcalculated(false),
- positional_encoding_props(props::MaxTimestep()) {
+ isPEcalculated(false), positional_encoding_props(props::MaxTimestep()) {
weight_idx.fill(std::numeric_limits<unsigned>::max());
}
unsigned int model_dim = input_dims[SINGLE_INOUT_IDX].width();
- ml::train::TensorDim pe_dim({max_token_size, model_dim});
+ ml::train::TensorDim pe_dim(
+ {max_token_size, model_dim},
+ {context.getFormat(), context.getWeightDataType()});
weight_idx[PositionalEncodingParams::positional_encoding] =
context.requestTensor(pe_dim, "positional_encoding",
nntrainer::Tensor::Initializer::NONE, false,
weight_idx[PositionalEncodingParams::positional_encoding]);
TensorDim input_dim = input.getDim();
- TensorDim pe_partial_dim({input_dim.height(), input_dim.width()});
+ TensorDim pe_partial_dim({input_dim.height(), input_dim.width()},
+ context.getTensor(0).getTensorType());
nntrainer::Tensor pe_partial = pe.getSharedDataTensor(pe_partial_dim, 0);
if (!isPEcalculated) {
INSTANTIATE_TEST_CASE_P(PositionalEncoding, LayerGoldenTest,
::testing::Values(positional_encoding_partial,
positional_encoding));
+
+auto positional_encoding_partial_fp16fp16 = LayerGoldenTestParamType(
+ nntrainer::createLayer<nntrainer::PositionalEncodingLayer>,
+ {"max_timestep=10"}, "3:1:7:6",
+ "positional_encoding_partial_fp16fp16.nnlayergolden",
+ LayerGoldenTestParamOptions::DEFAULT, "nchw", "fp16", "fp16");
+
+auto positional_encoding_fp16fp16 = LayerGoldenTestParamType(
+ nntrainer::createLayer<nntrainer::PositionalEncodingLayer>,
+ {"max_timestep=10"}, "3:1:10:6", "positional_encoding_fp16fp16.nnlayergolden",
+ LayerGoldenTestParamOptions::DEFAULT, "nchw", "fp16", "fp16");
+
+INSTANTIATE_TEST_CASE_P(PositionalEncoding16, LayerGoldenTest,
+ ::testing::Values(positional_encoding_partial_fp16fp16,
+ positional_encoding_fp16fp16));