Archived
abi: a request's words for the plugin (RadBatch::plugin_words), ABI 32
This commit is contained in:
1 parent
d60da58732
commit
5a2732f063
15 files changed
+207
-8
No files matched your search
+1
-1
@@ -17,7 +17,7 @@ extern "C" {
|
||||
* rad_spechub.h. Every kind of plugin reports it, and a plugin that does not report exactly this
|
||||
* version is refused at load with both versions printed. A new optional export (e.g.
|
||||
* rad_plugin_reference) is not a change of shape: a plugin without it gets the default. */
|
||||
#define RAD_ABI_VERSION 31u
|
||||
#define RAD_ABI_VERSION 32u
|
||||
|
||||
/* ================================================================== plugin identity */
|
||||
/* One value per plugin, not flags (QUANT is 3). RAD_PLUGIN_QUANT is a quantiser plugin:
|
||||
|
||||
@@ -678,6 +678,11 @@ int rad_declare_logits(RadBuilder* b, rad_buf logits);
|
||||
* this or logits, never both. */
|
||||
int rad_declare_pooled(RadBuilder* b, rad_buf pooled);
|
||||
|
||||
/* The most integer words one request may hand the plugin (RadBatch::plugin_words), 0 for none.
|
||||
* The engine stages that many a sequence in the step batch and refuses a longer request before
|
||||
* it is admitted, so the plugin reads its words at the size it declared. Additive export. */
|
||||
int rad_declare_plugin_words(RadBuilder* b, int64_t max_words);
|
||||
|
||||
|
||||
/* ================================================================== the drafter */
|
||||
/* The plugin's draft head. The core drives the extra passes, and only the plugin knows what it
|
||||
|
||||
@@ -290,6 +290,26 @@ typedef struct RadBatch {
|
||||
* position tables per grid) reads them here; they live as long as the pass. */
|
||||
const int32_t* enc_seg_h;
|
||||
const int32_t* enc_seg_w;
|
||||
|
||||
/* ---- appended in ABI 32 (a request's words for the plugin) */
|
||||
/* Integer words a request hands the plugin whole (Request::plugin_words), for a head that
|
||||
* needs more of a request than its tokens: clef's joint schema head reads the prompt's
|
||||
* question and option spans and the option tokens (abi/rad_clef.h). Sequence s's words are
|
||||
* `plugin_words[plugin_cu[s] .. plugin_cu[s+1])`; a sequence with none has an empty range.
|
||||
* The engine writes the sequence's first sampled logits row of this step into word 0 of its
|
||||
* range, so the head can put its result beside that row's logits; the words after it are the
|
||||
* request's own. Carried only on the trunk step that samples a prompt's first token, so a
|
||||
* head runs once a request, when every prompt row has been computed.
|
||||
*
|
||||
* `plugin_words_h` and `plugin_cu_h` are the same words on the host, for a plugin that reads
|
||||
* counts before it issues; they live as long as the pass. All null, with `n_plugin_words`
|
||||
* 0, on a step no sequence of which carries words, and on every step of a program that
|
||||
* declared none (rad_declare_plugin_words). */
|
||||
int64_t n_plugin_words;
|
||||
const int32_t* plugin_words; /* [n_plugin_words] device */
|
||||
const int32_t* plugin_cu; /* [n_seq + 1] device */
|
||||
const int32_t* plugin_words_h;
|
||||
const int32_t* plugin_cu_h;
|
||||
} RadBatch;
|
||||
|
||||
/* What a generator pass carries beside the step batch's own fields, which keep their meanings:
|
||||
|
||||
@@ -124,6 +124,7 @@ public:
|
||||
int decl_name_map(const RadNameMap* m);
|
||||
int declare_logits(rad_buf b);
|
||||
int declare_pooled(rad_buf b);
|
||||
int declare_plugin_words(int64_t max_words);
|
||||
int declare_drafter(const RadDrafterDecl* d);
|
||||
int drafter_shared_kv(int pos_offset);
|
||||
int lora_root(const char* native, const char* spellings);
|
||||
|
||||
@@ -1219,6 +1219,19 @@ int Builder::declare_pooled(rad_buf b) {
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
/* The words a request may hand the plugin (rad_declare_plugin_words). A bound, not a buffer: the
|
||||
* batch builder stages them per sequence beside the step's other arrays. */
|
||||
int Builder::declare_plugin_words(int64_t max_words) {
|
||||
if (finished_) { err(RAD_E_STATE, "declare_plugin_words after declare finished"); return RAD_E_STATE; }
|
||||
if (max_words < 0 || max_words > (1 << 20)) {
|
||||
err(RAD_E_INVAL, "declare_plugin_words: %lld words a request; the bound is 0 to %d",
|
||||
(long long)max_words, 1 << 20);
|
||||
return RAD_E_INVAL;
|
||||
}
|
||||
prog_.plugin_words = max_words;
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
/* Validates the encoder at declare: it runs only when a request carries media, so a bad
|
||||
* declaration would otherwise surface on the first image as an out-of-bounds pass.
|
||||
*
|
||||
@@ -2591,6 +2604,11 @@ int rad_declare_pooled(RadBuilder* b, rad_buf pooled) {
|
||||
return B(b)->declare_pooled(pooled);
|
||||
}
|
||||
|
||||
int rad_declare_plugin_words(RadBuilder* b, int64_t max_words) {
|
||||
if (!b) return RAD_E_INVAL;
|
||||
return B(b)->declare_plugin_words(max_words);
|
||||
}
|
||||
|
||||
int rad_declare_drafter(RadBuilder* b, const RadDrafterDecl* d) {
|
||||
if (!b) return RAD_E_INVAL;
|
||||
return B(b)->declare_drafter(d);
|
||||
|
||||
@@ -370,6 +370,9 @@ public:
|
||||
/* The step's pooled vectors (rad_declare_pooled): set only by an embedding program, which has
|
||||
* no logits buffer. */
|
||||
rad_buf pooled_buf = 0;
|
||||
/* The most words one request hands the plugin (rad_declare_plugin_words,
|
||||
* RadBatch::plugin_words); 0 when the plugin reads none. */
|
||||
int64_t plugin_words = 0;
|
||||
|
||||
/* Runtime LoRA (core/lora/), empty unless the engine was started with adapters enabled. */
|
||||
std::vector<LoraIssueSite> lora_sites;
|
||||
@@ -744,6 +747,12 @@ struct Request {
|
||||
* The request still samples the one token max_tokens allows; the caller discards it. */
|
||||
std::shared_ptr<TokenScores> token_scores;
|
||||
|
||||
/* Words the plugin reads on the step that samples the prompt's first token
|
||||
* (RadBatch::plugin_words): word 0 is the engine's, the rest the caller's. At most
|
||||
* Program::plugin_words of them, which the server checks before submission; clef's are laid
|
||||
* out by abi/rad_clef.h. Empty for every other request. */
|
||||
std::vector<int32_t> plugin_words;
|
||||
|
||||
/* An embedding request: the whole prompt in one step, never split (a bidirectional encoder
|
||||
* cannot take half its input), finished at that step with its pooled vector in the sink
|
||||
* (Sink::embedding). Nothing is generated. Only an embedding program (rad_declare_pooled)
|
||||
|
||||
@@ -929,7 +929,7 @@ int Ctx::lane_join(int from, int to) {
|
||||
* field added to RadBatch changes its size: decide whether the key must read it, then update the
|
||||
* size here. `agen_b` and `vgen_b` are set only on generator passes, which are never recorded
|
||||
* (below). */
|
||||
static_assert(sizeof(void*) != 8 || sizeof(RadBatch) == 360,
|
||||
static_assert(sizeof(void*) != 8 || sizeof(RadBatch) == 400,
|
||||
"RadBatch changed: check that Ctx::pass_key reads every new field a pass depends on");
|
||||
static_assert(sizeof(void*) != 8 || sizeof(RadKVGroupBatch) == 80,
|
||||
"RadKVGroupBatch changed: check that Ctx::pass_key reads every new field");
|
||||
@@ -938,6 +938,10 @@ uint64_t Ctx::pass_key(const RadBatch* b) const {
|
||||
/* Not recordable: encoder passes are shaped by their media, and passes carrying encoder rows
|
||||
* issue the scatter only when they have some. */
|
||||
if (b->enc || b->n_mm_rows > 0) return 0;
|
||||
/* A pass carrying a request's words for the plugin is shaped by them (a head issues per
|
||||
* sequence from their counts), and such a step samples a prompt's first token, which is not
|
||||
* the repeating decode pass. */
|
||||
if (b->n_plugin_words > 0) return 0;
|
||||
/* A generator pass is shaped by what RadBatch::gen_b, agen_b or vgen_b carries, which no key
|
||||
* below reads. */
|
||||
if (b->gen) return 0;
|
||||
|
||||
@@ -136,6 +136,9 @@ void BatchBuilder::carve(Set& s, char* h) {
|
||||
/* Each row's adapter slot, carved only when the engine serves adapters, so an engine without
|
||||
* them lays the slab out as if the array did not exist. */
|
||||
pair(&s.h_lora, &s.d_lora, lora_on_ ? T : 0);
|
||||
/* Each sequence's words for the plugin, carved only when the program declared a bound. */
|
||||
pair(&s.h_pw, &s.d_pw, pw_cap_ ? S * pw_cap_ : 0);
|
||||
pair(&s.h_pwcu, &s.d_pwcu, pw_cap_ ? S + 1 : 0);
|
||||
/* Host-only (derived metadata is copied into the planned arena), but carved on both sides to
|
||||
* keep device offsets equal to host offsets. */
|
||||
{
|
||||
@@ -473,6 +476,7 @@ int BatchBuilder::layout(Program& prog, const Config& cfg) {
|
||||
|
||||
mm_on_ = prog.encoder.modalities != 0 || prog.audio_encoder.modalities != 0;
|
||||
lora_on_ = cfg.lora.enabled();
|
||||
pw_cap_ = prog.plugin_words;
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
@@ -931,6 +935,8 @@ const RadBatch* BatchBuilder::build(const StepPlan& plan, const IKVManager& kv,
|
||||
int64_t n_mm = 0;
|
||||
bool lora_rows = false;
|
||||
int32_t cvec_rows = 0;
|
||||
int64_t n_pw = 0;
|
||||
if (pw_cap_) s.h_pwcu[0] = 0;
|
||||
s.h_cu[0] = 0;
|
||||
for (int64_t i = 0; i < n_seq; ++i) {
|
||||
const StepEntry& e = plan.e[(size_t)i];
|
||||
@@ -1007,9 +1013,25 @@ const RadBatch* BatchBuilder::build(const StepPlan& plan, const IKVManager& kv,
|
||||
const int32_t nr = e.hidden_n > 0 ? e.hidden_n : e.n_tokens;
|
||||
for (int32_t j = 0; j < nr; ++j) s.h_out[n_out++] = e.hidden_row + j;
|
||||
} else if (e.produces_token) {
|
||||
/* The request's words for the plugin ride the trunk step that samples its prompt's
|
||||
* first token (RadBatch::plugin_words); word 0 is that row's index in `out_ids`. */
|
||||
if (pw_cap_ && e.is_prefill && plan.draft_pass == 0 && e.req &&
|
||||
!e.req->plugin_words.empty()) {
|
||||
const std::vector<int32_t>& w = e.req->plugin_words;
|
||||
if ((int64_t)w.size() > pw_cap_) {
|
||||
RAD_ERR("step batch: sequence %llu carries %zu words for the plugin, past the "
|
||||
"%lld it declared", (unsigned long long)e.seq, w.size(),
|
||||
(long long)pw_cap_);
|
||||
return nullptr;
|
||||
}
|
||||
std::memcpy(s.h_pw + n_pw, w.data(), w.size() * sizeof(int32_t));
|
||||
s.h_pw[n_pw] = (int32_t)n_out;
|
||||
n_pw += (int64_t)w.size();
|
||||
}
|
||||
const int32_t first = (int32_t)(k + e.n_tokens) - 1 - e.n_spec;
|
||||
for (int32_t j = 0; j <= e.n_spec; ++j) s.h_out[n_out++] = first + j;
|
||||
}
|
||||
if (pw_cap_) s.h_pwcu[i + 1] = (int32_t)n_pw;
|
||||
if (e.draft_out) s.h_dout[n_dout++] = (int32_t)(k + e.n_tokens - 1);
|
||||
/* RADIANCE_DFLASH_TRACE logs each drafter pass's kind, positions and token ids. A wrong
|
||||
* anchor, mask id or position base shows only as near-zero acceptance with correct
|
||||
@@ -1176,6 +1198,11 @@ const RadBatch* BatchBuilder::build(const StepPlan& plan, const IKVManager& kv,
|
||||
* runs the same pass as an engine serving no adapters. */
|
||||
B.lora_slot = lora_rows ? on_rank(base, b0, s.d_lora) : nullptr;
|
||||
B.control_vector = cvec_rows;
|
||||
B.n_plugin_words = n_pw;
|
||||
B.plugin_words = n_pw ? on_rank(base, b0, s.d_pw) : nullptr;
|
||||
B.plugin_cu = n_pw ? on_rank(base, b0, s.d_pwcu) : nullptr;
|
||||
B.plugin_words_h = n_pw ? s.h_pw : nullptr;
|
||||
B.plugin_cu_h = n_pw ? s.h_pwcu : nullptr;
|
||||
B.enc = 0;
|
||||
B.enc_n_patch = 0;
|
||||
B.enc_pixels = nullptr;
|
||||
|
||||
@@ -220,6 +220,10 @@ private:
|
||||
/* [n_tok] each row's runtime LoRA adapter slot (RadBatch::lora_slot): carved only when the
|
||||
* engine serves adapters, empty otherwise. */
|
||||
int32_t *h_lora = nullptr, *d_lora = nullptr;
|
||||
/* [max_seqs * plugin_words] and [max_seqs + 1]: each sequence's words for the plugin
|
||||
* (RadBatch::plugin_words), carved only when the program declared a bound. */
|
||||
int32_t *h_pw = nullptr, *d_pw = nullptr;
|
||||
int32_t *h_pwcu = nullptr, *d_pwcu = nullptr;
|
||||
/* [n_kv_groups][max_seqs]: every conv group's state slot per sequence (see init()). */
|
||||
int32_t* h_convslot = nullptr;
|
||||
|
||||
@@ -329,6 +333,8 @@ private:
|
||||
bool mm_on_ = false;
|
||||
/* The engine serves runtime LoRA adapters (Config::lora): the batch carries each row's slot. */
|
||||
bool lora_on_ = false;
|
||||
/* Program::plugin_words: the words a sequence may carry, 0 for none. */
|
||||
int64_t pw_cap_ = 0;
|
||||
int64_t n_embd_ = 0;
|
||||
std::vector<void*> mm_dev_;
|
||||
uint16_t* mm_host_ = nullptr;
|
||||
|
||||
@@ -83,6 +83,11 @@ 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, n_plugin_words)
|
||||
ABI_FIELD(RadBatch, plugin_words)
|
||||
ABI_FIELD(RadBatch, plugin_cu)
|
||||
ABI_FIELD(RadBatch, plugin_words_h)
|
||||
ABI_FIELD(RadBatch, plugin_cu_h)
|
||||
ABI_STRUCT(RadBufDecl)
|
||||
ABI_FIELD(RadBufDecl, dtype)
|
||||
ABI_FIELD(RadBufDecl, rank)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* abi_layout_table.h -- every abi/ struct's size and field offsets at RAD_ABI_VERSION 31 and
|
||||
/* abi_layout_table.h -- every abi/ struct's size and field offsets at RAD_ABI_VERSION 32 and
|
||||
* RAD_FORMAT_VER 2, as { type, field, offset, size } rows ("" is the struct itself). A snapshot
|
||||
* of the headers on x86-64 Linux, which abi_layout_test.cpp holds the layout to; regenerate it
|
||||
* from the test's printout only together with a version bump. */
|
||||
@@ -29,7 +29,7 @@
|
||||
{ "RadArgs", "instance", 48, 8 },
|
||||
{ "RadArgs", "rank", 56, 4 },
|
||||
{ "RadArgs", "world_size", 60, 4 },
|
||||
{ "RadBatch", "", 0, 360 },
|
||||
{ "RadBatch", "", 0, 400 },
|
||||
{ "RadBatch", "phase", 0, 4 },
|
||||
{ "RadBatch", "step", 4, 4 },
|
||||
{ "RadBatch", "n_tok", 8, 8 },
|
||||
@@ -80,6 +80,11 @@
|
||||
{ "RadBatch", "control_vector", 336, 4 },
|
||||
{ "RadBatch", "enc_seg_h", 344, 8 },
|
||||
{ "RadBatch", "enc_seg_w", 352, 8 },
|
||||
{ "RadBatch", "n_plugin_words", 360, 8 },
|
||||
{ "RadBatch", "plugin_words", 368, 8 },
|
||||
{ "RadBatch", "plugin_cu", 376, 8 },
|
||||
{ "RadBatch", "plugin_words_h", 384, 8 },
|
||||
{ "RadBatch", "plugin_cu_h", 392, 8 },
|
||||
{ "RadBufDecl", "", 0, 80 },
|
||||
{ "RadBufDecl", "dtype", 0, 4 },
|
||||
{ "RadBufDecl", "rank", 4, 4 },
|
||||
@@ -215,7 +220,7 @@
|
||||
{ "RadAudioFormat", "language_lead", 48, 8 },
|
||||
{ "RadAudioFormat", "languages", 56, 8 },
|
||||
{ "RadAudioFormat", "n_languages", 64, 4 },
|
||||
{ "RadChatFormat", "", 0, 200 },
|
||||
{ "RadChatFormat", "", 0, 208 },
|
||||
{ "RadChatFormat", "struct_size", 0, 4 },
|
||||
{ "RadChatFormat", "name", 8, 8 },
|
||||
{ "RadChatFormat", "reasoning_open", 16, 8 },
|
||||
@@ -245,6 +250,7 @@
|
||||
{ "RadChatFormat", "object_string_close", 184, 8 },
|
||||
{ "RadChatFormat", "object_bare_keys", 192, 4 },
|
||||
{ "RadChatFormat", "reasoning_anywhere", 196, 4 },
|
||||
{ "RadChatFormat", "arg_json_value_prefix", 200, 8 },
|
||||
{ "RadConstraint", "", 0, 32 },
|
||||
{ "RadConstraint", "key", 0, 8 },
|
||||
{ "RadConstraint", "op", 8, 4 },
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
* Checked: a C translation unit (abi_c_test.c, strict C11) lays every struct out as C++ does; every
|
||||
* struct's listed fields account for its size, so the list in abi_layout_rows.h is complete; and
|
||||
* the layout agrees with the table below, taken at RAD_ABI_VERSION 31 and RAD_FORMAT_VER 2. Under
|
||||
* the layout agrees with the table below, taken at RAD_ABI_VERSION 32 and RAD_FORMAT_VER 2. Under
|
||||
* those versions a listed field may not move or change size, an ABI struct may only grow by fields
|
||||
* past its old end, and an on-disk struct may not change at all. The table is a snapshot of the
|
||||
* headers: nothing else states the layout. When it disagrees the test prints the live table.
|
||||
@@ -58,8 +58,8 @@ std::vector<Row> cpp_rows() {
|
||||
};
|
||||
}
|
||||
|
||||
/* The layout at RAD_ABI_VERSION 31 / RAD_FORMAT_VER 2 (see the file header). */
|
||||
constexpr uint32_t kTableAbi = 31, kTableFormat = 2;
|
||||
/* The layout at RAD_ABI_VERSION 32 / RAD_FORMAT_VER 2 (see the file header). */
|
||||
constexpr uint32_t kTableAbi = 32, kTableFormat = 2;
|
||||
const AbiRow kTable[] = {
|
||||
#include "abi_layout_table.h"
|
||||
};
|
||||
|
||||
@@ -111,6 +111,8 @@ struct RadBuilder {
|
||||
* output (rad_declare_pooled). */
|
||||
rad_buf logits = 0;
|
||||
rad_buf pooled = 0;
|
||||
/* The words a request may hand the plugin (rad_declare_plugin_words). */
|
||||
int64_t plugin_words = 0;
|
||||
|
||||
/* The draft head's declaration (rad_declare_drafter), and whether it keeps no cache of its
|
||||
* own (rad_drafter_shared_kv) and at which rotary offset. */
|
||||
@@ -294,6 +296,13 @@ extern "C" int rad_declare_pooled(RadBuilder* b, rad_buf pooled) {
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
/* The words a request may hand the plugin, recorded as the core records them. */
|
||||
extern "C" int rad_declare_plugin_words(RadBuilder* b, int64_t max_words) {
|
||||
if (!b || max_words < 0) return RAD_E_INVAL;
|
||||
b->plugin_words = max_words;
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
/* An image generator's declaration, recorded whole; it too excludes logits. */
|
||||
extern "C" int rad_declare_generator(RadBuilder* b, const RadGeneratorDecl* d) {
|
||||
if (!b || !d || !d->image_out || b->logits || b->pooled) return RAD_E_INVAL;
|
||||
|
||||
@@ -1826,6 +1826,19 @@ TEST(a_widened_weight_cannot_also_be_relayouted) {
|
||||
CHECK(any_error(b, "a widening and a relayout"));
|
||||
}
|
||||
|
||||
/* The words a request may hand the plugin are a bound the program records; a negative or absurd
|
||||
* bound is refused, and declaring none leaves it at zero. */
|
||||
TEST(the_plugin_words_bound_is_recorded_and_checked) {
|
||||
NEED_EXTRA(reg)
|
||||
Builder b(reg, make_meta(), make_ctx());
|
||||
CHECK_EQ(b.program().plugin_words, (int64_t)0);
|
||||
CHECK_OK(b.declare_plugin_words(4096));
|
||||
CHECK_EQ(b.program().plugin_words, (int64_t)4096);
|
||||
CHECK(b.declare_plugin_words(-1) < 0);
|
||||
CHECK(b.declare_plugin_words((int64_t)1 << 21) < 0);
|
||||
CHECK_EQ(b.program().plugin_words, (int64_t)4096);
|
||||
}
|
||||
|
||||
/* The other direction, the d3 readout: an f32 checkpoint tensor declared bf16 (what the device
|
||||
* logits kernel reads) is narrowed by the loader, and the stored form is one plain bf16 plane. */
|
||||
TEST(an_f32_source_declared_bf16_is_narrowed_at_load) {
|
||||
|
||||
@@ -3498,6 +3498,82 @@ TEST(a_two_rank_batch_rebases_stream_maps_into_each_ranks_pool_and_shares_the_mi
|
||||
bb.fini();
|
||||
}
|
||||
|
||||
/* A request's words for the plugin (Request::plugin_words) ride the prefill step that samples
|
||||
* its first token, with that row's index in word 0; a sequence without words, or one not at that
|
||||
* step, has an empty range. A request past the declared bound fails the build. */
|
||||
TEST(a_requests_plugin_words_ride_the_step_that_samples_its_first_token) {
|
||||
Fixture f;
|
||||
f.build();
|
||||
f.prog.plugin_words = 8;
|
||||
ChunkGeometry geo;
|
||||
CHECK_OK(chunk_geometry_resolve(f.prog, f.cfg, &geo));
|
||||
KVGeom kvg = KVGeom::of(f.prog.kv_groups);
|
||||
for (size_t i = 0; i < kvg.g.size(); ++i) {
|
||||
const int64_t w = f.kv.state_index_width((int32_t)i);
|
||||
if (w > 0) kvg.g[i].sidx_width = w;
|
||||
}
|
||||
BatchBuilder bb;
|
||||
std::vector<BatchBuilder::RankIO> rio;
|
||||
rio.push_back({ 0, nullptr, &f.prog });
|
||||
CHECK_OK(bb.init(f.prog, f.cfg, geo, kvg, rio));
|
||||
for (uint64_t id = 1; id <= 3; ++id) {
|
||||
CHECK_OK(f.kv.add_sequence(id));
|
||||
CHECK_OK(f.kv.ensure(id, 80));
|
||||
}
|
||||
Request r1, r2, r3;
|
||||
r1.prompt.assign(8, 1);
|
||||
r2.prompt.assign(8, 1);
|
||||
r2.plugin_words = { 0, 7, 8, 9 };
|
||||
r3.prompt.assign(8, 1);
|
||||
r3.plugin_words = { 0, 5 };
|
||||
|
||||
StepPlan p;
|
||||
p.reset();
|
||||
auto entry = [&](uint64_t id, const Request* r, bool last) {
|
||||
StepEntry e;
|
||||
e.seq = id;
|
||||
e.card = (int32_t)id - 1;
|
||||
e.req = r;
|
||||
e.n_tokens = 8;
|
||||
e.ctx_len = 0;
|
||||
e.is_prefill = true;
|
||||
e.produces_token = last;
|
||||
p.e.push_back(e);
|
||||
p.n_tok += 8;
|
||||
};
|
||||
entry(1, &r1, true); /* no words */
|
||||
entry(2, &r2, true); /* words, sampled this step */
|
||||
entry(3, &r3, false); /* words, but a mid-prompt chunk */
|
||||
const RadBatch* b = bb.build(p, f.kv, 0);
|
||||
REQUIRE(b != nullptr);
|
||||
CHECK_EQ(b->n_plugin_words, (int64_t)4);
|
||||
REQUIRE(b->plugin_cu_h != nullptr);
|
||||
CHECK_EQ(b->plugin_cu_h[0], 0);
|
||||
CHECK_EQ(b->plugin_cu_h[1], 0);
|
||||
CHECK_EQ(b->plugin_cu_h[2], 4);
|
||||
CHECK_EQ(b->plugin_cu_h[3], 4);
|
||||
/* Sequence 1 took logits row 0, so sequence 2's words open with row 1. */
|
||||
CHECK_EQ(b->plugin_words_h[0], 1);
|
||||
CHECK_EQ(b->plugin_words_h[1], 7);
|
||||
CHECK_EQ(b->plugin_words_h[3], 9);
|
||||
CHECK(b->plugin_words != nullptr && b->plugin_cu != nullptr);
|
||||
|
||||
/* No sequence carries words: every field is null. */
|
||||
p.reset();
|
||||
entry(1, &r1, true);
|
||||
b = bb.build(p, f.kv, 1);
|
||||
REQUIRE(b != nullptr);
|
||||
CHECK_EQ(b->n_plugin_words, (int64_t)0);
|
||||
CHECK(b->plugin_words == nullptr && b->plugin_cu_h == nullptr);
|
||||
|
||||
/* Past the bound: the build fails rather than overrun the slab. */
|
||||
r3.plugin_words.assign(9, 0);
|
||||
p.reset();
|
||||
entry(3, &r3, true);
|
||||
CHECK(bb.build(p, f.kv, 2) == nullptr);
|
||||
bb.fini();
|
||||
}
|
||||
|
||||
/* A sequence that leaves a row and returns to it is restaged whole. Its change marks are taken
|
||||
* wherever it is written, so the old row's copy goes stale; restaging only later changes would
|
||||
* keep entries a rollback replaced earlier. The scheduler's own passes reorder rows, so this
|
||||
|
||||
Reference in new issue
Block a user