Added 4d quantized LUT unittest for embedding_lookup
Type: New Feature | Bug Fix | Code Improvement | Documentation Issue: bugzilla id | jira id #No more newline after this Signed-off-by: Feiyue Chen <Feiyue.Chen@verisilicon.com>
This commit is contained in:
parent
06d4747b31
commit
789d4458ff
|
|
@ -24,10 +24,11 @@
|
||||||
#include "tim/vx/context.h"
|
#include "tim/vx/context.h"
|
||||||
#include "tim/vx/graph.h"
|
#include "tim/vx/graph.h"
|
||||||
#include "tim/vx/ops/embedding_lookup.h"
|
#include "tim/vx/ops/embedding_lookup.h"
|
||||||
|
#include "test_utils.h"
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
TEST(EmbeddingLookup, shape_2_5_int32) {
|
|
||||||
|
TEST(EmbeddingLookup, shape_2_5_int32LUT) {
|
||||||
auto ctx = tim::vx::Context::Create();
|
auto ctx = tim::vx::Context::Create();
|
||||||
auto graph = ctx->CreateGraph();
|
auto graph = ctx->CreateGraph();
|
||||||
tim::vx::ShapeType idx_shape({3});
|
tim::vx::ShapeType idx_shape({3});
|
||||||
|
|
@ -64,3 +65,50 @@ TEST(EmbeddingLookup, shape_2_5_int32) {
|
||||||
EXPECT_TRUE(out_tensor->CopyDataFromTensor(output.data()));
|
EXPECT_TRUE(out_tensor->CopyDataFromTensor(output.data()));
|
||||||
EXPECT_EQ(golden, output);
|
EXPECT_EQ(golden, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(EmbeddingLookup, shape_2_2_2_3_Uint8QuantizedLUT) {
|
||||||
|
auto ctx = tim::vx::Context::Create();
|
||||||
|
auto graph = ctx->CreateGraph();
|
||||||
|
tim::vx::ShapeType idx_shape({3});
|
||||||
|
tim::vx::ShapeType lut_shape({2, 2, 2, 3});
|
||||||
|
tim::vx::ShapeType out_shape({2, 2, 2, 3});
|
||||||
|
tim::vx::Quantization quant_lut(tim::vx::QuantType::ASYMMETRIC,
|
||||||
|
0.0167716537, 0);
|
||||||
|
|
||||||
|
tim::vx::TensorSpec idx_spec(tim::vx::DataType::INT32, idx_shape,
|
||||||
|
tim::vx::TensorAttribute::INPUT);
|
||||||
|
tim::vx::TensorSpec lut_spec(tim::vx::DataType::UINT8, lut_shape,
|
||||||
|
tim::vx::TensorAttribute::INPUT, quant_lut);
|
||||||
|
tim::vx::TensorSpec out_spec(tim::vx::DataType::FLOAT32, out_shape,
|
||||||
|
tim::vx::TensorAttribute::OUTPUT);
|
||||||
|
auto idx_tensor = graph->CreateTensor(idx_spec);
|
||||||
|
auto lut_tensor = graph->CreateTensor(lut_spec);
|
||||||
|
auto out_tensor = graph->CreateTensor(out_spec);
|
||||||
|
|
||||||
|
std::vector<int32_t> idx_data = {1,0,2};
|
||||||
|
std::vector<uint8_t> lut_data =
|
||||||
|
{
|
||||||
|
0, 1, 1, 2, 6, 7, 7, 8, // Row 0
|
||||||
|
60, 60, 61, 61,66, 66, 67, 67, // Row 1
|
||||||
|
119, 120,120, 121, 125, 126, 126, 127, // Row 2
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<float> golden =
|
||||||
|
{1.00, 1.01, 1.02, 1.03, 1.10, 1.11, 1.12, 1.13, // Row 1
|
||||||
|
0.00, 0.01, 0.02, 0.03, 0.10, 0.11, 0.12, 0.13, // Row 0
|
||||||
|
2.00, 2.01, 2.02, 2.03, 2.10, 2.11, 2.12, 2.13, // Row 2
|
||||||
|
};
|
||||||
|
EXPECT_TRUE(idx_tensor->CopyDataToTensor(idx_data.data(),
|
||||||
|
idx_data.size() * sizeof(int32_t)));
|
||||||
|
EXPECT_TRUE(lut_tensor->CopyDataToTensor(lut_data.data(),
|
||||||
|
lut_data.size() * sizeof(uint8_t)));
|
||||||
|
auto op = graph->CreateOperation<tim::vx::ops::EmbeddingLookup>();
|
||||||
|
(*op).BindInputs({idx_tensor,lut_tensor}).BindOutput(out_tensor);
|
||||||
|
|
||||||
|
EXPECT_TRUE(graph->Compile());
|
||||||
|
EXPECT_TRUE(graph->Run());
|
||||||
|
|
||||||
|
std::vector<float> output(golden.size());
|
||||||
|
EXPECT_TRUE(out_tensor->CopyDataFromTensor(output.data()));
|
||||||
|
EXPECT_TRUE(ArraysMatch(golden, output, (float)7.41e-03));
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue