Skip to content
Draft
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
15 changes: 7 additions & 8 deletions tests/core/distributed_runtime/worker_service_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class WorkerServiceOutputTest : public ::testing::Test {
void collect(const ForwardOutput& source, ForwardOutput& destination) {
runtime::Options options;
options.backend("llm");
WorkerService service(options, torch::Device("npu:0"), nullptr);
WorkerService service(options, torch::Device(/*device_string=*/"npu:0"));
collect(service, source, destination);
}
};
Expand All @@ -62,7 +62,7 @@ TEST_F(WorkerServiceOutputTest, WaitsForPendingCpuTokenSnapshot) {
using namespace std::chrono_literals;
runtime::Options options;
options.backend("llm").enable_schedule_overlap(true);
WorkerService service(options, torch::Device("npu:0"), nullptr);
WorkerService service(options, torch::Device(/*device_string=*/"npu:0"));
Stream producer(torch::Device("npu:0"));
ForwardOutput source;
source.next_tokens_host = torch::full({1}, -1, torch::kInt64);
Expand Down Expand Up @@ -402,12 +402,11 @@ void expect_rpc_rejection(runtime::Options options,
Response response;
CountingClosure done;
auto completed = done.get_future();
// The injected constructor marks the service initialized. A null Worker
// ensures rejected requests cannot accidentally enter model execution.
auto service = initialized ? std::make_unique<WorkerService>(
options, torch::Device("npu:0"), nullptr)
: std::make_unique<WorkerService>(
options, torch::Device("npu:0"));
auto service = std::make_unique<WorkerService>(
options, torch::Device(/*device_string=*/"npu:0"));
if (initialized) {
service->set_worker(/*worker=*/nullptr);
}
(service.get()->*rpc)(&controller, &request, &response, &done);
EXPECT_EQ(completed.wait_for(std::chrono::seconds(5)),
std::future_status::ready);
Expand Down
9 changes: 7 additions & 2 deletions tests/core/framework/block/block_manager_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,15 +862,20 @@ TEST(BlockManagerTest, Basic) {
Block& block = blocks[0];
{
const Block alias = block;
EXPECT_EQ(alias, block);
EXPECT_EQ(alias.id(), block.id());
EXPECT_EQ(block.ref_count(), 2);
}
blocks.back() = block;
EXPECT_EQ(blocks.back(), block);
EXPECT_EQ(blocks.back().id(), block.id());
EXPECT_EQ(block.ref_count(), 2);
blocks.pop_back();
EXPECT_EQ(block.ref_count(), 1);

{
const Block pinned(block, /*pin_block=*/true);
EXPECT_EQ(block.ref_count(), 2);
EXPECT_EQ(block.unpinned_ref_count(), 1);
}
const int32_t id = block.id();
const Block moved = std::move(block);
EXPECT_EQ(moved.id(), id);
Expand Down
18 changes: 3 additions & 15 deletions tests/core/framework/block/cache_tier_manager_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,31 +173,16 @@ class HostOffloadPageAllocator final : public VmmKVPageAllocator {
}
}

void trim_kv_cache(const std::string& /*model_id*/,
int32_t /*dp_rank*/) override {}

size_t get_num_available_virt_pages(const std::string& /*model_id*/,
int32_t /*dp_rank*/) const override {
return max_pages_ - mapped_pages_.size();
}
size_t get_num_inuse_virt_pages(const std::string& /*model_id*/,
int32_t /*dp_rank*/) const override {
return mapped_pages_.size();
}
size_t get_num_reserved_virt_pages(const std::string& /*model_id*/,
int32_t /*dp_rank*/) const override {
return mapped_pages_.empty() ? 1 : 0;
}
int64_t get_virt_page_id(int64_t block_id,
size_t block_memory_size) const override {
return block_id * static_cast<int64_t>(block_memory_size) /
static_cast<int64_t>(page_size());
}
size_t page_size() const override { return 64; }
size_t phy_pages_per_virt_page(
const std::string& /*model_id*/) const override {
return 4;
}

size_t mapped_pages() const { return mapped_pages_.size(); }
size_t mapping_count() const { return mapping_count_; }
Expand Down Expand Up @@ -2022,6 +2007,9 @@ TEST_F(CacheTierManagerTest, Dsv4ChunkGrowthOffloadsAllCompletedCacheGroups) {
Sequence sequence = make_test_sequence(/*index=*/0, tokens);

ASSERT_TRUE(pool.allocate(&sequence, kFirstChunkTokens));
const Block execution_block(
sequence.kv_state().blocks(/*type=*/BlockType::C4).front(),
/*pin_block=*/true);
EXPECT_EQ(CacheTierTestPeer::pending_offload_pair_count(pool), 0u);

sequence.kv_state().set_kv_cache_tokens_num(kFirstChunkTokens);
Expand Down
45 changes: 9 additions & 36 deletions tests/core/framework/block/composite_block_manager_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,6 @@ class TestVmmKVPageAllocator final : public VmmKVPageAllocator {
}
}

void trim_kv_cache(const std::string& /*model_id*/,
int32_t /*dp_rank*/) override {}

size_t get_num_available_virt_pages(const std::string& /*model_id*/,
int32_t dp_rank) const override {
if (before_available) {
Expand All @@ -237,25 +234,15 @@ class TestVmmKVPageAllocator final : public VmmKVPageAllocator {
return page_limit > inuse_pages ? page_limit - inuse_pages : 0;
}

size_t get_num_inuse_virt_pages(const std::string& /*model_id*/,
int32_t dp_rank) const override {
size_t num_inuse_virt_pages(int32_t dp_rank) const {
return allocated_pages_.at(dp_rank).size();
}
size_t get_num_reserved_virt_pages(const std::string& /*model_id*/,
int32_t dp_rank) const override {
return allocated_pages_.at(dp_rank).empty() ? 1 : 0;
}
int64_t get_virt_page_id(int64_t block_id,
size_t block_memory_size) const override {
return block_id * static_cast<int64_t>(block_memory_size) /
static_cast<int64_t>(page_size());
}
size_t page_size() const override { return 64; }
size_t phy_pages_per_virt_page(
const std::string& /*model_id*/) const override {
return 4;
}

int32_t prealloc_starts = 0;
std::vector<std::pair<std::string, int32_t>> allocation_requests;
std::vector<std::pair<std::string, int32_t>> released_pages;
Expand Down Expand Up @@ -1772,8 +1759,7 @@ TEST(CompositeBlockManagerTest, VirtualHistoryPlanningDoesNotMapPages) {
leaf, sequence, sequence.kv_state(), /*num_tokens=*/20)
.has_value());
EXPECT_FALSE(sequence.kv_state().has_any_blocks());
EXPECT_EQ(
allocator.get_num_inuse_virt_pages(kHistoryPlanModel, /*dp_rank=*/0), 0u);
EXPECT_EQ(allocator.num_inuse_virt_pages(/*dp_rank=*/0), 0u);

const size_t allocation_attempts = allocator.allocation_requests.size();
const HistoryGrowthPlan fits =
Expand Down Expand Up @@ -1809,16 +1795,12 @@ TEST(CompositeBlockManagerTest, PagedShortageReturnsPagesToInjectedAllocator) {
// One page holds four blocks. A five-block request must release its partial
// allocation, making the same page capacity available to the next request.
EXPECT_TRUE(leaf.allocate(/*num_blocks=*/5).empty());
EXPECT_EQ(
allocator.get_num_inuse_virt_pages(kInjectedCacheModel, /*dp_rank=*/0),
0u);
EXPECT_EQ(allocator.num_inuse_virt_pages(/*dp_rank=*/0), 0u);
ASSERT_EQ(allocator.released_pages.size(), 1u);
std::vector<Block> blocks = leaf.allocate(/*num_blocks=*/1);
ASSERT_EQ(blocks.size(), 1u);
blocks.clear();
EXPECT_EQ(
allocator.get_num_inuse_virt_pages(kInjectedCacheModel, /*dp_rank=*/0),
0u);
EXPECT_EQ(allocator.num_inuse_virt_pages(/*dp_rank=*/0), 0u);
EXPECT_EQ(allocator.released_pages.size(), 2u);
}

Expand All @@ -1840,9 +1822,7 @@ TEST(CompositeBlockManagerTest, VirtualPrefixRetainsPagesAndReusesBlockIds) {
EXPECT_EQ(leaf.num_blocks_in_prefix_cache(), 2u);
EXPECT_EQ(leaf.num_used_blocks(), 0u);
EXPECT_EQ(leaf.num_free_blocks(), 4u);
EXPECT_EQ(
allocator.get_num_inuse_virt_pages(kPrefixCacheModel, /*dp_rank=*/0),
1u);
EXPECT_EQ(allocator.num_inuse_virt_pages(/*dp_rank=*/0), 1u);
EXPECT_TRUE(allocator.released_pages.empty());

std::vector<Block> matched = leaf.allocate_shared(tokens);
Expand Down Expand Up @@ -1878,8 +1858,7 @@ TEST(CompositeBlockManagerTest, VirtualPrefixEvictsIdleBlocksUnderPressure) {
ASSERT_EQ(replacement.size(), 2u);
EXPECT_EQ(leaf.num_blocks_in_prefix_cache(), 2u);
EXPECT_EQ(leaf.num_used_blocks(), 2u);
EXPECT_EQ(
allocator.get_num_inuse_virt_pages(kPrefixCacheModel, /*dp_rank=*/0), 1u);
EXPECT_EQ(allocator.num_inuse_virt_pages(/*dp_rank=*/0), 1u);
EXPECT_TRUE(allocator.released_pages.empty());
std::vector<Block> matched = leaf.allocate_shared(tokens);
ASSERT_EQ(matched.size(), 2u);
Expand Down Expand Up @@ -2294,15 +2273,11 @@ TEST(CompositeBlockManagerTest,
// must keep its page mapped until its original owner releases it.
EXPECT_TRUE(leaf.allocate(/*num_blocks=*/4).empty());
EXPECT_EQ(leaf.num_used_blocks(), 1u);
EXPECT_EQ(
allocator.get_num_inuse_virt_pages(kInjectedCacheModel, /*dp_rank=*/0),
1u);
EXPECT_EQ(allocator.num_inuse_virt_pages(/*dp_rank=*/0), 1u);
EXPECT_TRUE(allocator.released_pages.empty());
held.clear();
EXPECT_EQ(leaf.num_used_blocks(), 0u);
EXPECT_EQ(
allocator.get_num_inuse_virt_pages(kInjectedCacheModel, /*dp_rank=*/0),
0u);
EXPECT_EQ(allocator.num_inuse_virt_pages(/*dp_rank=*/0), 0u);
EXPECT_EQ(allocator.released_pages.size(), 1u);
}

Expand All @@ -2317,9 +2292,7 @@ TEST(CompositeBlockManagerTest, VirtualMemoryRejectsDoubleFreeAfterPageDetach) {
const int32_t block_id = blocks.front().id();
blocks.clear();
EXPECT_EQ(leaf.num_used_blocks(), 0u);
EXPECT_EQ(
allocator.get_num_inuse_virt_pages(kInjectedCacheModel, /*dp_rank=*/0),
0u);
EXPECT_EQ(allocator.num_inuse_virt_pages(/*dp_rank=*/0), 0u);
ASSERT_EQ(allocator.released_pages.size(), 1u);

// The page-state object is already gone, so the manager must reject a
Expand Down
Loading
Loading