Skip to content

Commit 1d29df4

Browse files
pansichengkaiyux
authored andcommitted
fix partialMatch
Signed-off-by: pansicheng <[email protected]>
1 parent 0d35131 commit 1d29df4

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

cpp/include/tensorrt_llm/batch_manager/kvCacheManager.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ struct BlockKey
9494
SizeType32 numMatched{0};
9595
if (loraTaskId == other.loraTaskId)
9696
{
97-
auto [matchEnd, otherMatchEnd]
98-
= std::mismatch(uniqueTokens.begin(), uniqueTokens.end(), other.uniqueTokens.begin());
97+
auto [matchEnd, otherMatchEnd] = std::mismatch(
98+
uniqueTokens.begin(), uniqueTokens.end(), other.uniqueTokens.begin(), other.uniqueTokens.end());
9999
numMatched = std::distance(uniqueTokens.begin(), matchEnd);
100100
}
101101
return numMatched;

cpp/tests/batch_manager/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ target_link_libraries(trtGptModelRealDecoderTest PRIVATE modelSpecStatic
2828
add_gtest(peftCacheManagerTest peftCacheManagerTest.cpp)
2929
add_gtest(trtEncoderModelTest trtEncoderModelTest.cpp)
3030
add_gtest(guidedDecoderTest guidedDecoderTest.cpp)
31+
add_gtest(blockKeyTest blockKeyTest.cpp)
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include "tensorrt_llm/batch_manager/kvCacheManager.h"
2+
3+
#include <gtest/gtest.h>
4+
5+
using namespace tensorrt_llm::batch_manager::kv_cache_manager;
6+
7+
class BlockKeyTest : public ::testing::Test
8+
{
9+
};
10+
11+
TEST_F(BlockKeyTest, PartialMatch)
12+
{
13+
VecUniqueTokens tokens0 = {{0, 0}, {0, 0}};
14+
VecUniqueTokens tokens1 = {{0, 0}};
15+
BlockKey bk0(false, 0, tokens0);
16+
BlockKey bk1(false, 0, tokens1);
17+
18+
bk1.uniqueTokens.reserve(2);
19+
auto ptr = reinterpret_cast<char*>(bk1.uniqueTokens.data());
20+
std::fill(ptr, ptr + bk1.uniqueTokens.capacity() * sizeof(UniqueToken), 0);
21+
22+
EXPECT_EQ(bk0.partialMatch(bk1), 1);
23+
}

0 commit comments

Comments
 (0)