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
212 行
7.6 KiB
C++
212 行
7.6 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 {
|
|
|
|
class LoadBackViaCacheTestSuite : 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("r_seed", /*num_pages=*/2, /*start=*/1));
|
|
PlanOnce();
|
|
SendForwardDone("r_seed", {42});
|
|
PlanOnce();
|
|
SendFinish("r_seed");
|
|
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);
|
|
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();
|
|
}
|
|
};
|
|
|
|
TEST_F(LoadBackViaCacheTestSuite, LoadBack_TriggeredAfterPrefetchPopulatesHostCache) {
|
|
SetupHostCache();
|
|
|
|
Submit(MakeRequestSpec("r1", /*num_pages=*/2, /*start=*/1));
|
|
auto plan = PlanOnce();
|
|
auto lb = ExtractCacheOpsOfKind<FlatLoadBackOperation>(plan);
|
|
|
|
bool r1_in_forward = false;
|
|
for (const auto& op : plan.Operations()) {
|
|
if (auto* fwd = std::get_if<FlatForwardOperation>(&op)) {
|
|
for (const auto& rid : fwd->request_ids) {
|
|
if (rid == "r1") r1_in_forward = true;
|
|
}
|
|
}
|
|
}
|
|
EXPECT_TRUE(r1_in_forward || !lb.empty())
|
|
<< "host cache hit should trigger LoadBack inline or r1 should be in forward";
|
|
}
|
|
|
|
TEST_F(SchedulerTestSuite, LoadBack_NotTriggeredWithoutHostCacheHit) {
|
|
Submit(MakeRequestSpec("r1", 4));
|
|
auto plan = PlanOnce();
|
|
auto lb = ExtractCacheOpsOfKind<FlatLoadBackOperation>(plan);
|
|
EXPECT_TRUE(lb.empty());
|
|
}
|
|
|
|
TEST_F(SchedulerTestSuite, NoCacheOps_WhenNoRequests) {
|
|
auto plan = PlanOnce();
|
|
auto cache_ops = ExtractCacheOps(plan);
|
|
EXPECT_TRUE(cache_ops.empty());
|
|
}
|
|
|
|
TEST_F(SchedulerTestSuite, NoCacheOps_PlainRequestNoCacheHit) {
|
|
Submit(MakeRequestSpec("r1", 2));
|
|
auto plan = PlanOnce();
|
|
auto cache_ops = ExtractCacheOps(plan);
|
|
EXPECT_TRUE(cache_ops.empty());
|
|
}
|
|
|
|
class DisablePrefixCacheTestSuite : public SchedulerTestSuite {
|
|
protected:
|
|
SchedulerConfig MakeConfig() override {
|
|
auto cfg = SchedulerTestSuite::MakeConfig();
|
|
cfg.disable_prefix_cache = true;
|
|
return cfg;
|
|
}
|
|
};
|
|
|
|
TEST_F(DisablePrefixCacheTestSuite, SamePromptDoesNotReuseDevicePrefix) {
|
|
Submit(MakeRequestSpec("r_seed", 2));
|
|
PlanOnce();
|
|
SendForwardDone("r_seed", {100});
|
|
PlanOnce();
|
|
SendFinish("r_seed");
|
|
PlanOnce();
|
|
|
|
Submit(MakeRequestSpec("r1", 2));
|
|
auto plan = PlanOnce();
|
|
const auto& op = plan.Operations()[0];
|
|
auto* fwd = std::get_if<FlatForwardOperation>(&op);
|
|
ASSERT_NE(fwd, nullptr);
|
|
ASSERT_EQ(fwd->request_ids.size(), 1u);
|
|
EXPECT_EQ(fwd->request_ids[0], "r1");
|
|
EXPECT_EQ(fwd->extend_prefix_lens[0], 0);
|
|
EXPECT_EQ(fwd->input_lengths[0], 4);
|
|
EXPECT_TRUE(ExtractCacheOpsOfKind<FlatLoadBackOperation>(plan).empty());
|
|
}
|
|
|
|
TEST_F(DisablePrefixCacheTestSuite, PrefetchNotGeneratedForStorageHit) {
|
|
Submit(MakePrefetchableSpec("r1", 8, 6));
|
|
auto plan = PlanOnce();
|
|
EXPECT_TRUE(ExtractCacheOpsOfKind<PrefetchOperation>(plan).empty());
|
|
}
|
|
|
|
class StableCandidateOrderingSuite : public SchedulerTestSuite {
|
|
protected:
|
|
SchedulerConfig MakeConfig() override {
|
|
auto cfg = SchedulerTestSuite::MakeConfig();
|
|
// Force the candidates loop to break after exactly one push so the
|
|
// tiebreaker decides which request wins.
|
|
cfg.max_batch_size = 1;
|
|
return cfg;
|
|
}
|
|
};
|
|
|
|
TEST_F(StableCandidateOrderingSuite, NewForwardOperationTieBreaksOnRequestId) {
|
|
// TP-determinism regression: requests_ is unordered_map<string, ...> so
|
|
// candidates are visited in per-process random order. Without an Id()
|
|
// tiebreaker in newForwardOperation's sort, each rank picks a different
|
|
// request when the loop budget admits only a subset — making forward_op
|
|
// None on some ranks and non-None on others, which deadlocks NCCL.
|
|
Submit(MakeRequestSpec("r_ccc", 2, 300));
|
|
Submit(MakeRequestSpec("r_aaa", 2, 100));
|
|
Submit(MakeRequestSpec("r_bbb", 2, 200));
|
|
auto plan = PlanOnce();
|
|
std::vector<std::string> ids;
|
|
for (const auto& op : plan.Operations()) {
|
|
if (auto* fwd = std::get_if<FlatForwardOperation>(&op)) {
|
|
ids = fwd->request_ids;
|
|
}
|
|
}
|
|
ASSERT_EQ(ids.size(), 1u);
|
|
EXPECT_EQ(ids[0], "r_aaa");
|
|
}
|
|
|
|
TEST_F(StableCandidateOrderingSuite, ForwardOpIsInsertionOrderIndependent) {
|
|
// Mirror of the above using two scheduler instances fed the same request
|
|
// set in opposite submit orders. The chosen forward request must depend
|
|
// only on the SET of request ids, not the submission sequence.
|
|
Submit(MakeRequestSpec("r_ccc", 2, 300));
|
|
Submit(MakeRequestSpec("r_aaa", 2, 100));
|
|
Submit(MakeRequestSpec("r_bbb", 2, 200));
|
|
auto plan_a = PlanOnce();
|
|
std::vector<std::string> ids_a;
|
|
for (const auto& op : plan_a.Operations()) {
|
|
if (auto* fwd = std::get_if<FlatForwardOperation>(&op)) {
|
|
ids_a = fwd->request_ids;
|
|
}
|
|
}
|
|
|
|
scheduler_ = std::make_unique<Scheduler>(config_);
|
|
Submit(MakeRequestSpec("r_bbb", 2, 200));
|
|
Submit(MakeRequestSpec("r_ccc", 2, 300));
|
|
Submit(MakeRequestSpec("r_aaa", 2, 100));
|
|
auto plan_b = PlanOnce();
|
|
std::vector<std::string> ids_b;
|
|
for (const auto& op : plan_b.Operations()) {
|
|
if (auto* fwd = std::get_if<FlatForwardOperation>(&op)) {
|
|
ids_b = fwd->request_ids;
|
|
}
|
|
}
|
|
|
|
ASSERT_FALSE(ids_a.empty());
|
|
EXPECT_EQ(ids_a, ids_b);
|
|
}
|
|
|
|
} // namespace tokenspeed::test
|