Skip to content
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test(llm): 添加 attention 前端单测
Signed-off-by: YdrMaster <[email protected]>
  • Loading branch information
YdrMaster committed Feb 19, 2024
commit 9f736e9a1d394bd7de401e2a8778f9cb6db66c4b
44 changes: 44 additions & 0 deletions src/08-01llm/test/test_attention.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "../src/operators/attention.hh"
#include "llm/operators.h"
#include <gtest/gtest.h>

using namespace refactor;
using namespace llm;

TEST(infer, AttentionNoKvCache) {
llm::register_();
auto batch = DimExpr("N");
auto numHead = DimExpr(16);
auto seqLen = DimExpr(31);
auto headDim = DimExpr(64);
{
auto edges = Edges{
{Tensor::share(DataType::FP16, Shape{batch, numHead, seqLen, headDim}, {}), ""},
{Tensor::share(DataType::FP16, Shape{batch, numHead, seqLen, headDim}, {}), ""},
{Tensor::share(DataType::FP16, Shape{batch, numHead, seqLen, headDim}, {}), ""},
};
count_t inputs[]{0, 1, 2};
auto infered = Attention(0).infer(TensorRefs(edges, inputs), {true});
ASSERT_TRUE(infered.isOk());
auto outputs = std::move(infered.unwrap());
ASSERT_EQ(outputs.size(), 1);
auto y = std::move(outputs[0]);
ASSERT_EQ(y->dataType, DataType::FP16);
ASSERT_EQ(y->shape, edges[0].tensor->shape);
}
{
auto edges = Edges{
{Tensor::share(DataType::FP16, Shape{batch, numHead, seqLen, headDim}, {}), ""},
{Tensor::share(DataType::FP16, Shape{batch, DimExpr(4), seqLen, headDim}, {}), ""},
{Tensor::share(DataType::FP16, Shape{batch, DimExpr(4), seqLen, headDim}, {}), ""},
};
count_t inputs[]{0, 1, 2};
auto infered = Attention(0).infer(TensorRefs(edges, inputs), {true});
ASSERT_TRUE(infered.isOk());
auto outputs = std::move(infered.unwrap());
ASSERT_EQ(outputs.size(), 1);
auto y = std::move(outputs[0]);
ASSERT_EQ(y->dataType, DataType::FP16);
ASSERT_EQ(y->shape, edges[0].tensor->shape);
}
}