Archived
libxe2: add_rmsnorm (schema and row); arch/common: the plain norm and the attention gate without unread work
- libxe2 serves `add_rmsnorm` (device-only; libxe2 now publishes its schema, libr4d's spelling): x += a then rmsnorm of the x written in one pass, at rmsnorm's own bf16 partition, so both outputs are byte-identical to the pair here. NormQuantFP8's plain form takes it where it resolves (one launch instead of `add` + `rmsnorm`, ~150 a round). - AttnGatedFP8: under the plain norm an out projection that reads no codes skips the quantiser after the gate's sigmoid + mul. Greedy output 8/8 identical to the previous commit; decode proxy 81.2 -> 82.5 tok/s; declared ops 2046 -> 1902. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f26eec2633
commit
4511822138
5 files changed
+148
-4
No files matched your search
@@ -465,11 +465,20 @@ inline int AttnGatedFP8::declare(RadBuilder* b, Names& nm, const Geom& geom, int
|
||||
RAD_STR("dtype", g.dtype), RAD_STR("act", "sigmoid")),
|
||||
RAD_NOWEIGHTS),
|
||||
{w.qg, w.attn.x}, {w.attn.cq(), w.attn.cs(), w.attn.x});
|
||||
/* Under Geom::plain_norm an out projection that reads no codes (a 4-bit one) takes the
|
||||
* pair alone: the quantiser after it wrote codes nobody read. */
|
||||
bool o_plain = false;
|
||||
if (!op_gq && g.plain_norm) {
|
||||
RAD_ARCH_TRY(o.probe(b, nm, g, nm.f("blk.%d.attn_output", l), { src.o }));
|
||||
o_plain = o.codes_free && o.reads_x;
|
||||
}
|
||||
if (!op_gq && g.head_dim % RAD_FP8_BLOCK == 0) {
|
||||
RAD_ARCH_TRY(gate_pair(decl_b(b, nm.f("blk.%d.attn_gate", l), g.act_dtype,
|
||||
{g.max_tok, q_dim})));
|
||||
RAD_ARCH_TRY(q_gate.declare(b, g, w.attn, q_dim));
|
||||
if (!q_gate.op) return RAD_E_INVAL;
|
||||
if (!o_plain) {
|
||||
RAD_ARCH_TRY(q_gate.declare(b, g, w.attn, q_dim));
|
||||
if (!q_gate.op) return RAD_E_INVAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -389,6 +389,9 @@ struct NormQuantFP8 {
|
||||
* without the codes. */
|
||||
bool x_only = false;
|
||||
rad_op op_add = 0;
|
||||
/* x_only with a residual, where a library serves `add_rmsnorm` (byte-identical to the pair):
|
||||
* the add and the norm as one launch, `op` unused. */
|
||||
rad_op op_addn = 0;
|
||||
Geom gm{};
|
||||
/* The row width, for turning a row slice into element offsets. */
|
||||
int64_t n = 0;
|
||||
@@ -428,6 +431,17 @@ inline int NormQuantFP8::declare(RadBuilder* b, const Geom& g, rad_weight gain,
|
||||
if (x_only) {
|
||||
if (fuse_ar != kArNone || !src || !a.x || !w || n <= 0) return RAD_E_INVAL;
|
||||
const int64_t rows = max_rows > 0 ? max_rows : g.max_tok;
|
||||
if (res && rad_op_declared(b, "add_rmsnorm")) {
|
||||
const rad_op h = RAD_OP(b, "add_rmsnorm",
|
||||
RAD_PARAMS(RAD_RANGE("M", 1, rows), RAD_INT("n", n),
|
||||
RAD_F64("eps", g.eps), RAD_F64("wadd", g.wadd),
|
||||
RAD_STR("dtype", g.dtype)),
|
||||
RAD_WEIGHTS(w));
|
||||
if (h && rad_op_resolved(b, h)) {
|
||||
op_addn = rw(b, h, { res, src }, { res, a.x });
|
||||
if (op_addn) return RAD_OK;
|
||||
}
|
||||
}
|
||||
if (res) {
|
||||
op_add = rw(b, RAD_OP(b, "add",
|
||||
RAD_PARAMS(RAD_RANGE("M", 1, rows), RAD_INT("n", n),
|
||||
@@ -519,6 +533,11 @@ inline void NormQuantFP8::step_plain(RadCtx* c, int64_t T, int64_t r0, int64_t r
|
||||
inline void NormQuantFP8::step(RadCtx* c, int64_t T, int64_t r0, int64_t rows) const {
|
||||
if (rows <= 0) rows = T - r0;
|
||||
if (x_only) {
|
||||
if (op_addn) {
|
||||
RAD_ISSUE_N(c, op_addn, rows, brow_slice(res, r0, rows, n), brow_slice(src, r0, rows, n),
|
||||
RAD_W(w), brow_slice(a.x, r0, rows, n));
|
||||
return;
|
||||
}
|
||||
if (op_add)
|
||||
RAD_ISSUE_N(c, op_add, rows, brow_slice(src, r0, rows, n), brow_slice(res, r0, rows, n),
|
||||
brow_slice(res, r0, rows, n));
|
||||
|
||||
Reference in new issue
Block a user