Skip to content

fix: fix partialMatch #3413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions cpp/include/tensorrt_llm/batch_manager/kvCacheManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ struct BlockKey
SizeType32 numMatched{0};
if (loraTaskId == other.loraTaskId)
{
auto [matchEnd, otherMatchEnd]
= std::mismatch(uniqueTokens.begin(), uniqueTokens.end(), other.uniqueTokens.begin());
auto [matchEnd, otherMatchEnd] = std::mismatch(
uniqueTokens.begin(), uniqueTokens.end(), other.uniqueTokens.begin(), other.uniqueTokens.end());
numMatched = std::distance(uniqueTokens.begin(), matchEnd);
}
return numMatched;
Expand Down
1 change: 1 addition & 0 deletions cpp/tests/batch_manager/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ target_link_libraries(trtGptModelRealDecoderTest PRIVATE modelSpecStatic
add_gtest(peftCacheManagerTest peftCacheManagerTest.cpp)
add_gtest(trtEncoderModelTest trtEncoderModelTest.cpp)
add_gtest(guidedDecoderTest guidedDecoderTest.cpp)
add_gtest(blockKeyTest blockKeyTest.cpp)
23 changes: 23 additions & 0 deletions cpp/tests/batch_manager/blockKeyTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "tensorrt_llm/batch_manager/kvCacheManager.h"

#include <gtest/gtest.h>

using namespace tensorrt_llm::batch_manager::kv_cache_manager;

class BlockKeyTest : public ::testing::Test
{
};

TEST_F(BlockKeyTest, PartialMatch)
{
VecUniqueTokens tokens0 = {{0, 0}, {0, 0}};
VecUniqueTokens tokens1 = {{0, 0}};
BlockKey bk0(false, 0, tokens0);
BlockKey bk1(false, 0, tokens1);

bk1.uniqueTokens.reserve(2);
auto ptr = reinterpret_cast<char*>(bk1.uniqueTokens.data());
std::fill(ptr, ptr + bk1.uniqueTokens.capacity() * sizeof(UniqueToken), 0);

EXPECT_EQ(bk0.partialMatch(bk1), 1);
}