diff --git a/arch/bailing_hybrid/bailing_hybrid.cpp b/arch/bailing_hybrid/bailing_hybrid.cpp index 324e7c98..71997a5b 100644 --- a/arch/bailing_hybrid/bailing_hybrid.cpp +++ b/arch/bailing_hybrid/bailing_hybrid.cpp @@ -420,9 +420,9 @@ struct Model { Names nm{}; Geom g{}; Shape s{}; - /* The trunk is rotated int8 (rad_fp8.h's linear_is_w8h or linear_is_wnh), its activation codes - * one scale a `trunk_g8` columns: 256 for IQ8R, 128 for the other rotated forms. `norm_fed`: - * the block norms write those codes themselves (rmsnorm_had_quant_i8g is served). */ + /* Whether layer 0's probe found a rotated-int8 trunk, and its activation scale group: see + * rad_fp8.h's trunk_rotation. `norm_fed`: the block norms write those codes themselves + * (rmsnorm_had_quant_i8g is served). */ bool trunk_rot = false, norm_fed = false; int64_t trunk_g8 = RAD_FP8_BLOCK; std::vector layers; @@ -849,8 +849,7 @@ static int declare(RadBuilder* b, const RadModelMeta* meta, const RadBuildCtx* c { RadEncoding enc{}; m.trunk_rot = weight_enc(b, nm.f("blk.0.attn_qkv.weight"), &enc) && - (linear_is_w8h(enc) || linear_is_wnh(enc)); - if (m.trunk_rot) m.trunk_g8 = linear_w8h_group(enc); + trunk_rotation(enc, &m.trunk_g8); } int64_t shared_g8 = m.trunk_g8; if (m.trunk_rot) { diff --git a/arch/common/rad_fp8.h b/arch/common/rad_fp8.h index 8d90b563..092a788c 100644 --- a/arch/common/rad_fp8.h +++ b/arch/common/rad_fp8.h @@ -1081,6 +1081,17 @@ inline bool linear_is_wnh(const RadEncoding& e) { zp->block[1] == RAD_FP8_BLOCK; } +/* Whether a trunk whose first linear probed as `e` is rotated int8 -- w8h or wnh -- and if so + * how wide its activation codes' scale group is: 256 for IQ8R, 128 for the other rotated forms + * (linear_w8h_group spells the rule). An arch learns this by probing layer 0's q projection + * before declaring activations; the probe and the fields are the arch's, the question belongs + * beside the predicates it is made of. */ +inline bool trunk_rotation(const RadEncoding& e, int64_t* g8) { + if (!linear_is_w8h(e) && !linear_is_wnh(e)) return false; + *g8 = linear_w8h_group(e); + return true; +} + /* The OCP-MXFP4 weight LinearFP8 serves at mxfp4a8: e2m1 codes and an E8M0 exponent per [1 x 32], * no transform (libr4d's MXFP4 layout hook). */ enum { RAD_MX_GROUP = 32 }; diff --git a/arch/flint/flint.cpp b/arch/flint/flint.cpp index ee046510..3efebaf7 100644 --- a/arch/flint/flint.cpp +++ b/arch/flint/flint.cpp @@ -53,8 +53,8 @@ struct Model { Geom g{}; int64_t n_ff_expert = 0, n_ff_shared = 0; rad_kvgroup kv_full = 0, kv_win = 0; - /* The trunk is rotated int8 (rad_fp8.h's linear_is_w8h or linear_is_wnh), its activation codes - * one scale a `trunk_g8` columns: 256 for IQ8R, 128 for the other rotated forms. */ + /* Whether layer 0's probe found a rotated-int8 trunk, and its activation scale group: see + * rad_fp8.h's trunk_rotation. */ bool trunk_rot = false; int64_t trunk_g8 = RAD_FP8_BLOCK; @@ -183,17 +183,15 @@ static int declare(RadBuilder* b, const RadModelMeta* meta, const RadBuildCtx* c const int64_t T = g.max_tok, qd = g.q_dim(), kvd = g.kv_dim(); - /* ---- the trunk's stored form, read from layer 0's q projection through that layer's own - * LinearFP8, which then does not map it again; the activations below carry rotated int8 - * codes only for a rotated trunk. */ + /* The trunk's stored form, probed from layer 0's q projection: rad_fp8.h's trunk_rotation + * answers whether it is rotated int8 and how wide the activation codes' scale group is. */ m.layers.resize((size_t)g.n_layer); RAD_ARCH_TRY(m.layers[0].attn.q.probe(b, nm, g, nm.f("blk.0.attn_q"), { nm.ckpt("model.layers.0.self_attn.q_proj.weight") })); { RadEncoding enc{}; m.trunk_rot = weight_enc(b, nm.f("blk.0.attn_q.weight"), &enc) && - (linear_is_w8h(enc) || linear_is_wnh(enc)); - if (m.trunk_rot) m.trunk_g8 = linear_w8h_group(enc); + trunk_rotation(enc, &m.trunk_g8); } MoeFP8::Config mc{};