Archived
core, abi: scored steps -- rad_declare_scores, RadBatch::score_only, and /v1/systemone's model
A scored request (Request::token_scores, what /v1/systemone asks: the raw logits at a few candidate ids) does not need the half-gigabyte lm_head read the sampler would consume. A plugin whose head is the bf16 embedding table declares the final-normed hidden rows and that table (rad_declare_scores); on a step whose sampled rows are all scored rows and whose program declared both, the core sets RadBatch::score_only, the plugin issues everything but the head, and the core reads the hidden rows and the candidates' table rows back and takes the dot products in f64 on the host. RadBatch gains one trailing int32 (score_only, 360), which the pass key mixes; an older plugin never sees it set. The scheduler issues no step ahead of one that brings a scored row to max_tokens: that forward pass reads nothing and a max_tokens=1 question would pay a decode step after its prefill. Scored rows only -- every other decode keeps the step of overlap it had. /v1/systemone reports which model answered. Co-Authored-By: Pi <pi@localhost>
This commit is contained in:
1 parent
9093bf618e
commit
ed1e5caf9d
16 files changed
+214
-8
No files matched your search
@@ -84,6 +84,7 @@ ABI_FIELD(RadBatch, vgen_b)
|
||||
ABI_FIELD(RadBatch, control_vector)
|
||||
ABI_FIELD(RadBatch, enc_seg_h)
|
||||
ABI_FIELD(RadBatch, enc_seg_w)
|
||||
ABI_FIELD(RadBatch, score_only)
|
||||
ABI_STRUCT(RadBufDecl)
|
||||
ABI_FIELD(RadBufDecl, dtype)
|
||||
ABI_FIELD(RadBufDecl, rank)
|
||||
|
||||
@@ -80,6 +80,7 @@
|
||||
{ "RadBatch", "control_vector", 336, 4 },
|
||||
{ "RadBatch", "enc_seg_h", 344, 8 },
|
||||
{ "RadBatch", "enc_seg_w", 352, 8 },
|
||||
{ "RadBatch", "score_only", 360, 4 },
|
||||
{ "RadBufDecl", "", 0, 80 },
|
||||
{ "RadBufDecl", "dtype", 0, 4 },
|
||||
{ "RadBufDecl", "rank", 4, 4 },
|
||||
|
||||
@@ -86,6 +86,8 @@ struct RecJoin { size_t at = 0; int from = 0, to = 0; };
|
||||
using namespace rad_fake;
|
||||
|
||||
struct RadBuilder {
|
||||
rad_buf score_hidden = 0; /* rad_declare_scores */
|
||||
rad_weight score_table = 0;
|
||||
std::vector<RecWeight> weights;
|
||||
std::vector<RecBuf> bufs;
|
||||
std::vector<RecOp> ops;
|
||||
@@ -289,6 +291,14 @@ extern "C" int rad_declare_logits(RadBuilder* b, rad_buf logits) {
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
/* Scored steps' hidden rows and head table, recorded for the tests. */
|
||||
extern "C" int rad_declare_scores(RadBuilder* b, rad_buf hidden, rad_weight table) {
|
||||
if (!b || !hidden || !table) return RAD_E_INVAL;
|
||||
b->score_hidden = hidden;
|
||||
b->score_table = table;
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
/* An embedding program names its pooled output instead of logits; a program declares one. */
|
||||
extern "C" int rad_declare_pooled(RadBuilder* b, rad_buf pooled) {
|
||||
if (!b || !pooled || b->logits) return RAD_E_INVAL;
|
||||
|
||||
@@ -5843,6 +5843,46 @@ TEST(a_request_finishing_under_a_step_issued_ahead_keeps_its_blocks_for_that_ste
|
||||
CHECK_EQ((int)f.sch.find(a)->output.size(), 2); /* the step ahead emitted nothing */
|
||||
}
|
||||
|
||||
/* A SCORED row (Request::token_scores) the step in flight brings to max_tokens gets no step issued
|
||||
* ahead: it would be a forward pass for a request that finishes at the commit. The step after the
|
||||
* commit is planned as usual, and a decode that is not scored keeps its step of overlap. */
|
||||
TEST(no_step_is_issued_ahead_for_a_scored_request_the_step_in_flight_finishes) {
|
||||
Fixture f;
|
||||
f.build(/*blocks=*/20, /*states=*/64);
|
||||
CHECK_OK(f.start());
|
||||
const int64_t before = f.kv.free_blocks(0);
|
||||
auto r = f.request(40, /*max_tokens=*/2);
|
||||
r->speculation_fixed = true;
|
||||
r->token_scores = std::make_shared<TokenScores>();
|
||||
r->token_scores->tokens = { 1, 2 };
|
||||
const uint64_t a = f.add(std::move(r));
|
||||
REQUIRE(f.sch.step() != nullptr);
|
||||
f.commit_plain();
|
||||
REQUIRE(f.sch.step() != nullptr);
|
||||
CHECK(f.sch.step_next() == nullptr);
|
||||
f.commit_plain(); /* the second token: finished */
|
||||
CHECK_EQ((int)f.sch.find(a)->state, (int)ReqState::Finished);
|
||||
CHECK_EQ(f.kv.free_blocks(0), before);
|
||||
CHECK_EQ((int)f.sch.find(a)->output.size(), 2);
|
||||
CHECK(f.sch.step() == nullptr);
|
||||
}
|
||||
|
||||
/* The same row without token_scores is an ordinary decode: the step ahead is issued, as upstream. */
|
||||
TEST(a_non_scored_row_keeps_the_step_issued_ahead) {
|
||||
Fixture f;
|
||||
f.build(/*blocks=*/20, /*states=*/64);
|
||||
CHECK_OK(f.start());
|
||||
auto r = f.request(40, /*max_tokens=*/2);
|
||||
r->speculation_fixed = true;
|
||||
const uint64_t a = f.add(std::move(r));
|
||||
REQUIRE(f.sch.step() != nullptr);
|
||||
f.commit_plain();
|
||||
REQUIRE(f.sch.step() != nullptr);
|
||||
CHECK(f.sch.step_next() != nullptr);
|
||||
f.commit_plain();
|
||||
CHECK_EQ((int)f.sch.find(a)->output.size(), 2);
|
||||
}
|
||||
|
||||
/* ================================================================== terminal paths */
|
||||
/* A lone request that outgrows the whole pool fails with the reason the client sees and gives its
|
||||
* blocks back; nothing is preempted, since there is nobody to preempt and preempting itself would
|
||||
|
||||
@@ -326,6 +326,7 @@ TEST(the_endpoint_answers_only_for_a_declared_d1) {
|
||||
if (!*type) { CHECK_EQ(res.status, 501); continue; }
|
||||
REQUIRE(res.status == 200);
|
||||
const json j = json::parse(res.body);
|
||||
CHECK_EQ(j["model"].get<std::string>(), "d1");
|
||||
CHECK_NEAR(j["answers"]["q"]["noul"].get<double>(), 0.75, 1e-6);
|
||||
CHECK_EQ(j["answers"]["c"]["choice"].get<std::string>(), "one");
|
||||
CHECK_EQ(j["usage"]["output_tokens"].get<int>(), 0);
|
||||
|
||||
Reference in new issue
Block a user