Archived
prefill: fail closed when live split geometry is unknown
Head-256 split-prefill launchers now declare that their grid depends on live KV. Without an architecture geometry key, those passes stay live instead of replaying a stale tape. Qwen keys only a proven one-sequence prefill. Plugin ABI 34.
This commit is contained in:
1 parent
ded64c0bd3
commit
aa14eea76c
10 files changed
+148
-30
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 33 and
|
||||
/* abi_layout_table.h -- every abi/ struct's size and field offsets at RAD_ABI_VERSION 34 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. */
|
||||
@@ -33,7 +33,7 @@
|
||||
{ "RadArgs", "instance", 48, 8 },
|
||||
{ "RadArgs", "rank", 56, 4 },
|
||||
{ "RadArgs", "world_size", 60, 4 },
|
||||
{ "RadBatch", "", 0, 416 },
|
||||
{ "RadBatch", "", 0, 424 },
|
||||
{ "RadBatch", "phase", 0, 4 },
|
||||
{ "RadBatch", "step", 4, 4 },
|
||||
{ "RadBatch", "n_tok", 8, 8 },
|
||||
@@ -91,6 +91,7 @@
|
||||
{ "RadBatch", "plugin_words_h", 392, 8 },
|
||||
{ "RadBatch", "plugin_cu_h", 400, 8 },
|
||||
{ "RadBatch", "sgen_b", 408, 8 },
|
||||
{ "RadBatch", "kv_used_max_h", 416, 8 },
|
||||
{ "RadBufDecl", "", 0, 80 },
|
||||
{ "RadBufDecl", "dtype", 0, 4 },
|
||||
{ "RadBufDecl", "rank", 4, 4 },
|
||||
@@ -516,7 +517,7 @@
|
||||
{ "RadKVStream", "host_layer_stride", 48, 8 },
|
||||
{ "RadKVStream", "slots", 56, 8 },
|
||||
{ "RadKVStream", "host_bytes", 64, 8 },
|
||||
{ "RadKernelInfo", "", 0, 168 },
|
||||
{ "RadKernelInfo", "", 0, 176 },
|
||||
{ "RadKernelInfo", "name", 0, 8 },
|
||||
{ "RadKernelInfo", "op", 8, 8 },
|
||||
{ "RadKernelInfo", "family", 16, 8 },
|
||||
@@ -539,6 +540,7 @@
|
||||
{ "RadKernelInfo", "opd_shape", 144, 8 },
|
||||
{ "RadKernelInfo", "unrelayout", 152, 8 },
|
||||
{ "RadKernelInfo", "replaces", 160, 8 },
|
||||
{ "RadKernelInfo", "capabilities", 168, 8 },
|
||||
{ "RadLayout", "", 0, 80 },
|
||||
{ "RadLayout", "tag", 0, 8 },
|
||||
{ "RadLayout", "dtype", 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 rad_abi_layout_rows.h is complete; and
|
||||
* the layout agrees with the table below, taken at RAD_ABI_VERSION 32 and RAD_FORMAT_VER 2. Under
|
||||
* the layout agrees with the table below, taken at RAD_ABI_VERSION 34 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 32 / RAD_FORMAT_VER 2 (see the file header). */
|
||||
constexpr uint32_t kTableAbi = 33, kTableFormat = 2;
|
||||
/* The layout at RAD_ABI_VERSION 34 / RAD_FORMAT_VER 2 (see the file header). */
|
||||
constexpr uint32_t kTableAbi = 34, kTableFormat = 2;
|
||||
const AbiRow kTable[] = {
|
||||
#include "abi_layout_table.h"
|
||||
};
|
||||
|
||||
@@ -524,6 +524,7 @@ extern "C" int rad_step_fail(RadCtx* c, const char* what) {
|
||||
extern "C" const RadBatch* rad_batch(RadCtx* c) { return c->batch; }
|
||||
extern "C" int rad_rank(RadCtx* c) { return c->rank; }
|
||||
extern "C" int rad_world_size(RadCtx* c) { return c->world; }
|
||||
extern "C" int rad_ctx_wgp_count(RadCtx*) { return 32; }
|
||||
/* The context itself, so a copy issued on the step's stream is recorded in it (rad_memcpy_async). */
|
||||
extern "C" RadStream rad_stream(RadCtx* c) { return (RadStream)c; }
|
||||
extern "C" int rad_stream_sync(RadStream s) { (void)s; return RAD_OK; }
|
||||
|
||||
@@ -1882,6 +1882,55 @@ RadModelMeta qwen4exp_meta() {
|
||||
}
|
||||
} /* namespace */
|
||||
|
||||
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;
|
||||
RadBuilder graph;
|
||||
REQUIRE_EQ(qwen4exp_fp8::declare(&graph, &meta, &build), RAD_OK);
|
||||
rad_kvgroup kv_full = 0;
|
||||
for (size_t i = 0; i < graph.kv_groups.size(); ++i)
|
||||
if (graph.kv_groups[i].name.find("kv_attn") != std::string::npos) {
|
||||
kv_full = (rad_kvgroup)(i + 1);
|
||||
break;
|
||||
}
|
||||
REQUIRE(kv_full != 0);
|
||||
|
||||
RadCtx ctx{};
|
||||
RadKVGroupBatch group{};
|
||||
group.group = kv_full;
|
||||
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;
|
||||
int32_t used[1] = {2304};
|
||||
const uint64_t key6 = qwen4exp_fp8::pass_key(&ctx, &batch, used);
|
||||
CHECK(key6 != 0);
|
||||
used[0] = 2305;
|
||||
CHECK_EQ(qwen4exp_fp8::pass_key(&ctx, &batch, used), key6);
|
||||
used[0] = 3072;
|
||||
CHECK(qwen4exp_fp8::pass_key(&ctx, &batch, used) != key6);
|
||||
|
||||
/* 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;
|
||||
const uint64_t key_chunk = qwen4exp_fp8::pass_key(&ctx, &batch, used);
|
||||
CHECK(key_chunk != 0);
|
||||
CHECK(key_chunk != key6);
|
||||
batch.n_tok = 64; batch.max_q_len = 64;
|
||||
|
||||
batch.phase = RAD_PHASE_MIXED;
|
||||
CHECK_EQ(qwen4exp_fp8::pass_key(&ctx, &batch, used), (uint64_t)0);
|
||||
batch.phase = RAD_PHASE_DECODE; batch.n_spec = 1;
|
||||
CHECK_EQ(qwen4exp_fp8::pass_key(&ctx, &batch, used), (uint64_t)0);
|
||||
batch.n_spec = 0; batch.draft_pass = -1;
|
||||
CHECK_EQ(qwen4exp_fp8::pass_key(&ctx, &batch, used), (uint64_t)0);
|
||||
batch.draft_pass = 0; batch.phase = RAD_PHASE_PREFILL; batch.n_seq = 2;
|
||||
CHECK_EQ(qwen4exp_fp8::pass_key(&ctx, &batch, used), (uint64_t)0);
|
||||
batch.n_seq = 1; used[0] = 0;
|
||||
CHECK_EQ(qwen4exp_fp8::pass_key(&ctx, &batch, used), (uint64_t)0);
|
||||
}
|
||||
|
||||
TEST(qwen4exp_yarn_reaches_attention_indexer_and_compressed_keys) {
|
||||
RadModelMeta meta = qwen4exp_meta();
|
||||
std::vector<const char*> keys(meta.kv_key, meta.kv_key + meta.n_kv);
|
||||
|
||||
+39
-1
@@ -2178,12 +2178,14 @@ int k_copy(const RadArgs* a, RadStream s) {
|
||||
}
|
||||
|
||||
/* A host row for every band of `op`, from a library that is not the reference. */
|
||||
void attach_host_row(Fixture& f, rad_op op, RadLaunchFn fn, const char* name) {
|
||||
void attach_host_row(Fixture& f, rad_op op, RadLaunchFn fn, const char* name,
|
||||
uint64_t capabilities = 0) {
|
||||
for (rad::Band& band : f.P.ops[op].bands) {
|
||||
f.infos.push_back(RadKernelInfo{});
|
||||
RadKernelInfo& ki = f.infos.back();
|
||||
ki.name = name; ki.op = "rope"; ki.family = "test"; ki.domain = RAD_DOMAIN_HOST;
|
||||
ki.launch = fn;
|
||||
ki.capabilities = capabilities;
|
||||
f.rows.push_back(rad::KernelRow{});
|
||||
rad::KernelRow& kr = f.rows.back();
|
||||
kr.info = &ki;
|
||||
@@ -2341,6 +2343,42 @@ static uint64_t test_prefill_geometry_key(RadCtx* c, const RadBatch* b, const in
|
||||
return rad_prefill_grid_key((int)b->max_q_len, bq, splits, kv_heads, (int)b->n_seq, threads);
|
||||
}
|
||||
|
||||
TEST(legacy_prefill_keying_only_fails_closed_for_dynamic_split_rows) {
|
||||
{
|
||||
Fixture f;
|
||||
f.add_buffer("x", RAD_BF16, 64, 4, 0);
|
||||
rad_op op = loose_op(f);
|
||||
attach_host_row(f, op, k_host_read, "unaffected_prefill");
|
||||
CHECK_OK(f.start());
|
||||
|
||||
RadBatch b{};
|
||||
b.phase = RAD_PHASE_PREFILL;
|
||||
b.n_tok = 128; b.n_seq = 1; b.max_q_len = 128;
|
||||
CHECK(f.ctx.pass_key(&b) != 0); // Unaffected legacy prefill retains reuse.
|
||||
}
|
||||
{
|
||||
Fixture f;
|
||||
f.add_buffer("x", RAD_BF16, 64, 4, 0);
|
||||
rad_op op = loose_op(f);
|
||||
attach_host_row(f, op, k_host_read, "live_split_prefill",
|
||||
RAD_KERNEL_CAP_DYNAMIC_PREFILL_SPLIT);
|
||||
CHECK_OK(f.start());
|
||||
|
||||
RadBatch b{};
|
||||
b.phase = RAD_PHASE_PREFILL;
|
||||
b.n_tok = 128; b.n_seq = 1; b.max_q_len = 128;
|
||||
CHECK_EQ(f.ctx.pass_key(&b), (uint64_t)0);
|
||||
b.phase = RAD_PHASE_MIXED;
|
||||
CHECK_EQ(f.ctx.pass_key(&b), (uint64_t)0);
|
||||
b.phase = RAD_PHASE_DECODE; b.n_spec = 1;
|
||||
CHECK_EQ(f.ctx.pass_key(&b), (uint64_t)0);
|
||||
b.n_spec = 0; b.draft_pass = -1;
|
||||
CHECK_EQ(f.ctx.pass_key(&b), (uint64_t)0);
|
||||
b.draft_pass = 0;
|
||||
CHECK(f.ctx.pass_key(&b) != 0); // Ordinary decode remains recordable.
|
||||
}
|
||||
}
|
||||
|
||||
TEST(the_prefill_geometry_key_reuses_equal_grids_and_separates_changed_grids) {
|
||||
Fixture f;
|
||||
f.add_buffer("x", RAD_BF16, 64, 4, 0);
|
||||
|
||||
Reference in new issue
Block a user