Archived
arch/gemma4: the DFlash head reads a block-fp8 copy of the table where the container holds one
The drafter's head was `gemm_nt` over the target's bf16 table -- 352 MiB a rank at tp 4, every draft
pass, 566 us of a 26B-A4B decode step under --profile-ops on 4x R9700: the widest read on the draft
path, and the "first thing to change once the model runs" its own comment named.
A container may now hold the table a second time as `dflash.draft_head.weight`, block fp8 -- one
checkpoint tensor, two logical weights, as rad_block_dflash2.h does it -- made by the recipe line
dflash.draft_head.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16
which the three gemma4-26b-a4b -df recipes now carry. Where the copy is there, the head is
quant_act_fp8 over the gathered rows and gemm_nt_q over the copy at fp8a8: half the bytes, for 176
MiB a rank more. The copy is row-sharded exactly as the table, so a rank's rows are the same
vocabulary slice and row_topk's vocab_off, the all_gather and pair_argmax are unchanged. Drafts are
verified, so the coarser logits change what is proposed and never what is accepted --
draft_n_accepted says whether they propose worse; there is no rerank against the bf16 table yet.
Where the copy is not there -- every container converted before this, or one whose recipe made it
something other than block fp8 -- the head reads the bf16 table exactly as before. The decision is
the stored encoding's (weight_enc on the copy's name), and the copy's name map entry alone writes
nothing: rad-convert walks the declared weights. The startup note names the head in use. The
block-fp8 test moves to one helper, which the routed experts' encoding check now uses too.
arch_test: with the copy's encoding block fp8, the copy is declared and the head is gemm_nt_q over
it from the quantised rows; without, nothing is declared and the head is gemm_nt over the table;
a draft pass issues the head once either way. ARCHITECTURES.md says so.
Not yet run on the cards; it needs a container converted with the new recipe line.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
73c3dc38be
commit
743b7e1a6a
7 files changed
+157
-20
No files matched your search
@@ -3759,3 +3759,49 @@ TEST(gemma4_scales_the_routing_weights_in_one_launch) {
|
||||
if (o.resolved) CHECK(o.uses_declared);
|
||||
}
|
||||
}
|
||||
|
||||
/* The drafter's head reads the container's block-fp8 copy of the target's table where it holds one
|
||||
* -- `dflash.draft_head.weight` -- through quant_act_fp8 and gemm_nt_q, and the bf16 table through
|
||||
* gemm_nt where it does not. The copy is declared only in the first case, so a container converted
|
||||
* without the recipe line is served exactly as before. */
|
||||
TEST(gemma4_dflash_head_reads_the_fp8_copy_where_the_container_holds_one) {
|
||||
const std::vector<const char*> keys = g4df_keys(), vals = g4df_vals();
|
||||
for (int fp8 = 0; fp8 < 2; ++fp8) {
|
||||
RadModelMeta meta = gemma4_moe_meta();
|
||||
meta.n_kv = (int)keys.size();
|
||||
meta.kv_key = keys.data();
|
||||
meta.kv_val = vals.data();
|
||||
RadBuilder b;
|
||||
if (fp8)
|
||||
b.encs = { { "dflash.draft_head", rad_enc_affine(RAD_F8E4M3, RAD_BF16, 128, 128) } };
|
||||
RadBuildCtx ctx = build_ctx();
|
||||
ctx.max_spec = 15;
|
||||
CHECK_OK(gemma4::declare(&b, &meta, &ctx));
|
||||
CHECK_EQ(find_w(b, "dflash.draft_head.weight") != nullptr, fp8 == 1);
|
||||
|
||||
const int dlog = buf_named(b, "df_dlog"), selh = buf_named(b, "df_selh");
|
||||
REQUIRE(dlog > 0 && selh > 0);
|
||||
const RecOp* head = nullptr;
|
||||
for (const auto& o : b.ops)
|
||||
if (o.resolved &&
|
||||
std::find(o.writes.begin(), o.writes.end(), (rad_buf)dlog) != o.writes.end())
|
||||
head = &o;
|
||||
REQUIRE(head != nullptr);
|
||||
CHECK_EQ(head->op, std::string(fp8 ? "gemm_nt_q" : "gemm_nt"));
|
||||
const bool reads_selh =
|
||||
std::find(head->reads.begin(), head->reads.end(), (rad_buf)selh) != head->reads.end();
|
||||
CHECK_EQ(reads_selh, fp8 == 0);
|
||||
|
||||
/* and a draft pass issues it */
|
||||
RadCtx c; c.b = &b; c.rank = 0; c.world = 1;
|
||||
RadBatch batch = decode_batch();
|
||||
batch.draft_pass = 1;
|
||||
c.batch = &batch;
|
||||
gemma4::step(&c, &batch);
|
||||
CHECK(c.step_fail.empty());
|
||||
int head_issues = 0;
|
||||
for (const auto& i : c.issues)
|
||||
if (b.op_of(i.op) == head) ++head_issues;
|
||||
CHECK_EQ(head_issues, 1);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user