Archived
fp8: the trunk-rotation question lives beside its predicates
"The trunk is rotated int8 (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" was written twice, verbatim, in flint's and bailing_hybrid's field declarations, and the probe that answers it -- weight_enc, the two predicates, linear_w8h_group -- was re-typed at both arches' layer-0 sites. museglimmer_ct carries the near-variant; its question is narrower (exactly-IQ8R, not rotated-at-all), so it keeps its own predicate. rad_fp8.h now answers it once: trunk_rotation(enc, &g8), beside the predicates it is made of, so the group-width semantics travel with the forms that define them instead of with three copies of a comment. The two call sites shrink to the probe and the named question. Standards axis of the 2.1.0 review pass, finding 4.
This commit is contained in:
1 parent
8ac613ddb9
commit
a8d82678fa
3 files changed
+20
-12
No files matched your search
@@ -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<Layer> 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) {
|
||||
|
||||
@@ -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 };
|
||||
|
||||
@@ -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{};
|
||||
|
||||
Reference in new issue
Block a user