Archived
prefill: key tape splits from ordered host KV bounds
This commit is contained in:
1 parent
aa14eea76c
commit
798fb21e51
14 files changed
+221
-65
No files matched your search
@@ -1,4 +1,4 @@
|
||||
/* abi_layout_table.h -- every abi/ struct's size and field offsets at RAD_ABI_VERSION 34 and
|
||||
/* abi_layout_table.h -- every abi/ struct's size and field offsets at RAD_ABI_VERSION 35 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. */
|
||||
@@ -23,7 +23,7 @@
|
||||
{ "RadArchProbe", "gen_max_pixels", 104, 8 },
|
||||
{ "RadArchProbe", "gen_max_refs", 112, 8 },
|
||||
{ "RadArchProbe", "gen_shape", 120, 4 },
|
||||
{ "RadArgs", "", 0, 64 },
|
||||
{ "RadArgs", "", 0, 72 },
|
||||
{ "RadArgs", "t", 0, 8 },
|
||||
{ "RadArgs", "n_t", 8, 4 },
|
||||
{ "RadArgs", "p", 16, 8 },
|
||||
@@ -33,7 +33,9 @@
|
||||
{ "RadArgs", "instance", 48, 8 },
|
||||
{ "RadArgs", "rank", 56, 4 },
|
||||
{ "RadArgs", "world_size", 60, 4 },
|
||||
{ "RadBatch", "", 0, 424 },
|
||||
{ "RadArgs", "kv_used_max_h", 64, 4 },
|
||||
{ "RadArgs", "wgp_count", 68, 4 },
|
||||
{ "RadBatch", "", 0, 432 },
|
||||
{ "RadBatch", "phase", 0, 4 },
|
||||
{ "RadBatch", "step", 4, 4 },
|
||||
{ "RadBatch", "n_tok", 8, 8 },
|
||||
@@ -92,6 +94,7 @@
|
||||
{ "RadBatch", "plugin_cu_h", 400, 8 },
|
||||
{ "RadBatch", "sgen_b", 408, 8 },
|
||||
{ "RadBatch", "kv_used_max_h", 416, 8 },
|
||||
{ "RadBatch", "positions_h", 424, 8 },
|
||||
{ "RadBufDecl", "", 0, 80 },
|
||||
{ "RadBufDecl", "dtype", 0, 4 },
|
||||
{ "RadBufDecl", "rank", 4, 4 },
|
||||
@@ -488,7 +491,7 @@
|
||||
{ "RadGeneratorDecl", "chunk_bos", 364, 4 },
|
||||
{ "RadGeneratorDecl", "chunk_eos", 368, 4 },
|
||||
{ "RadGeneratorDecl", "cond_opts", 372, 4 },
|
||||
{ "RadKVGroupBatch", "", 0, 80 },
|
||||
{ "RadKVGroupBatch", "", 0, 88 },
|
||||
{ "RadKVGroupBatch", "group", 0, 4 },
|
||||
{ "RadKVGroupBatch", "slot_mapping", 8, 8 },
|
||||
{ "RadKVGroupBatch", "block_table", 16, 8 },
|
||||
@@ -499,6 +502,7 @@
|
||||
{ "RadKVGroupBatch", "block_size", 56, 8 },
|
||||
{ "RadKVGroupBatch", "max_blocks", 64, 8 },
|
||||
{ "RadKVGroupBatch", "stream", 72, 8 },
|
||||
{ "RadKVGroupBatch", "seqused_h", 80, 8 },
|
||||
{ "RadKVGroupDecl", "", 0, 56 },
|
||||
{ "RadKVGroupDecl", "kind", 0, 4 },
|
||||
{ "RadKVGroupDecl", "dtype", 4, 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 rad_abi_layout_rows.h is complete; and
|
||||
* the layout agrees with the table below, taken at RAD_ABI_VERSION 34 and RAD_FORMAT_VER 2. Under
|
||||
* the layout agrees with the table below, taken at RAD_ABI_VERSION 35 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 34 / RAD_FORMAT_VER 2 (see the file header). */
|
||||
constexpr uint32_t kTableAbi = 34, kTableFormat = 2;
|
||||
/* The layout at RAD_ABI_VERSION 35 / RAD_FORMAT_VER 2 (see the file header). */
|
||||
constexpr uint32_t kTableAbi = 35, kTableFormat = 2;
|
||||
const AbiRow kTable[] = {
|
||||
#include "abi_layout_table.h"
|
||||
};
|
||||
|
||||
+9
-2
@@ -1885,7 +1885,7 @@ RadModelMeta qwen4exp_meta() {
|
||||
TEST(qwen4exp_pass_key_reuses_only_proven_uniform_prefill_grids) {
|
||||
RadModelMeta meta = qwen4exp_meta();
|
||||
RadBuildCtx build = build_ctx(0, 1);
|
||||
build.max_tok = 64; build.max_seqs = 2; build.max_spec = 0; build.max_ctx = 4096;
|
||||
build.max_tok = 64; build.max_seqs = 2; build.max_spec = 0; build.max_ctx = 65536;
|
||||
RadBuilder graph;
|
||||
REQUIRE_EQ(qwen4exp_fp8::declare(&graph, &meta, &build), RAD_OK);
|
||||
rad_kvgroup kv_full = 0;
|
||||
@@ -1902,7 +1902,8 @@ TEST(qwen4exp_pass_key_reuses_only_proven_uniform_prefill_grids) {
|
||||
RadBatch batch{};
|
||||
batch.phase = RAD_PHASE_PREFILL;
|
||||
batch.n_tok = 64; batch.n_seq = 1; batch.max_q_len = 64;
|
||||
batch.max_ctx_len = 4096; batch.n_kv_groups = 1; batch.kv = &group;
|
||||
/* The split law uses the declared launch context, not this rounded live-batch bound. */
|
||||
batch.max_ctx_len = 1024; batch.n_kv_groups = 1; batch.kv = &group;
|
||||
int32_t used[1] = {2304};
|
||||
const uint64_t key6 = qwen4exp_fp8::pass_key(&ctx, &batch, used);
|
||||
CHECK(key6 != 0);
|
||||
@@ -1911,6 +1912,12 @@ TEST(qwen4exp_pass_key_reuses_only_proven_uniform_prefill_grids) {
|
||||
used[0] = 3072;
|
||||
CHECK(qwen4exp_fp8::pass_key(&ctx, &batch, used) != key6);
|
||||
|
||||
/* Same rounded live bound, different exact grids under the launcher's model context. */
|
||||
used[0] = 896;
|
||||
const uint64_t key_896 = qwen4exp_fp8::pass_key(&ctx, &batch, used);
|
||||
used[0] = 1152;
|
||||
CHECK(qwen4exp_fp8::pass_key(&ctx, &batch, used) != key_896);
|
||||
|
||||
/* A shorter one-sequence chunk still proves q_len = n_tok; do not require the model max_tok. */
|
||||
used[0] = 2304;
|
||||
batch.n_tok = 32; batch.max_q_len = 32;
|
||||
|
||||
+51
-1
@@ -50,6 +50,7 @@ struct Rec {
|
||||
RadTensor t[8]{};
|
||||
long long M = -1;
|
||||
int rank = 0, world = 0;
|
||||
int32_t kv_used_max_h = -1;
|
||||
void* scratch = nullptr;
|
||||
int64_t scratch_bytes = 0;
|
||||
void* instance = nullptr;
|
||||
@@ -67,6 +68,7 @@ static int record(const char* name, const RadArgs* a, RadStream s) {
|
||||
rad_args_geti(a, "M", &r.M);
|
||||
r.rank = a->rank;
|
||||
r.world = a->world_size;
|
||||
r.kv_used_max_h = a->kv_used_max_h;
|
||||
r.scratch = a->scratch;
|
||||
r.scratch_bytes = a->scratch_bytes;
|
||||
r.instance = a->instance;
|
||||
@@ -2337,9 +2339,10 @@ static uint64_t test_prefill_geometry_key(RadCtx* c, const RadBatch* b, const in
|
||||
if (!c || !b || !used) return 0;
|
||||
const int bq = 192, tile = 48, kv_heads = 4, threads = 768;
|
||||
const int wgps = rad_ctx_wgp_count(c);
|
||||
constexpr int declared_max_ctx = 65536;
|
||||
const int splits = rad_prefill_splits_for_live(bq, tile, (int)b->max_q_len,
|
||||
(int)b->n_tok, (int)b->n_seq, kv_heads,
|
||||
b->max_ctx_len, used[0], wgps);
|
||||
declared_max_ctx, used[0], wgps);
|
||||
return rad_prefill_grid_key((int)b->max_q_len, bq, splits, kv_heads, (int)b->n_seq, threads);
|
||||
}
|
||||
|
||||
@@ -2379,6 +2382,53 @@ TEST(legacy_prefill_keying_only_fails_closed_for_dynamic_split_rows) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST(issue_passes_only_proven_kv_host_summaries) {
|
||||
Fixture f;
|
||||
rad_op op = f.add_op("rope", "M", { 8192 }, { k_pre }, { "prefill" }, nullptr, {});
|
||||
CHECK_OK(f.start());
|
||||
|
||||
int32_t used_device[2] = { 896, 1152 }, used_host[2] = { 896, 1152 };
|
||||
int32_t positions_device[128]{}, positions_host[128]{};
|
||||
for (int i = 0; i < 128; ++i) positions_host[i] = 2048 + i;
|
||||
RadKVGroupBatch kv{};
|
||||
kv.group = 1;
|
||||
kv.seqused = used_device;
|
||||
kv.seqused_h = used_host;
|
||||
int32_t used_max[1] = { 1152 };
|
||||
f.batch.n_kv_groups = 1;
|
||||
f.batch.kv = &kv;
|
||||
f.batch.kv_used_max_h = used_max;
|
||||
f.batch.positions = positions_device;
|
||||
f.batch.positions_h = positions_host;
|
||||
|
||||
auto issue = [&](const int32_t* ptr, int rows, int batch_seqs, int phase, int n_spec) -> int32_t {
|
||||
f.batch.phase = phase;
|
||||
f.batch.n_tok = 128;
|
||||
f.batch.n_seq = batch_seqs;
|
||||
f.batch.n_spec = n_spec;
|
||||
g_rec.clear();
|
||||
g_body = [&](Ctx& c) {
|
||||
const RadOperand arg[1] = { RAD_P_T2(ptr, RAD_I32, rows, 1) };
|
||||
(void)c.issue(op, arg, 1, RAD_N_BATCH);
|
||||
};
|
||||
const int status = f.ctx.run_step(&f.batch);
|
||||
g_body = nullptr;
|
||||
if (status < 0 || g_rec.size() != 1) return -999;
|
||||
return g_rec[0].kv_used_max_h;
|
||||
};
|
||||
|
||||
CHECK_EQ(issue(used_device, 2, 2, RAD_PHASE_PREFILL, 0), 1152); // full group maximum
|
||||
CHECK_EQ(issue(used_device + 1, 1, 2, RAD_PHASE_PREFILL, 0), 1152); // exact sequence slice
|
||||
CHECK_EQ(issue(used_device, 1, 2, RAD_PHASE_PREFILL, 0), 896); // first sequence only
|
||||
CHECK_EQ(issue(used_device, 3, 2, RAD_PHASE_PREFILL, 0), -1); // out-of-range span
|
||||
CHECK_EQ(issue(used_device + 1, 1, 2, RAD_PHASE_MIXED, 0), 1152); // mixed prefill slice
|
||||
CHECK_EQ(issue(used_device, 2, 2, RAD_PHASE_PREFILL, 1), 1152); // exact speculative operand
|
||||
CHECK_EQ(issue(positions_device + 64, 1, 1, RAD_PHASE_PREFILL, 0), positions_host[64]);
|
||||
CHECK_EQ(issue(positions_device + 128, 1, 1, RAD_PHASE_PREFILL, 0), -1); // past step end
|
||||
CHECK_EQ(issue(positions_device + 64, 1, 1, RAD_PHASE_MIXED, 0), -1);
|
||||
CHECK_EQ(issue(positions_device + 64, 1, 1, RAD_PHASE_PREFILL, 1), -1);
|
||||
}
|
||||
|
||||
TEST(the_prefill_geometry_key_reuses_equal_grids_and_separates_changed_grids) {
|
||||
Fixture f;
|
||||
f.add_buffer("x", RAD_BF16, 64, 4, 0);
|
||||
|
||||
@@ -6977,6 +6977,10 @@ TEST(a_preempted_ring_sequence_replays_its_output_a_token_a_step) {
|
||||
REQUIRE(chunk != nullptr);
|
||||
REQUIRE_EQ(f.sch.plan().e.size(), (size_t)1);
|
||||
const RadKVGroupBatch& paged = chunk->kv[0];
|
||||
REQUIRE(paged.seqused_h != nullptr);
|
||||
REQUIRE(chunk->positions_h != nullptr);
|
||||
CHECK_EQ(paged.seqused_h[0], paged.seqused[0]);
|
||||
CHECK_EQ(chunk->positions_h[0], chunk->positions[0]);
|
||||
int32_t used_max = 0;
|
||||
for (int64_t i = 0; i < chunk->n_seq; ++i)
|
||||
used_max = std::max(used_max, paged.seqused[i]);
|
||||
@@ -6993,6 +6997,10 @@ TEST(a_preempted_ring_sequence_replays_its_output_a_token_a_step) {
|
||||
const RadBatch* rb = f.sch.step();
|
||||
REQUIRE(rb != nullptr);
|
||||
CHECK_EQ(rb->kv_used_max_h[0], rb->kv[0].seqused[0]);
|
||||
REQUIRE(rb->kv[0].seqused_h != nullptr);
|
||||
REQUIRE(rb->positions_h != nullptr);
|
||||
CHECK_EQ(rb->kv[0].seqused_h[0], rb->kv[0].seqused[0]);
|
||||
CHECK_EQ(rb->positions_h[0], rb->positions[0]);
|
||||
CHECK_EQ(f.sch.plan().e[0].ctx_len, 160);
|
||||
CHECK_EQ(f.sch.plan().e[0].n_tokens, 1);
|
||||
CHECK(f.sch.plan().e[0].produces_token);
|
||||
|
||||
Reference in new issue
Block a user