From cebf759a3669208f2cff009a405ce0747685c0f0 Mon Sep 17 00:00:00 2001 From: Constantin Date: Tue, 3 Nov 2026 14:04:24 -0500 Subject: [PATCH] fix: keep one Spark prefill pass key per plugin --- arch/spark25_bf16/spark25_bf16.cpp | 26 ----------------- arch/spark25_w8a8/spark25_w8a8.cpp | 26 ----------------- tests/spark25_arch_test.cpp | 46 ------------------------------ 3 files changed, 98 deletions(-) diff --git a/arch/spark25_bf16/spark25_bf16.cpp b/arch/spark25_bf16/spark25_bf16.cpp index a7deda42..52ed2d93 100644 --- a/arch/spark25_bf16/spark25_bf16.cpp +++ b/arch/spark25_bf16/spark25_bf16.cpp @@ -593,32 +593,6 @@ static uint64_t pass_key(RadCtx* c, const RadBatch* batch, const int32_t* used_m /* The speculation depth this container supports: zero without a drafter, or the block length a * DSpark drafter was trained at. `draft_depth_fixed` because a block-diffusion drafter denoises * exactly that many mask positions, and `declare` refuses to run it at any other depth. */ -#ifdef SPARK25_HAVE_PREFILL_SPLIT -static uint64_t pass_key(RadCtx* c, const RadBatch* batch, const int32_t* used_max_h) { - if (!c || !batch) return 0; - Model& m = models[rad_rank(c)]; - int group = -1; - if (batch->kv) for (int i = 0; i < batch->n_kv_groups; ++i) - if (batch->kv[i].group == m.kv) { group = i; break; } - spark25_prefill_key::Request r; - r.phase = batch->phase; - r.n_tok = batch->n_tok; - r.n_seq = batch->n_seq; - r.max_q_len = batch->max_q_len; - r.max_ctx = m.g.max_ctx; - r.n_spec = batch->n_spec; - r.draft_pass = batch->draft_pass; - r.enc = batch->enc != 0; - r.head_dim = m.g.head_dim; - r.gqa = m.g.gqa(); - r.kv_heads = m.g.n_head_kv; - r.kv_group_found = group >= 0; - r.used = used_max_h && group >= 0 ? used_max_h[group] : 0; - r.wgps = rad_ctx_wgp_count(c); - return spark25_prefill_key::pass_key(r); -} -#endif - static int probe(const RadModelMeta* meta, RadArchProbe* out) { if (!meta || !out) return RAD_E_INVAL; out->draft_depth = 0; diff --git a/arch/spark25_w8a8/spark25_w8a8.cpp b/arch/spark25_w8a8/spark25_w8a8.cpp index fd42cb04..27c43645 100644 --- a/arch/spark25_w8a8/spark25_w8a8.cpp +++ b/arch/spark25_w8a8/spark25_w8a8.cpp @@ -647,32 +647,6 @@ static uint64_t pass_key(RadCtx* c, const RadBatch* batch, const int32_t* used_m /* The speculation depth this container supports: zero without a drafter, or the block length a * DSpark drafter was trained at. `draft_depth_fixed` because a block-diffusion drafter denoises * exactly that many mask positions, and `declare` refuses to run it at any other depth. */ -#ifdef SPARK25_HAVE_PREFILL_SPLIT -static uint64_t pass_key(RadCtx* c, const RadBatch* batch, const int32_t* used_max_h) { - if (!c || !batch) return 0; - Model& m = models[rad_rank(c)]; - int group = -1; - if (batch->kv) for (int i = 0; i < batch->n_kv_groups; ++i) - if (batch->kv[i].group == m.kv) { group = i; break; } - spark25_prefill_key::Request r; - r.phase = batch->phase; - r.n_tok = batch->n_tok; - r.n_seq = batch->n_seq; - r.max_q_len = batch->max_q_len; - r.max_ctx = m.g.max_ctx; - r.n_spec = batch->n_spec; - r.draft_pass = batch->draft_pass; - r.enc = batch->enc != 0; - r.head_dim = m.g.head_dim; - r.gqa = m.g.gqa(); - r.kv_heads = m.g.n_head_kv; - r.kv_group_found = group >= 0; - r.used = used_max_h && group >= 0 ? used_max_h[group] : 0; - r.wgps = rad_ctx_wgp_count(c); - return spark25_prefill_key::pass_key(r); -} -#endif - static int probe(const RadModelMeta* meta, RadArchProbe* out) { if (!meta || !out) return RAD_E_INVAL; out->draft_depth = 0; diff --git a/tests/spark25_arch_test.cpp b/tests/spark25_arch_test.cpp index 4cf272f5..2d9eca63 100644 --- a/tests/spark25_arch_test.cpp +++ b/tests/spark25_arch_test.cpp @@ -840,52 +840,6 @@ TEST(the_int8_trunk_carries_the_same_drafter) { CHECK_EQ(p.draft_depth_fixed, 1); } -TEST(spark_prefill_keys_match_live_r4d_split_grid) { -#ifdef SPARK25_HAVE_PREFILL_SPLIT - spark25_prefill_key::Request r; - r.phase = RAD_PHASE_PREFILL; r.n_tok = r.max_q_len = 256; r.n_seq = 1; - r.max_ctx = 65536; r.head_dim = 256; r.gqa = 4; r.kv_heads = 4; - r.kv_group_found = 1; r.used = 1536; r.wgps = 32; - const uint64_t k4 = spark25_prefill_key::pass_key(r); - CHECK_EQ(rad_prefill_splits_for_live(96, 48, 256, 256, 1, 4, 65536, 1536, 32), 4); - r.used = 2048; - CHECK_EQ(rad_prefill_splits_for_live(96, 48, 256, 256, 1, 4, 65536, 2048, 32), 5); - CHECK(spark25_prefill_key::pass_key(r) != k4); - r = {}; r.phase = RAD_PHASE_PREFILL; r.n_tok = r.max_q_len = 256; r.n_seq = 2; - r.max_ctx = 65536; r.head_dim = 256; r.gqa = 4; r.kv_heads = 4; - r.kv_group_found = 1; r.used = 1536; r.wgps = 32; - CHECK_EQ(spark25_prefill_key::pass_key(r), (uint64_t)0); - - MetaKV meta = spark_meta(); - RadBuildCtx ctx = build_ctx(); - RadBuilder bf16_builder; - REQUIRE_EQ(spark25_bf16::declare(&bf16_builder, meta.meta(), &ctx), RAD_OK); - RadKVGroupBatch kv{}; kv.group = spark25_bf16::models[0].kv; - RadBatch batch{}; batch.phase = RAD_PHASE_PREFILL; batch.n_tok = batch.max_q_len = 256; - batch.n_seq = batch.n_kv_groups = 1; batch.kv = &kv; - int32_t used[1] = {1536}; RadCtx c{}; - const uint64_t bf16_k4 = spark25_bf16::pass_key(&c, &batch, used); - REQUIRE(bf16_k4 != 0); - used[0] = 2048; - CHECK(spark25_bf16::pass_key(&c, &batch, used) != bf16_k4); - - MetaKV iqmeta = spark_meta(); - iqmeta.m.quant = "w8a8_fwht128"; - iqmeta.set("quantization_config.quant_method", "w8a8") - .set("quantization_config.fmt", "fwht128"); - RadBuilder iq_builder; spark_iq8r_encodings(iq_builder); - REQUIRE_EQ(spark25_w8a8::declare(&iq_builder, iqmeta.meta(), &ctx), RAD_OK); - kv.group = spark25_w8a8::models[0].kv; - used[0] = 1536; - const uint64_t iq_k4 = spark25_w8a8::pass_key(&c, &batch, used); - REQUIRE(iq_k4 != 0); - used[0] = 2048; - CHECK(spark25_w8a8::pass_key(&c, &batch, used) != iq_k4); -#else - CHECK_EQ(spark25_prefill_key::pass_key({}), (uint64_t)0); -#endif -} - TEST(refuses_unimplemented_variants) { RadBuildCtx ctx = build_ctx(); for (const auto& change : {std::pair{"tie_word_embeddings", "0"},