lightseekorg--tokenspeed
59a0a3844c
PR Test AMD / cancel-on-close (push) Has been skipped
PR Test NVIDIA ARM / scan (push) Has been skipped
PR Test NVIDIA / cancel-on-close (push) Has been skipped
PR Test AMD / scan (push) Has been skipped
PR Test NVIDIA ARM / cancel-on-close (push) Has been skipped
PR Test NVIDIA / scan (push) Has been skipped
Release Docker Images / build (cu129-torch-2.11.0) (push) Has been skipped
Release Docker Images / build (cu130-torch-2.11.0) (push) Has been skipped
Release PyPI / publish (push) Has been skipped
Scheduler Python Test / test (push) Successful in 27m19s
Docs / build (push) Successful in 28m8s
Scheduler C++ Test / test (push) Successful in 28m19s
Scheduler C++ Test / test-flat (push) Successful in 28m18s
Docs / deploy (push) Has been cancelled
PR Test AMD / finish (push) Has been cancelled
PR Test NVIDIA / finish (push) Has been cancelled
PR Test NVIDIA ARM / finish (push) Has been cancelled
PR Test NVIDIA ARM / ${{ matrix.name }} (${{ matrix.runner }}) (push) Has been cancelled
PR Test AMD / ${{ matrix.name }} (${{ matrix.runner }}) (push) Has been cancelled
PR Test NVIDIA / ${{ matrix.name }} (${{ matrix.runner }}) (push) Has been cancelled
136 行
5.1 KiB
C++
136 行
5.1 KiB
C++
// Copyright (c) 2026 LightSeek Foundation
|
|
//
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
// in the Software without restriction, including without limitation the rights
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
// furnished to do so, subject to the following conditions:
|
|
//
|
|
// The above copyright notice and this permission notice shall be included in
|
|
// all copies or substantial portions of the Software.
|
|
//
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
// SOFTWARE.
|
|
|
|
#include "integration_test_helper.h"
|
|
|
|
namespace tokenspeed::test {
|
|
|
|
inline const FlatForwardOperation* GetForwardOp(const std::vector<Operation>& ops) {
|
|
for (const auto& op : ops) {
|
|
if (auto* f = std::get_if<FlatForwardOperation>(&op)) {
|
|
return f;
|
|
}
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
inline std::int32_t FindRequestIndex(const FlatForwardOperation* fwd, const std::string& rid) {
|
|
if (fwd == nullptr) return -1;
|
|
for (std::size_t i = 0; i < fwd->request_ids.size(); ++i) {
|
|
if (fwd->request_ids[i] == rid) return static_cast<std::int32_t>(i);
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
class LoadBackDoneTestSuite : public SchedulerTestSuite {
|
|
protected:
|
|
SchedulerConfig MakeConfig() override {
|
|
auto cfg = SchedulerTestSuite::MakeConfig();
|
|
cfg.decode_input_tokens = 0;
|
|
cfg.device_allocator.total_pages = 5;
|
|
cfg.host_allocator.total_pages = 32;
|
|
cfg.enable_l3_storage = false;
|
|
return cfg;
|
|
}
|
|
|
|
void SetupHostCache() {
|
|
Submit(MakeRequestSpec("r1", /*num_pages=*/2, /*start=*/1));
|
|
PlanOnce();
|
|
SendForwardDone("r1", {42});
|
|
PlanOnce();
|
|
SendFinish("r1");
|
|
auto plan_wb = PlanOnce();
|
|
const FlatWriteBackOperation* wb = nullptr;
|
|
for (const auto& op : plan_wb.Operations()) {
|
|
if (auto* cop = std::get_if<CacheOperation>(&op)) {
|
|
if (auto* w = std::get_if<FlatWriteBackOperation>(cop)) {
|
|
wb = w;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
ASSERT_NE(wb, nullptr) << "SetupHostCache: expected WriteBack op for r1";
|
|
ASSERT_FALSE(wb->op_ids.empty());
|
|
SendWriteBackDone(wb->op_ids[0]);
|
|
PlanOnce();
|
|
|
|
Submit(MakeRequestSpec("r_fill", /*num_pages=*/3, /*start=*/100));
|
|
PlanOnce();
|
|
SendForwardDone("r_fill", {200});
|
|
PlanOnce();
|
|
SendFinish("r_fill");
|
|
auto plan_wb2 = PlanOnce();
|
|
for (const auto& op : plan_wb2.Operations()) {
|
|
if (auto* cop = std::get_if<CacheOperation>(&op)) {
|
|
if (auto* w = std::get_if<FlatWriteBackOperation>(cop)) {
|
|
if (!w->op_ids.empty()) SendWriteBackDone(w->op_ids[0]);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
PlanOnce();
|
|
}
|
|
|
|
static const FlatLoadBackOperation* GetLoadBack(const ExecutionPlan& plan) {
|
|
for (const auto& op : plan.Operations()) {
|
|
if (auto* cop = std::get_if<CacheOperation>(&op)) {
|
|
if (auto* lb = std::get_if<FlatLoadBackOperation>(cop)) return lb;
|
|
}
|
|
}
|
|
return nullptr;
|
|
}
|
|
};
|
|
|
|
// After host cache is populated, a new request with same tokens should see
|
|
// the host cache and be scheduled with reduced input_length (host pages already cached).
|
|
TEST_F(LoadBackDoneTestSuite, LoadBackDone_Success_PrefixLenChangesInForward) {
|
|
SetupHostCache();
|
|
|
|
Submit(MakeRequestSpec("r2", /*num_pages=*/2, /*start=*/1));
|
|
auto plan = PlanOnce();
|
|
auto* fwd = GetForwardOp(plan.Operations());
|
|
ASSERT_NE(fwd, nullptr);
|
|
auto idx = FindRequestIndex(fwd, "r2");
|
|
ASSERT_GE(idx, 0) << "r2 should be in forward after host cache hit";
|
|
|
|
// With block_size=2 and 4 prefill tokens, GetFullPagedTokens(except_last=true)
|
|
// yields 3 tokens → 1 matchable page. Host has 2 pages but only 1 matches.
|
|
// unscheduled = 4 - 1*2 = 2, so input_length = 2 and extend_prefix_len = 1*block_size = 2.
|
|
EXPECT_EQ(fwd->input_lengths[idx], 2) << "host hit covers 1 page; 2 tokens remain";
|
|
|
|
if (!fwd->extend_prefix_lens.empty()) {
|
|
EXPECT_EQ(fwd->extend_prefix_lens[idx], 1 * PageSize()) << "extend_prefix_len should cover the 1 loadback page";
|
|
}
|
|
}
|
|
|
|
// LoadBack is inline (synchronous); subsequent plans proceed normally.
|
|
TEST_F(LoadBackDoneTestSuite, LoadBack_SubsequentPlanProceeds) {
|
|
SetupHostCache();
|
|
|
|
Submit(MakeRequestSpec("r2", /*num_pages=*/2, /*start=*/1));
|
|
auto plan = PlanOnce();
|
|
|
|
auto plan2 = PlanOnce();
|
|
(void)plan2;
|
|
EXPECT_TRUE(true);
|
|
}
|
|
|
|
} // namespace tokenspeed::test
|