libr4d: rmsnorm_had_quant_i8g, ar_rmsnorm_had_quant_i8g, gated_had_quant_i8g -- producers that write rotated int8 codes

An i8a8h linear quantises its own input from the bf16 plane with had_quant_act_i8g, so a decode
step of the int8 Qwen3.8-27B issues 288 of them after the norms and the silu product. These three
device ops write those codes from the producer instead:

- rmsnorm_had_quant_i8g and ar_rmsnorm_had_quant_i8g (exact and wire=6): norm_quant_row gains an
  HI8 form, r4d_fwht_wave<128> and then quant_group<I8>, on the lane mapping, rotation and rounding
  had_quant_act_i8g uses.
- gated_had_quant_i8g: the gated kernel's existing ROT && I8 instance, which the shim refused.

Each writes the bytes its producer followed by had_quant_act_i8g writes. They are ops of their own,
not a flag on the fp8 forms, as gated_had_quant_fp8 is: a rotated and a plain quantiser must not be
substitutable. n % 128 == 0; device only, so a graph falls back to the pair where they are not
declared.

r4d_selftest checks each against its pair byte for byte (plain, with the residual add and the
residual it leaves, and the gated product) and that each refuses E4M3 codes. The all-reduce form
is skipped like ar_rmsnorm_quant_fp8, since it needs a peer rank.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
eddie168168andClaude Opus 5.5 authored and StillDeadcode committed 2026-10-21 09:25:39 +02:00
1 parent 3ef9ce33ae
commit d999524054
8 files changed
+430 -50

No files matched your search

+55
View File
@@ -1178,6 +1178,24 @@ extern "C" int r4d_shape_ar_rmsnorm_quant_fp8(const RadParam* p, int n_p, int op
R4D_PICK(l);
}
extern "C" int r4d_shape_ar_rmsnorm_had_quant_i8g(const RadParam* p, int n_p, int operand,
RadOpdDesc* out) {
const int64_t M = pi(p, n_p, "M");
const int64_t n = pi(p, n_p, "n");
const int64_t g = pi(p, n_p, "group", R4D_FP8_BLOCK);
if (g != R4D_FP8_BLOCK) return RAD_E_UNSUPPORTED;
const RadOpdDesc l[] = {
opd((uint32_t)RAD_BF16, M, n), /* inout: the message and the input */
opd((uint32_t)RAD_BF16, M, n),
opd((uint32_t)RAD_F32, n), /* f32 or bf16; the shim reads the operand's own */
opd((uint32_t)RAD_I8, M, n),
opd((uint32_t)RAD_F32, M, (n + g - 1) / g),
opd((uint32_t)RAD_BF16, M, n),
};
R4D_PICK(l);
}
/* ==========================================================================================
* GEMM, dequant and the row top-R (shims in the r4d_gemm_*.hip units, r4d_dequant_w4_bf16.hip and
* r4d_rowtopk_bf16.hip).
@@ -1891,6 +1909,43 @@ extern "C" int r4d_shape_gated_quant_fp8(const RadParam* p, int n_p, int operand
R4D_PICK(l);
}
/* The `_had_quant_i8g` twins: the same operands with int8 codes (had_quant_act_i8g's). */
extern "C" int r4d_shape_rmsnorm_had_quant_i8g(const RadParam* p, int n_p, int operand,
RadOpdDesc* out) {
const int64_t M = pi(p, n_p, "M");
const int64_t n = pi(p, n_p, "n");
const int64_t g = pi(p, n_p, "group", R4D_FP8_BLOCK);
const uint32_t D = dt_act(p, n_p, "dtype");
if (g != R4D_FP8_BLOCK) return RAD_E_UNSUPPORTED;
const RadOpdDesc l[] = {
opd(D, M, n),
opd(D, M, n),
opd((uint32_t)RAD_F32, n),
opd((uint32_t)RAD_I8, M, n),
opd((uint32_t)RAD_F32, M, (n + g - 1) / g),
opd(D, M, n),
};
R4D_PICK(l);
}
extern "C" int r4d_shape_gated_had_quant_i8g(const RadParam* p, int n_p, int operand,
RadOpdDesc* out) {
const int64_t M = pi(p, n_p, "M");
const int64_t n = pi(p, n_p, "n");
const int64_t g = pi(p, n_p, "group", R4D_FP8_BLOCK);
const uint32_t D = dt_act(p, n_p, "dtype");
if (g != R4D_FP8_BLOCK) return RAD_E_UNSUPPORTED;
const RadOpdDesc l[] = {
opd(D, M, 2 * n), /* gate then up in one buffer */
opd((uint32_t)RAD_I8, M, n),
opd((uint32_t)RAD_F32, M, (n + g - 1) / g),
opd(D, M, n),
};
R4D_PICK(l);
}
extern "C" int r4d_shape_gate_quant_fp8(const RadParam* p, int n_p, int operand,
RadOpdDesc* out) {