Archived
--kv-cache-dtype fp8_v4 | k6_v4 (RadBuildCtx::kv_quant, RadArchProbe::kv_quant_ok; ABI 23)
The flag sets the trunk's cache to E4M3 plus a RAD_KVQ_* layout; a plugin offers the layouts it serves in its probe and the server refuses any other, naming the plugin. qwen35_fp8 offers both at head_dim 256, gqa 6, and declares the group at head_dim 200 / 176 (the row's bytes / 2), so the core sizes pages as for fp8; a drafter's cache stays fp8. Qwen3.8-27B on two R9700s, KL against bf16 on 17 long documents: fp8 0.039963 (518,800 tokens of KV), fp8_v4 0.040076 (664,400), k6_v4 0.039965 (755,184); prefill and decode at fp8's speed. ABI 23: two trailing fields, the layout table regenerated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c00a650bce
commit
1823ccd5e9
14 files changed
+238
-20
No files matched your search
@@ -16,6 +16,7 @@ ABI_FIELD(RadArchProbe, gen_patches)
|
||||
ABI_FIELD(RadArchProbe, gen_audio)
|
||||
ABI_FIELD(RadArchProbe, gen_ctx)
|
||||
ABI_FIELD(RadArchProbe, gen_video)
|
||||
ABI_FIELD(RadArchProbe, kv_quant_ok)
|
||||
ABI_STRUCT(RadArgs)
|
||||
ABI_FIELD(RadArgs, t)
|
||||
ABI_FIELD(RadArgs, n_t)
|
||||
@@ -99,6 +100,7 @@ ABI_FIELD(RadBuildCtx, max_enc_patches)
|
||||
ABI_FIELD(RadBuildCtx, max_out_rows)
|
||||
ABI_FIELD(RadBuildCtx, max_audio_frames)
|
||||
ABI_FIELD(RadBuildCtx, max_mixed_tok)
|
||||
ABI_FIELD(RadBuildCtx, kv_quant)
|
||||
ABI_STRUCT(RadAudioGenBatch)
|
||||
ABI_FIELD(RadAudioGenBatch, n_lane)
|
||||
ABI_FIELD(RadAudioGenBatch, lane)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* abi_layout_table.h -- every abi/ struct's size and field offsets at RAD_ABI_VERSION 21 and
|
||||
/* abi_layout_table.h -- every abi/ struct's size and field offsets at RAD_ABI_VERSION 23 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. */
|
||||
@@ -13,6 +13,7 @@
|
||||
{ "RadArchProbe", "gen_audio", 48, 4 },
|
||||
{ "RadArchProbe", "gen_ctx", 56, 8 },
|
||||
{ "RadArchProbe", "gen_video", 64, 4 },
|
||||
{ "RadArchProbe", "kv_quant_ok", 68, 4 },
|
||||
{ "RadArgs", "", 0, 64 },
|
||||
{ "RadArgs", "t", 0, 8 },
|
||||
{ "RadArgs", "n_t", 8, 4 },
|
||||
@@ -79,7 +80,7 @@
|
||||
{ "RadBufDecl", "domain", 60, 4 },
|
||||
{ "RadBufDecl", "derive", 64, 8 },
|
||||
{ "RadBufDecl", "kv", 72, 4 },
|
||||
{ "RadBuildCtx", "", 0, 104 },
|
||||
{ "RadBuildCtx", "", 0, 112 },
|
||||
{ "RadBuildCtx", "rank", 0, 4 },
|
||||
{ "RadBuildCtx", "world_size", 4, 4 },
|
||||
{ "RadBuildCtx", "max_tok", 8, 8 },
|
||||
@@ -96,6 +97,7 @@
|
||||
{ "RadBuildCtx", "max_out_rows", 80, 8 },
|
||||
{ "RadBuildCtx", "max_audio_frames", 88, 8 },
|
||||
{ "RadBuildCtx", "max_mixed_tok", 96, 8 },
|
||||
{ "RadBuildCtx", "kv_quant", 104, 4 },
|
||||
{ "RadAudioGenBatch", "", 0, 264 },
|
||||
{ "RadAudioGenBatch", "n_lane", 0, 8 },
|
||||
{ "RadAudioGenBatch", "lane", 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 22 and RAD_FORMAT_VER 2. Under
|
||||
* the layout agrees with the table below, taken at RAD_ABI_VERSION 23 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.
|
||||
@@ -57,8 +57,8 @@ std::vector<Row> cpp_rows() {
|
||||
};
|
||||
}
|
||||
|
||||
/* The layout at RAD_ABI_VERSION 22 / RAD_FORMAT_VER 2 (see the file header). */
|
||||
constexpr uint32_t kTableAbi = 22, kTableFormat = 2;
|
||||
/* The layout at RAD_ABI_VERSION 23 / RAD_FORMAT_VER 2 (see the file header). */
|
||||
constexpr uint32_t kTableAbi = 23, kTableFormat = 2;
|
||||
const AbiRow kTable[] = {
|
||||
#include "abi_layout_table.h"
|
||||
};
|
||||
|
||||
@@ -6081,6 +6081,92 @@ TEST(gemma3_dflash2_drafter_taps_and_block) {
|
||||
CHECK_EQ(q.draft_depth, 0);
|
||||
}
|
||||
|
||||
/* --kv-cache-dtype fp8_v4: the trunk's attention cache is E4M3 K (256 bytes), int4 V (128) and
|
||||
* eight f16 scales, 400 bytes a token and head, declared as 25 * 256 / 32 = 200 E4M3 columns so the
|
||||
* core sizes its pages; every trunk op on it bands on kv_dtype fp8_v4. The DFlash2 drafter's own
|
||||
* group stays E4M3 at its head_dim. Without kv_quant the same build is plain fp8. */
|
||||
TEST(qwen35_fp8_fp8_v4_cache_is_400_bytes_a_token_and_head) {
|
||||
MetaKV mk = with_dflash2(q35fp8_meta());
|
||||
auto count = [](const RadBuilder& b, const char* kd) {
|
||||
int n = 0;
|
||||
for (const auto& o : b.ops) if (pstr(&o, "kv_dtype") == kd) ++n;
|
||||
return n;
|
||||
};
|
||||
RadBuilder f8;
|
||||
RadBuildCtx c8 = spec_ctx(0, 1, 7);
|
||||
c8.kv_dtype = RAD_F8E4M3;
|
||||
REQUIRE_EQ(qwen35_fp8::declare(&f8, mk.meta(), &c8), RAD_OK);
|
||||
CHECK_EQ(f8.kv_groups[0].d.head_dim, 256);
|
||||
CHECK_EQ(count(f8, "fp8_v4"), 0);
|
||||
const int n8 = count(f8, "fp8_e4m3");
|
||||
|
||||
RadBuilder b;
|
||||
RadBuildCtx ctx = c8;
|
||||
ctx.kv_quant = RAD_KVQ_V4;
|
||||
REQUIRE_EQ(qwen35_fp8::declare(&b, mk.meta(), &ctx), RAD_OK);
|
||||
CHECK_EQ(b.kv_groups[0].name, std::string("kv_attn"));
|
||||
const RadKVGroupDecl& f = b.kv_groups[0].d;
|
||||
CHECK_EQ(f.kind, RAD_KV_FULL);
|
||||
CHECK_EQ(f.dtype, (uint32_t)RAD_F8E4M3);
|
||||
CHECK_EQ(f.n_head_kv, 4);
|
||||
CHECK_EQ(f.head_dim, 200);
|
||||
const RadKVGroupDecl& d = b.kv_groups.back().d;
|
||||
CHECK_EQ(d.dtype, (uint32_t)RAD_F8E4M3);
|
||||
CHECK_EQ(d.head_dim, 128);
|
||||
const int v4 = count(b, "fp8_v4"), e4 = count(b, "fp8_e4m3");
|
||||
CHECK(v4 > 0);
|
||||
CHECK(e4 > 0); /* the drafter's attention */
|
||||
CHECK_EQ(v4 + e4, n8);
|
||||
CHECK(noted(b, "kv cache fp8_v4"));
|
||||
|
||||
RadArchProbe p{};
|
||||
CHECK_OK(qwen35_fp8::probe(mk.meta(), &p));
|
||||
CHECK_EQ(p.kv_quant_ok, (1 << RAD_KVQ_V4) | (1 << RAD_KVQ_K6V4));
|
||||
}
|
||||
|
||||
/* --kv-cache-dtype k6_v4: int6 K and int4 V, each in groups of 32 with an f16 scale, 352 bytes a
|
||||
* token and head, declared as 176 E4M3 columns; the trunk's ops band on kv_dtype k6_v4 and the
|
||||
* drafter's group stays E4M3. */
|
||||
TEST(qwen35_fp8_k6_v4_cache_is_352_bytes_a_token_and_head) {
|
||||
MetaKV mk = with_dflash2(q35fp8_meta());
|
||||
RadBuilder b;
|
||||
RadBuildCtx ctx = spec_ctx(0, 1, 7);
|
||||
ctx.kv_dtype = RAD_F8E4M3;
|
||||
ctx.kv_quant = RAD_KVQ_K6V4;
|
||||
REQUIRE_EQ(qwen35_fp8::declare(&b, mk.meta(), &ctx), RAD_OK);
|
||||
const RadKVGroupDecl& f = b.kv_groups[0].d;
|
||||
CHECK_EQ(f.dtype, (uint32_t)RAD_F8E4M3);
|
||||
CHECK_EQ(f.head_dim, 176);
|
||||
CHECK_EQ(b.kv_groups.back().d.head_dim, 128);
|
||||
int k6 = 0, v4 = 0, e4 = 0;
|
||||
for (const auto& o : b.ops) {
|
||||
const std::string kd = pstr(&o, "kv_dtype");
|
||||
k6 += kd == "k6_v4"; v4 += kd == "fp8_v4"; e4 += kd == "fp8_e4m3";
|
||||
}
|
||||
CHECK(k6 > 0);
|
||||
CHECK(e4 > 0);
|
||||
CHECK_EQ(v4, 0);
|
||||
CHECK(noted(b, "kv cache k6_v4"));
|
||||
}
|
||||
|
||||
/* libr4d's fp8_v4 and k6_v4 rows are h256/gqa6 only: the probe answers no for another geometry, so the
|
||||
* engine refuses the flag at startup, and declare refuses it too if asked anyway. */
|
||||
TEST(qwen35_fp8_quantised_kv_is_refused_outside_h256_gqa6) {
|
||||
MetaKV mk = q35fp8_meta();
|
||||
mk.m.n_head_kv = 2; /* gqa 12 */
|
||||
RadArchProbe p{};
|
||||
CHECK_OK(qwen35_fp8::probe(mk.meta(), &p));
|
||||
CHECK_EQ(p.kv_quant_ok, 0);
|
||||
for (int q : { (int)RAD_KVQ_V4, (int)RAD_KVQ_K6V4 }) {
|
||||
RadBuilder b;
|
||||
RadBuildCtx ctx = build_ctx();
|
||||
ctx.kv_dtype = RAD_F8E4M3;
|
||||
ctx.kv_quant = q;
|
||||
CHECK_EQ(stderr_of_rc([&] { return qwen35_fp8::declare(&b, mk.meta(), &ctx); }),
|
||||
RAD_E_UNSUPPORTED);
|
||||
}
|
||||
}
|
||||
|
||||
/* The 35B-A3B: a replicated router over every expert, a normalised top-k (norm_topk_prob
|
||||
* defaults on in this family; without it the weights sum to about 0.4), fp8a8 grouped GEMMs over
|
||||
* the expert planes, and the shared expert folded into the gather behind a sigmoid gate. */
|
||||
|
||||
@@ -621,16 +621,21 @@ TEST(the_p2p_mode_is_one_of_three_names) {
|
||||
CHECK_EQ(parse({ "--p2p", "OFF" }, &c), RAD_E_INVAL);
|
||||
}
|
||||
|
||||
TEST(the_kv_cache_dtype_is_one_of_two_names) {
|
||||
TEST(the_kv_cache_dtype_is_one_of_four_names) {
|
||||
Config c;
|
||||
CHECK_EQ(parse({ "--kv-cache-dtype", "bf16" }, &c), RAD_OK);
|
||||
CHECK_EQ(c.kv_cache_dtype, std::string("bf16"));
|
||||
CHECK_EQ(parse({ "--kv-cache-dtype", "fp8" }, &c), RAD_OK);
|
||||
CHECK_EQ(c.kv_cache_dtype, std::string("fp8"));
|
||||
/* Two values only: an "auto" resolving to bf16 would be a second name for the default, and
|
||||
CHECK_EQ(parse({ "--kv-cache-dtype", "fp8_v4" }, &c), RAD_OK);
|
||||
CHECK_EQ(c.kv_cache_dtype, std::string("fp8_v4"));
|
||||
CHECK_EQ(parse({ "--kv-cache-dtype", "k6_v4" }, &c), RAD_OK);
|
||||
CHECK_EQ(c.kv_cache_dtype, std::string("k6_v4"));
|
||||
/* Four values only: an "auto" resolving to bf16 would be a second name for the default, and
|
||||
* each value should be unambiguous in a log. */
|
||||
CHECK_EQ(parse({ "--kv-cache-dtype", "auto" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--kv-cache-dtype", "fp16" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--kv-cache-dtype", "v4" }, &c), RAD_E_INVAL);
|
||||
|
||||
Config d;
|
||||
CHECK_EQ(parse({}, &d), RAD_OK);
|
||||
|
||||
Reference in new issue
Block a user