diff --git a/arch/common/rad_block_mtp_fp8.h b/arch/common/rad_block_mtp_fp8.h index 6ae1f72f..5651c8d0 100644 --- a/arch/common/rad_block_mtp_fp8.h +++ b/arch/common/rad_block_mtp_fp8.h @@ -168,12 +168,16 @@ struct MtpBlockFP8 { int layer = 0; /* absolute, for the KV group's layer_slot lookup */ int64_t rows = 0; /* the widest pass: one row per token of a prefill chunk */ int64_t off_e = 0, off_h = 0; /* the two halves' column offsets inside `c` */ - rad_weight w_tok = 0, w_lm = 0, w_fc = 0, w_norm = 0, w_pre_h = 0, w_pre_e = 0; + rad_weight w_tok = 0, w_lm = 0, w_norm = 0, w_pre_h = 0, w_pre_e = 0; + /* `fc` in whatever form the container stores it: plain bf16 (gemm_nt, as the checkpoint) or a + * 4-bit weight with a zero point (the w4a16 / w4a8i8 GEMMs), read from the bf16 `c` plane. */ + LinearFP8 fc{}; + ActFP8 a_c{}; rad_weight w_dh = 0, w_dhs = 0; /* the 2-bit lm_head and its (scale, zero) plane */ bool q2 = false; /* is the draft round reading it? */ AttnGatedFP8 attn{}; Ffn mlp{}; - rad_op op_gather = 0, op_embed = 0, op_embed_ar = 0, op_pre_h = 0, op_pre_e = 0, op_fc = 0; + rad_op op_gather = 0, op_embed = 0, op_embed_ar = 0, op_pre_h = 0, op_pre_e = 0; /* Media rows over the head's embedding: the history pass embeds the prompt too (one position * on), and an image token's embedding comes from the encoder. Set `media` before declare when * the program has an encoder. */ @@ -209,7 +213,6 @@ inline int MtpBlockFP8::declare(RadBuilder* b, Names& nm, const Geom& geom, RAD_ARCH_TRY(map_copy(b, nm.f("mtp.pre_fc_norm_hidden.weight"), src.pre_norm_hidden)); RAD_ARCH_TRY(map_copy(b, nm.f("mtp.pre_fc_norm_embedding.weight"), src.pre_norm_embedding)); RAD_ARCH_TRY(map_copy(b, nm.f("mtp.norm.weight"), src.norm)); - RAD_ARCH_TRY(map_copy(b, nm.f("mtp.fc.weight"), src.fc)); w_pre_h = decl_w(b, nm.f("mtp.pre_fc_norm_hidden.weight"), RAD_F32, {g.n_embd}, RAD_ACCESS_PER_TOKEN, RAD_SHARD_NONE, grp_layer(l)); @@ -217,8 +220,6 @@ inline int MtpBlockFP8::declare(RadBuilder* b, Names& nm, const Geom& geom, RAD_ACCESS_PER_TOKEN, RAD_SHARD_NONE, grp_layer(l)); w_norm = decl_w(b, nm.f("mtp.norm.weight"), RAD_F32, {g.n_embd}, RAD_ACCESS_PER_TOKEN, RAD_SHARD_NONE, grp_layer(l)); - w_fc = decl_w(b, nm.f("mtp.fc.weight"), RAD_BF16, {g.n_embd, 2 * g.n_embd}, - RAD_ACCESS_PER_TOKEN, RAD_SHARD_NONE, grp_layer(l)); /* Separate gather_rows and embed_lookup ops over the trunk's buffers and weights, because * they write different buffers and liveness comes from each op's read/write sets. */ @@ -257,11 +258,9 @@ inline int MtpBlockFP8::declare(RadBuilder* b, Names& nm, const Geom& geom, RAD_WEIGHTS(w_pre_e)), {w.e}, {w.c}); - op_fc = rw(b, RAD_OP(b, "gemm_nt", - RAD_PARAMS(RAD_RANGE("M", 1, rows), RAD_INT("N", g.n_embd), - RAD_INT("K", 2 * g.n_embd), RAD_STR("dtype", g.dtype)), - RAD_WEIGHTS(w_fc)), - {w.c}, {w.x}); + a_c.x = w.c; + RAD_ARCH_TRY(fc.declare(b, nm, g, "mtp.fc", g.n_embd, 2 * g.n_embd, RAD_SHARD_NONE, grp_layer(l), + { src.fc }, a_c, w.x, rows)); RAD_ARCH_TRY(attn.declare(b, nm, g, l, kv, rotary_dim, w.attn, src.attn)); @@ -419,7 +418,7 @@ inline void MtpBlockFP8::step(RadCtx* c, const RadBatch* batch) const { RAD_ISSUE(c, op_pre_h, brows(w.hout, T), RAD_W(w_pre_h), bcol(w.c, off_h, g.n_embd, T)); RAD_ISSUE(c, op_pre_e, brows(w.e, T), RAD_W(w_pre_e), bcol(w.c, off_e, g.n_embd, T)); - RAD_ISSUE(c, op_fc, brows(w.c, T), RAD_W(w_fc), brows(w.x, T)); + fc.step(c, a_c, w.x, T); /* A history pass with no drafting rows (every prefill chunk but a prompt's last) only needs * K and V. `n_draft_out` is the same on every rank, so skipped collectives match. */