Archived
engine: the KV plan split, the host mirror, and --kv-resident bring-up
This commit is contained in:
1 parent
cce687bf2c
commit
a9e627b7ca
44 files changed
+3118
-51
No files matched your search
@@ -18,6 +18,7 @@ ABI_FIELD(RadArchProbe, gen_ctx)
|
||||
ABI_FIELD(RadArchProbe, gen_video)
|
||||
ABI_FIELD(RadArchProbe, kv_quant_ok)
|
||||
ABI_FIELD(RadArchProbe, chain_pays)
|
||||
ABI_FIELD(RadArchProbe, kv_stream_ok)
|
||||
ABI_FIELD(RadArchProbe, control_vector_ok)
|
||||
ABI_FIELD(RadArchProbe, tp_attn_rows_ok)
|
||||
ABI_FIELD(RadArchProbe, state_f16_ok)
|
||||
@@ -109,6 +110,8 @@ ABI_FIELD(RadBuildCtx, max_audio_frames)
|
||||
ABI_FIELD(RadBuildCtx, max_mixed_tok)
|
||||
ABI_FIELD(RadBuildCtx, kv_quant)
|
||||
ABI_FIELD(RadBuildCtx, attn_prefill_fp8)
|
||||
ABI_FIELD(RadBuildCtx, kv_resident_blocks)
|
||||
ABI_FIELD(RadBuildCtx, kv_stream_ok)
|
||||
ABI_FIELD(RadBuildCtx, cvec)
|
||||
ABI_FIELD(RadBuildCtx, tp_attn_rows)
|
||||
ABI_FIELD(RadBuildCtx, state_dtype)
|
||||
@@ -476,6 +479,7 @@ ABI_FIELD(RadKVGroupBatch, state_index)
|
||||
ABI_FIELD(RadKVGroupBatch, state_index_pitch)
|
||||
ABI_FIELD(RadKVGroupBatch, block_size)
|
||||
ABI_FIELD(RadKVGroupBatch, max_blocks)
|
||||
ABI_FIELD(RadKVGroupBatch, stream)
|
||||
ABI_STRUCT(RadKVGroupDecl)
|
||||
ABI_FIELD(RadKVGroupDecl, kind)
|
||||
ABI_FIELD(RadKVGroupDecl, dtype)
|
||||
@@ -484,6 +488,16 @@ ABI_FIELD(RadKVGroupDecl, n_head_kv)
|
||||
ABI_FIELD(RadKVGroupDecl, head_dim)
|
||||
ABI_FIELD(RadKVGroupDecl, state_dim)
|
||||
ABI_FIELD(RadKVGroupDecl, conv_width)
|
||||
ABI_STRUCT(RadKVStream)
|
||||
ABI_FIELD(RadKVStream, host)
|
||||
ABI_FIELD(RadKVStream, res)
|
||||
ABI_FIELD(RadKVStream, slot_block)
|
||||
ABI_FIELD(RadKVStream, slot_state)
|
||||
ABI_FIELD(RadKVStream, ctl)
|
||||
ABI_FIELD(RadKVStream, block_bytes)
|
||||
ABI_FIELD(RadKVStream, host_layer_stride)
|
||||
ABI_FIELD(RadKVStream, slots)
|
||||
ABI_FIELD(RadKVStream, host_bytes)
|
||||
ABI_STRUCT(RadKernelInfo)
|
||||
ABI_FIELD(RadKernelInfo, name)
|
||||
ABI_FIELD(RadKernelInfo, op)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* abi_layout_table.h -- every abi/ struct's size and field offsets at RAD_ABI_VERSION 27 and
|
||||
/* abi_layout_table.h -- every abi/ struct's size and field offsets at RAD_ABI_VERSION 30 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. */
|
||||
@@ -15,9 +15,10 @@
|
||||
{ "RadArchProbe", "gen_video", 64, 4 },
|
||||
{ "RadArchProbe", "kv_quant_ok", 68, 4 },
|
||||
{ "RadArchProbe", "chain_pays", 72, 4 },
|
||||
{ "RadArchProbe", "control_vector_ok", 76, 4 },
|
||||
{ "RadArchProbe", "tp_attn_rows_ok", 80, 4 },
|
||||
{ "RadArchProbe", "state_f16_ok", 84, 4 },
|
||||
{ "RadArchProbe", "kv_stream_ok", 76, 4 },
|
||||
{ "RadArchProbe", "control_vector_ok", 80, 4 },
|
||||
{ "RadArchProbe", "tp_attn_rows_ok", 84, 4 },
|
||||
{ "RadArchProbe", "state_f16_ok", 88, 4 },
|
||||
{ "RadArgs", "", 0, 64 },
|
||||
{ "RadArgs", "t", 0, 8 },
|
||||
{ "RadArgs", "n_t", 8, 4 },
|
||||
@@ -106,10 +107,12 @@
|
||||
{ "RadBuildCtx", "max_mixed_tok", 96, 8 },
|
||||
{ "RadBuildCtx", "kv_quant", 104, 4 },
|
||||
{ "RadBuildCtx", "attn_prefill_fp8", 108, 4 },
|
||||
{ "RadBuildCtx", "cvec", 112, 8 },
|
||||
{ "RadBuildCtx", "tp_attn_rows", 120, 4 },
|
||||
{ "RadBuildCtx", "state_dtype", 124, 4 },
|
||||
{ "RadBuildCtx", "draft_coupling", 128, 4 },
|
||||
{ "RadBuildCtx", "kv_resident_blocks", 112, 8 },
|
||||
{ "RadBuildCtx", "kv_stream_ok", 120, 4 },
|
||||
{ "RadBuildCtx", "cvec", 128, 8 },
|
||||
{ "RadBuildCtx", "tp_attn_rows", 136, 4 },
|
||||
{ "RadBuildCtx", "state_dtype", 140, 4 },
|
||||
{ "RadBuildCtx", "draft_coupling", 144, 4 },
|
||||
{ "RadAudioGenBatch", "", 0, 344 },
|
||||
{ "RadAudioGenBatch", "n_lane", 0, 8 },
|
||||
{ "RadAudioGenBatch", "lane", 8, 8 },
|
||||
@@ -463,7 +466,7 @@
|
||||
{ "RadGeneratorDecl", "chunk_bos", 364, 4 },
|
||||
{ "RadGeneratorDecl", "chunk_eos", 368, 4 },
|
||||
{ "RadGeneratorDecl", "cond_opts", 372, 4 },
|
||||
{ "RadKVGroupBatch", "", 0, 72 },
|
||||
{ "RadKVGroupBatch", "", 0, 80 },
|
||||
{ "RadKVGroupBatch", "group", 0, 4 },
|
||||
{ "RadKVGroupBatch", "slot_mapping", 8, 8 },
|
||||
{ "RadKVGroupBatch", "block_table", 16, 8 },
|
||||
@@ -473,6 +476,7 @@
|
||||
{ "RadKVGroupBatch", "state_index_pitch", 48, 8 },
|
||||
{ "RadKVGroupBatch", "block_size", 56, 8 },
|
||||
{ "RadKVGroupBatch", "max_blocks", 64, 8 },
|
||||
{ "RadKVGroupBatch", "stream", 72, 8 },
|
||||
{ "RadKVGroupDecl", "", 0, 56 },
|
||||
{ "RadKVGroupDecl", "kind", 0, 4 },
|
||||
{ "RadKVGroupDecl", "dtype", 4, 4 },
|
||||
@@ -481,6 +485,16 @@
|
||||
{ "RadKVGroupDecl", "head_dim", 24, 8 },
|
||||
{ "RadKVGroupDecl", "state_dim", 32, 16 },
|
||||
{ "RadKVGroupDecl", "conv_width", 48, 8 },
|
||||
{ "RadKVStream", "", 0, 72 },
|
||||
{ "RadKVStream", "host", 0, 8 },
|
||||
{ "RadKVStream", "res", 8, 8 },
|
||||
{ "RadKVStream", "slot_block", 16, 8 },
|
||||
{ "RadKVStream", "slot_state", 24, 8 },
|
||||
{ "RadKVStream", "ctl", 32, 8 },
|
||||
{ "RadKVStream", "block_bytes", 40, 8 },
|
||||
{ "RadKVStream", "host_layer_stride", 48, 8 },
|
||||
{ "RadKVStream", "slots", 56, 8 },
|
||||
{ "RadKVStream", "host_bytes", 64, 8 },
|
||||
{ "RadKernelInfo", "", 0, 168 },
|
||||
{ "RadKernelInfo", "name", 0, 8 },
|
||||
{ "RadKernelInfo", "op", 8, 8 },
|
||||
|
||||
@@ -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 27 and RAD_FORMAT_VER 2. Under
|
||||
* the layout agrees with the table below, taken at RAD_ABI_VERSION 30 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 27 / RAD_FORMAT_VER 2 (see the file header). */
|
||||
constexpr uint32_t kTableAbi = 27, kTableFormat = 2;
|
||||
/* The layout at RAD_ABI_VERSION 30 / RAD_FORMAT_VER 2 (see the file header). */
|
||||
constexpr uint32_t kTableAbi = 30, kTableFormat = 2;
|
||||
const AbiRow kTable[] = {
|
||||
#include "abi_layout_table.h"
|
||||
};
|
||||
|
||||
@@ -429,6 +429,7 @@ const std::map<std::string, std::vector<std::string>>& legal_values() {
|
||||
{ "--max-model-len", { "4096" } }, { "--rope-scaling", { "yarn:4" } },
|
||||
{ "--gpu-headroom-mib", { "128" } }, { "--kv-cache-dtype", { "fp8" } },
|
||||
{ "--state-cache-dtype", { "f16" } }, { "--attn-prefill-fp8", { "both" } },
|
||||
{ "--kv-resident", { "65536" } },
|
||||
{ "--host-pool-mib", { "1024" } }, { "--host-headroom-mib", { "2048" } },
|
||||
{ "--embedding-placement", { "vram" } },
|
||||
{ "--vision-tower-placement", { "ram" } }, { "--ngram-placement", { "disk" } },
|
||||
@@ -726,6 +727,29 @@ TEST(the_kv_cache_dtype_is_one_of_four_names) {
|
||||
CHECK_EQ(d.kv_cache_dtype, std::string("bf16"));
|
||||
}
|
||||
|
||||
/* --kv-resident is the whole switch: absent or 0 and nothing streams, and it is whole tokens
|
||||
* rounded up to the group's page at startup. The mode flag is gone, and a launch line that still
|
||||
* passes it is refused by name rather than silently served without streaming. */
|
||||
TEST(kv_resident_is_the_whole_switch_and_its_ring_is_whole_tokens) {
|
||||
Config d;
|
||||
CHECK_EQ(parse({}, &d), RAD_OK);
|
||||
CHECK_EQ(d.kv_resident, 0ll); /* nothing streams */
|
||||
CHECK(!d.kv_streams); /* derived: no group streams either */
|
||||
for (const char* old : { "auto", "on", "off", "measure" }) {
|
||||
Config c;
|
||||
int st = RAD_OK;
|
||||
const std::string log = stderr_of([&] { st = parse({ "--kv-streaming", old }, &c); });
|
||||
CHECK_EQ(st, (int)RAD_E_INVAL);
|
||||
CHECK(has(log, "--kv-resident")); /* the message names the replacement */
|
||||
}
|
||||
Config c;
|
||||
CHECK_EQ(parse({ "--kv-resident", "262144" }, &c), RAD_OK);
|
||||
CHECK_EQ(c.kv_resident, 262144ll);
|
||||
CHECK_EQ(parse({ "--kv-resident", "0" }, &c), RAD_OK);
|
||||
CHECK_EQ(c.kv_resident, 0ll);
|
||||
CHECK_EQ(parse({ "--kv-resident", "-1" }, &c), RAD_E_INVAL);
|
||||
}
|
||||
|
||||
/* The embedding takes ram (default) or vram; the n-gram table takes auto (default), vram, ram or
|
||||
* disk. The parser records whether the embedding placement was named and leaves resolution to
|
||||
* Engine::plan, which can refuse a placement with the model in hand. */
|
||||
|
||||
@@ -18,6 +18,9 @@
|
||||
#include "runtime/ctx.h"
|
||||
#include "runtime/kvbind.h"
|
||||
#include "mem/kv.h"
|
||||
#include "kvstream/bind.h"
|
||||
#include "kvstream/plan.h"
|
||||
#include "kvstream/stage.h"
|
||||
#include "runtime/rank_barrier.h"
|
||||
#include "runtime/residency.h"
|
||||
#include "runtime/wtab.h"
|
||||
@@ -1676,6 +1679,9 @@ TEST(too_many_operands_or_an_unknown_handle_is_refused) {
|
||||
/* ================================================================== KV operands */
|
||||
namespace {
|
||||
alignas(64) uint16_t g_kv_pool[4 * 2048];
|
||||
/* One layer of a 13-layer group's context: [8 blocks, 2 heads, 4 tokens, 2*4] fp8 = 512 B. A
|
||||
* prefill pool for a streamed group is this deep, not 13 of these. */
|
||||
alignas(64) uint8_t g_alias_pool[8 * 2 * 4 * 2 * 4];
|
||||
|
||||
/* Group 1: full attention over layers 3, 7 and 11, rank 4. Group 2: a conv state, rank 3, over
|
||||
* layer 0. Group 0 is the sentinel every handle table carries, with no pool. */
|
||||
@@ -1782,6 +1788,133 @@ TEST(kv_pools_bind_each_layer_to_its_place_in_the_group) {
|
||||
CHECK_EQ(b[3].layer_slot[2], 0);
|
||||
}
|
||||
|
||||
/* A streamed group's prefill pool is ONE layer deep and every layer of the group addresses it.
|
||||
*
|
||||
* Above `qsa_exact_to` one prefill launch selects 70-100% of the live history (docs/KV-STREAMING.md
|
||||
* §3.5), so a decode-sized ring overflows and the prefill path stages one layer's history into an
|
||||
* identity-layout buffer instead. Layer L is staged into that buffer, read, and then overwritten by
|
||||
* layer L+1, so the buffer is one layer deep rather than `n_layers` deep: 128 MiB at 262K fp8 on
|
||||
* two ranks, against 1.66 GiB.
|
||||
*
|
||||
* The operand resolution accepts it, and the depth is the whole arithmetic: `layer_slot` is a
|
||||
* lookup and the only bound is `off + layer_stride <= bytes` (runtime/issue.cpp:781-789), which a
|
||||
* one-layer-deep pool satisfies at `off == 0` for every layer. This case pins that, pins that an
|
||||
* identity table over the same pool is refused (so the depth is not silently tolerated), and pins
|
||||
* the two facts that make aliasing a *binding* change rather than a hand-built layer table: the
|
||||
* same table is the host mirror's row (`rad_kv_layer_index`, arch/common/rad_arch.h:1028-1032), so
|
||||
* mapping every layer to 0 collapses the mirror; and bind_kv_pools derives the table from each
|
||||
* layer's position in the group, so an aliased table cannot come from it. */
|
||||
TEST(a_streamed_groups_layers_may_all_alias_one_pool_slot) {
|
||||
const int64_t n_blocks = 8, heads = 2, block = 4, hd = 4;
|
||||
const int64_t lbpb = heads * block * 2 * hd; /* one block of ONE layer */
|
||||
const int64_t stride = n_blocks * lbpb; /* one whole layer: the stage's depth */
|
||||
const int64_t shape[4] = { n_blocks, heads, block, 2 * hd };
|
||||
const int64_t st[4] = { heads * block * 2 * hd, block * 2 * hd, 2 * hd, 1 };
|
||||
|
||||
Fixture f;
|
||||
f.kv.assign(2, rad::KVPoolBinding{});
|
||||
rad::KVPoolBinding& alias = f.kv[1];
|
||||
alias.base = g_alias_pool;
|
||||
alias.layer_stride = stride;
|
||||
alias.bytes = stride; /* 13 layers share these bytes */
|
||||
alias.depth = 1; /* every layer resolves to offset 0 */
|
||||
alias.dtype = RAD_F8E4M3;
|
||||
alias.layer_slot.assign(13, 0);
|
||||
for (int l = 0; l < 13; ++l) alias.layer_slot[(size_t)l] = l; /* the MIRROR row */
|
||||
alias.rank = 4;
|
||||
for (int d = 0; d < 4; ++d) alias.shape[d] = shape[d];
|
||||
rad_op op = loose_op(f, "attn_paged");
|
||||
CHECK_OK(f.start());
|
||||
|
||||
/* The recorder keeps eight operands, so the 13 layers go in two issues. Every layer reads the
|
||||
* same pool base because `depth` is 1, and the operand's shape follows the stage view. */
|
||||
for (int first = 0; first < 13; first += 8) {
|
||||
const int last = first + 8 < 13 ? first + 8 : 13;
|
||||
std::vector<RadOperand> some;
|
||||
for (int l = first; l < last; ++l) some.push_back(RAD_KV(1, l));
|
||||
CHECK_OK(issue_once(f, first, op, some));
|
||||
REQUIRE_EQ(g_rec.size(), (size_t)1);
|
||||
REQUIRE_EQ(g_rec[0].n_t, last - first);
|
||||
for (int l = first; l < last; ++l) {
|
||||
const RadTensor& t = g_rec[0].t[l - first];
|
||||
CHECK(t.data == (void*)g_alias_pool);
|
||||
CHECK_EQ((int)t.rank, 4);
|
||||
CHECK_EQ((int)t.dtype, (int)RAD_F8E4M3);
|
||||
for (int d = 0; d < 4; ++d) {
|
||||
CHECK_EQ(t.shape[d], shape[d]);
|
||||
CHECK_EQ(t.stride[d], st[d]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* The mirror's row comes from the same lookup, which is why aliasing has to be a depth of the
|
||||
* binding and not a rewritten layer_slot: with depth 1 every layer would read layer 0's mirror
|
||||
* row. The lookup itself is untouched and still positional. */
|
||||
for (int l = 0; l < 13; ++l) CHECK_EQ(f.ctx.kv_layer_index(1, l), (int64_t)l);
|
||||
|
||||
/* The same one-layer-deep pool with depth 0 is a positional table, and `bytes` is the only
|
||||
* bound: it serves exactly layer 0 and refuses the rest. This is what makes the aliasing a
|
||||
* deliberate depth rather than something issue.cpp silently tolerates. */
|
||||
Fixture g;
|
||||
g.kv.assign(2, rad::KVPoolBinding{});
|
||||
g.kv[1] = alias;
|
||||
g.kv[1].depth = 0;
|
||||
for (int l = 0; l < 13; ++l) g.kv[1].layer_slot[(size_t)l] = l;
|
||||
rad_op op_g = loose_op(g, "attn_paged");
|
||||
CHECK_OK(g.start());
|
||||
refused(g, issue_once(g, 0, op_g, { RAD_KV(1, 1) }), RAD_E_INVAL, "outside the");
|
||||
next_step_clean(g, 1, op_g, { RAD_KV(1, 0) });
|
||||
|
||||
/* The plan's arithmetic: the ring is n_slots blocks of every layer, the stage is the context
|
||||
* one layer deep, and the carve is their maximum, never their sum. */
|
||||
rad::KVGroupPlan p;
|
||||
p.kind = RAD_KV_FULL;
|
||||
p.n_layers = 13;
|
||||
p.n_blocks = n_blocks;
|
||||
p.n_slots = 2; /* a decode-sized ring, smaller than the context */
|
||||
p.depth = 1;
|
||||
p.block_size = block;
|
||||
p.bytes_per_block = 13 * lbpb;
|
||||
CHECK_EQ(p.layer_stride(), 2 * lbpb);
|
||||
CHECK_EQ(p.streamed(), true);
|
||||
CHECK_EQ(p.n_blocks * p.layer_bytes_per_block(), stride); /* one layer, not 13 */
|
||||
CHECK_EQ(rad::kv_ring_bytes(p, 2), 2 * 13 * lbpb);
|
||||
CHECK_EQ(rad::kv_pool_bytes(p), 2 * 13 * lbpb); /* ring wins here */
|
||||
CHECK_EQ(rad::kv_ceiling_bytes(p, 200, 2), 200 * lbpb); /* stage wins at context */
|
||||
CHECK_EQ(rad::kv_tier_cached(p), false);
|
||||
|
||||
/* The engine's own builder places each bound layer at its position in the group and keeps the
|
||||
* pool alias a view, so both views are fixed from bring-up and the ring is active first. */
|
||||
Program P;
|
||||
P.kv_groups.resize(2);
|
||||
P.kv_groups[1].decl.kind = RAD_KV_FULL;
|
||||
P.kv_groups[1].decl.n_head_kv = heads;
|
||||
P.kv_groups[1].decl.head_dim = hd;
|
||||
for (int l = 0; l < 13; ++l) P.kv_groups[1].layers.push_back(l);
|
||||
std::vector<rad::KVGroupPlan> plans(2);
|
||||
plans[1] = p;
|
||||
plans[1].base = g_alias_pool;
|
||||
plans[1].pool_bytes = rad::kv_pool_bytes(p);
|
||||
std::vector<rad::KVPoolBinding> b;
|
||||
rad::bind_kv_pools(P, [&](int32_t x) -> const rad::KVGroupPlan* {
|
||||
return x == 0 ? nullptr : &plans[(size_t)x];
|
||||
}, &b);
|
||||
REQUIRE_EQ(b.size(), (size_t)2);
|
||||
REQUIRE_EQ(b[1].layer_slot.size(), (size_t)13);
|
||||
for (int l = 0; l < 13; ++l) CHECK_EQ(b[1].layer_slot[(size_t)l], l);
|
||||
REQUIRE(b[1].has_stage);
|
||||
CHECK_EQ(b[1].depth, 0); /* the ring is the active view */
|
||||
CHECK_EQ(b[1].layer_stride, 2 * lbpb);
|
||||
CHECK_EQ(b[1].shape[0], 2);
|
||||
CHECK_EQ(b[1].stage.layer_stride, stride);
|
||||
CHECK_EQ(b[1].stage.shape0, n_blocks);
|
||||
rad::kv_binding_enter(b[1], rad::KVView::Stage);
|
||||
CHECK_EQ(b[1].depth, 1);
|
||||
CHECK_EQ(b[1].layer_stride, stride);
|
||||
CHECK_EQ(b[1].shape[0], n_blocks);
|
||||
for (int l = 0; l < 13; ++l) CHECK_EQ(rad::kv_binding_offset(b[1], l), 0);
|
||||
}
|
||||
|
||||
/* ================================================================== arena levels */
|
||||
/* A level packs the transient buffers for smaller steps at new offsets with smaller shapes; the
|
||||
* active level decides every buffer's address and the extent an operand is checked against, so a
|
||||
@@ -2199,6 +2332,67 @@ TEST(the_pass_key_changes_with_the_arena_level) {
|
||||
CHECK_EQ(f.ctx.pass_key(&b), k0);
|
||||
}
|
||||
|
||||
/* A streamed pass's key names the memory its view reads, not the address of the struct that carries
|
||||
* it: the batch's view is a copy in a rotating builder Out slot, so keying on `&view` made every
|
||||
* streamed decode step a pass the tape had never seen, no tape survived the 24-slot LRU, and the
|
||||
* host walked the whole issue path every step (record §55: 25 ms/step, §56 the fix). Two views
|
||||
* with the same bytes must agree, a view that hands a kernel different memory must not, and on a
|
||||
* card the same streamed pass twice must play. The host backend records no tape, so only the key
|
||||
* is checked there. */
|
||||
TEST(a_streamed_pass_is_keyed_by_its_view_and_replays) {
|
||||
Fixture f;
|
||||
rad_buf x = f.add_buffer("x", RAD_BF16, 64, 4, 0);
|
||||
rad_op op = loose_op(f);
|
||||
CHECK_OK(f.start(nullptr, false, /*record=*/true));
|
||||
|
||||
std::vector<int32_t> res(64, -1), sblk(64, -1), sst(128, 0), ctl(16, 0);
|
||||
std::vector<uint8_t> host(1024, 0);
|
||||
RadKVStream view{};
|
||||
view.host = host.data(); view.res = res.data(); view.slot_block = sblk.data();
|
||||
view.slot_state = sst.data(); view.ctl = ctl.data();
|
||||
view.block_bytes = 16; view.host_layer_stride = 1024; view.slots = 64;
|
||||
view.host_bytes = 2048;
|
||||
|
||||
RadKVGroupBatch kg[1]{};
|
||||
f.batch.kv = kg;
|
||||
f.batch.n_kv_groups = 1;
|
||||
f.batch.phase = RAD_PHASE_DECODE;
|
||||
f.batch.n_tok = 1; f.batch.n_seq = 1;
|
||||
|
||||
kg[0].stream = &view;
|
||||
const uint64_t k0 = f.ctx.pass_key(&f.batch);
|
||||
CHECK(k0 != 0);
|
||||
/* The Out slot moves; the bytes a kernel reads do not. */
|
||||
RadKVStream copy = view;
|
||||
kg[0].stream = ©
|
||||
CHECK_EQ(f.ctx.pass_key(&f.batch), k0);
|
||||
/* A different ring or a different map is a different pass. */
|
||||
copy.slots = view.slots + 1;
|
||||
CHECK(f.ctx.pass_key(&f.batch) != k0);
|
||||
copy = view;
|
||||
copy.res = res.data() + 1;
|
||||
CHECK(f.ctx.pass_key(&f.batch) != k0);
|
||||
|
||||
kg[0].stream = &view;
|
||||
const auto body = [&](Ctx& c) {
|
||||
const RadOperand o[1] = { RAD_B(x) };
|
||||
CHECK_OK(c.issue(op, o, 1, RAD_N_BATCH));
|
||||
};
|
||||
/* First sighting records, the second is the audit every recording gets before its first play,
|
||||
* the third is the play. A key that moved each step would never get past the first. */
|
||||
/* The first pass settles the runtime state the key also names (the host-touch and scratch
|
||||
* flags a pass leaves behind), then: one sighting records, the next is the audit every
|
||||
* recording gets before its first play, the third is the play. A key that moved with the view
|
||||
* slot would never get past the first. */
|
||||
for (int i = 0; i < 4; ++i) CHECK_OK(f.step(1, i, body));
|
||||
if (f.ctx.records_passes()) {
|
||||
const Ctx::PassCounts pc = f.ctx.pass_counts();
|
||||
CHECK(pc.recorded > 0);
|
||||
CHECK(pc.audited > 0);
|
||||
CHECK(pc.played > 0); /* the streamed pass replayed, not reissued */
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================== the op oracle */
|
||||
namespace {
|
||||
std::string radiance_home() {
|
||||
|
||||
@@ -339,6 +339,14 @@ struct FakeKV : IKVManager {
|
||||
const KVGeom::G& gg = geom.g[(size_t)g];
|
||||
return gg.paged ? gg.block_size : 0;
|
||||
}
|
||||
/* A streamed group's view, as KVManager::stream_view returns it. Tests install fake
|
||||
* addresses to check that the builder rebases them into each rank's pool; with `streams`
|
||||
* false the fake has none, which is every other scheduler test. */
|
||||
RadKVStream stream{};
|
||||
bool streams = false;
|
||||
const RadKVStream* stream_view(int32_t g) const override {
|
||||
return streams && g == 0 ? &stream : nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
struct FakePC : IPrefixCache {
|
||||
|
||||
@@ -3336,6 +3336,78 @@ TEST(the_cards_block_tables_match_the_manager_after_every_build) {
|
||||
CHECK(checked > 100);
|
||||
}
|
||||
|
||||
/* A streamed group's residency map and ring bookkeeping live in each rank's KV pool,
|
||||
* but the manager the builder is given is rank 0's, so its pointers are rank 0's addresses. A
|
||||
* two-rank batch must name rank r's own copies or device r resolves through device 0's memory
|
||||
* (a page-not-present fault at --tp 2). The host mirror is the exception: RAD_MEM_HOST_MAPPED's
|
||||
* device view is its host address on every card, so it is the same pointer on both ranks.
|
||||
*
|
||||
* The bases are fake and no map is dereferenced: what is under test is the rebasing arithmetic,
|
||||
* not two cards. Both ranks use device 0 so the test runs on the host backend. */
|
||||
TEST(a_two_rank_batch_rebases_stream_maps_into_each_ranks_pool_and_shares_the_mirror) {
|
||||
Fixture f;
|
||||
f.build();
|
||||
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;
|
||||
}
|
||||
|
||||
/* Two pools' worth of address space, only ever differenced, never dereferenced. */
|
||||
alignas(16) char pool0[0x200], pool1[0x200];
|
||||
char* const base[2] = { pool0, pool1 };
|
||||
const int64_t res_off = 0x40, sblk_off = 0x80, sst_off = 0xc0, ctl_off = 0x100;
|
||||
alignas(16) uint8_t mirror[0x100];
|
||||
f.kv.streams = true;
|
||||
f.kv.stream.host = mirror;
|
||||
f.kv.stream.res = (int32_t*)(base[0] + res_off);
|
||||
f.kv.stream.slot_block = (int32_t*)(base[0] + sblk_off);
|
||||
f.kv.stream.slot_state = (int32_t*)(base[0] + sst_off);
|
||||
f.kv.stream.ctl = (int32_t*)(base[0] + ctl_off);
|
||||
f.kv.stream.block_bytes = 64;
|
||||
f.kv.stream.slots = 8;
|
||||
|
||||
BatchBuilder bb;
|
||||
std::vector<BatchBuilder::RankIO> rio;
|
||||
rio.push_back({ 0, nullptr, &f.prog, base[0] });
|
||||
rio.push_back({ 0, nullptr, &f.prog, base[1] });
|
||||
CHECK_OK(bb.init(f.prog, f.cfg, geo, kvg, rio));
|
||||
|
||||
CHECK_OK(f.kv.add_sequence(1));
|
||||
CHECK_OK(f.kv.ensure(1, 80));
|
||||
StepPlan p;
|
||||
p.reset();
|
||||
StepEntry e;
|
||||
e.seq = 1;
|
||||
e.card = 0;
|
||||
e.n_tokens = 1;
|
||||
e.ctx_len = 79;
|
||||
p.e.push_back(e);
|
||||
p.n_tok = 1;
|
||||
REQUIRE(bb.build(p, f.kv, 0) != nullptr);
|
||||
|
||||
for (int r = 0; r < 2; ++r) {
|
||||
const RadBatch* b = bb.batch_for(r);
|
||||
REQUIRE(b != nullptr);
|
||||
const RadKVStream* s = b->kv[0].stream;
|
||||
REQUIRE(s != nullptr);
|
||||
CHECK_EQ((void*)s->res, (void*)(base[r] + res_off));
|
||||
CHECK_EQ((void*)s->slot_block, (void*)(base[r] + sblk_off));
|
||||
CHECK_EQ((void*)s->slot_state, (void*)(base[r] + sst_off));
|
||||
CHECK_EQ((void*)s->ctl, (void*)(base[r] + ctl_off));
|
||||
/* Same mirror address, and the geometry is rank-independent. */
|
||||
CHECK_EQ((void*)s->host, (void*)mirror);
|
||||
CHECK_EQ(s->block_bytes, (int64_t)64);
|
||||
CHECK_EQ(s->slots, (int64_t)8);
|
||||
/* Groups that do not stream keep a null view. */
|
||||
for (int gi = 1; gi < b->n_kv_groups; ++gi)
|
||||
CHECK(b->kv[gi].stream == 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
|
||||
|
||||
@@ -2271,6 +2271,11 @@ TEST(metrics_is_valid_prometheus_text_with_vllm_names) {
|
||||
CHECK_EQ(d.type["radiance:draft_acceptance_ratio"], std::string("gauge"));
|
||||
CHECK_EQ(d.type["radiance:decode_tokens_per_second"], std::string("gauge"));
|
||||
CHECK_EQ(d.type["radiance:http_admission_rejected_total"], std::string("counter"));
|
||||
/* KV streaming (docs/KV-STREAMING.md §4.2), present even when no group streams so a dashboard
|
||||
* can query the names before the feature is turned on. The bytes counter carries `dir`. */
|
||||
CHECK_EQ(d.type["radiance:kv_resident_blocks"], std::string("gauge"));
|
||||
CHECK_EQ(d.type["radiance:kv_stream_misses_total"], std::string("counter"));
|
||||
CHECK_EQ(d.type["radiance:kv_stream_bytes_total"], std::string("counter"));
|
||||
|
||||
/* The scheduler's numbers reached the gauges. */
|
||||
auto find_one = [&](const std::string& prefix) -> double {
|
||||
@@ -2283,6 +2288,10 @@ TEST(metrics_is_valid_prometheus_text_with_vllm_names) {
|
||||
CHECK_NEAR(find_one("vllm:gpu_cache_usage_perc{"), 0.42, 1e-9);
|
||||
CHECK_NEAR(find_one("radiance:draft_acceptance_ratio{"), 0.61, 1e-9);
|
||||
CHECK_NEAR(find_one("vllm:generation_tokens_total{"), 5.0, 1e-9);
|
||||
/* This server streams nothing, so every streaming number is zero. */
|
||||
CHECK_NEAR(find_one("radiance:kv_resident_blocks{"), 0.0, 1e-9);
|
||||
CHECK_NEAR(find_one("radiance:kv_stream_misses_total{"), 0.0, 1e-9);
|
||||
CHECK_NEAR(find_one("radiance:kv_stream_bytes_total{"), 0.0, 1e-9);
|
||||
|
||||
/* An unmeasured decode floor is absent, not 0, which a scrape would plot as the fastest step
|
||||
* ever. This fixture completes no single-stream window, so neither series appears. */
|
||||
|
||||
Reference in new issue
Block a user