abi: a request's words for the plugin (RadBatch::plugin_words), ABI 32

This commit is contained in:
Brandon Bertelsen committed 2026-10-28 00:33:55 -04:00
1 parent d60da58732
commit 5a2732f063
15 files changed
+207 -8

No files matched your search

+5
View File
@@ -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)
+9 -3
View File
@@ -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 },
+3 -3
View File
@@ -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"
};
+9
View File
@@ -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;
+13
View File
@@ -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) {
+76
View File
@@ -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