arch/common: a clamped gated product writes rotated int8 codes

GateQuantFP8's clamped branch (swiglu_clamped, swiglu_step) refused an output of rotated int8
codes, since its quantiser was the unrotated quant_act_i8g. A down projection stored at i8a8h reads
rotated codes, so a model that clamps its SwiGLU had no form with int8 activations.

The branch now picks had_quant_act_i8g for rotated int8 codes, at the consumer's group (128, or 256
through had_quant_act_iq8r for IQ8R), the quantiser the rotated trunk's other inputs use. The clamp
still writes the bf16 plane first: one launch more than the unclamped gated_had_quant_i8g, in the
clamped layers only. E4M3 and plain int8 outputs are unchanged.
This commit is contained in:
keptn42 authored and StillDeadcode committed 2026-11-17 18:26:13 +01:00
1 parent 79ac2bd50d
commit 2e558e2dcc
1 file changed
+10 -5
+10 -5
View File
@@ -614,11 +614,14 @@ inline int GateQuantFP8::declare(RadBuilder* b, const Geom& g, rad_buf gate_up,
return op_q ? RAD_OK : RAD_E_INVAL;
}
if (clipped) {
/* No rotated int8 form: its quantiser would be quant_act_i8g, unrotated; and no clamp
* with `silu_only`. */
if (!gate_up || !a.x || n <= 0 || rot || silu_only || (a.q8_fed && a.q8_rot) ||
std::strcmp(act_name, "silu"))
/* The clamp writes the bf16 plane and a quantiser reads it: E4M3, plain int8, or the
* rotated int8 codes an i8a8h consumer reads (had_quant_act_i8g at that consumer's
* group, the quantiser the rotated trunk's other inputs use). Against the unclamped
* gated_had_quant_i8g that is one launch more, in the clamped layers only. No clamp
* with `silu_only`, and none into a rotated E4M3 consumer (`rot`). */
if (!gate_up || !a.x || n <= 0 || rot || silu_only || std::strcmp(act_name, "silu"))
return RAD_E_INVAL;
const bool hi8 = a.q8_fed && a.q8_rot;
const int64_t rows = max_rows > 0 ? max_rows : g.max_tok;
if (fuse_clamped && !step && !bf16 && !a.q8_fed && a.cq() && a.cs() &&
rad_op_declared(b, "swiglu_clamped_quant_fp8")) {
@@ -644,9 +647,11 @@ inline int GateQuantFP8::declare(RadBuilder* b, const Geom& g, rad_buf gate_up,
{ gate_up }, { a.x });
if (!bf16) {
if (!a.cq() || !a.cs()) return RAD_E_INVAL;
const char* qn = hi8 ? "had_quant_act_i8g" : a.q8_fed ? "quant_act_i8g"
: "quant_act_fp8";
op_quant =
rw(b,
RAD_OP(b, a.q8_fed ? "quant_act_i8g" : "quant_act_fp8",
RAD_OP(b, qn,
RAD_PARAMS(RAD_RANGE("M", 1, rows), RAD_INT("n", n),
RAD_INT("group", a.cg()), RAD_STR("dtype", g.dtype)),
RAD_NOWEIGHTS),