qwen35_w8a8: qwen35_fp8.cpp built for a rotated int8 trunk

A third build of the qwen35 source, as qwen35moe_fp8 is, claiming (qwen35, w8a8_fwht128).
Behind QWEN35_W8A8: check_format's method and fmt, a probe of the first delta-net input
projection that learns the trunk is rotated int8 before the activations are declared (and refuses
one that is not, plain int8 included: the descriptor names the rotation), and the plugin
identity; the four trunk activations then carry int8 code pairs.

It declines imported checkpoints (RAD_ARCH_SERVES_IMPORTS(0)): as the family's second quantised
plugin it would make every imported Qwen3.8 release (Quark, ParoQuant, GPTQ, NVFP4) refuse, so
those stay with qwen35_fp8.

arch_test: every trunk linear an i8a8h GEMM behind its own quantiser at one and two ranks, the
refusals (no int8 trunk, a plain one, another format, no fmt), lint clean with the MTP head and
with DFlash2, and two ArchCases (pinned graphs; libref's vocabulary serves it at one rank).
shipped_plugins_test lists the new key and holds each shipped family to at most one plugin that
takes imports. ARCHITECTURES.md and GUIDE.md list the plugin.

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-19 10:42:13 +02:00
1 parent 2ac0d966b3
commit 5d11c7c200
7 files changed
+298 -7

No files matched your search

+80 -6
View File
@@ -45,9 +45,30 @@
* and includes this file. Every difference is behind `#if QWEN35_MOE`: the expert-count check, the
* routing geometry read from metadata, the block's buffers, the per-layer source names, the MTP
* head's feed-forward, and the plugin identity. */
/* ============================== AND A THIRD: qwen35_w8a8 ==============================
*
* `qwen35_w8a8` is the dense build with an int8 trunk: every large linear `i8*bf16[1x128]/fwht128`,
* rotated by a 128-wide Hadamard and served at i8a8h, each quantising its own input from the bf16
* plane (LinearFP8's int8 branch). The producers already write that plane, as they do for a rotated
* MXFP4 linear, so the graph is this one. It is a plugin of its own because the quantisation
* descriptor is half of the selection key: `w8a8_fwht128`, which names the rotation, so a plain
* int8 trunk is refused.
*
* Its differences are behind `#if QWEN35_W8A8`: check_format's method, the probe that learns the
* trunk is int8 before the activations are declared (and refuses one that is not), and the plugin
* identity. The int8 activation pairs follow from the probe. */
#ifndef QWEN35_MOE
#define QWEN35_MOE 0
#endif
#ifndef QWEN35_W8A8
#define QWEN35_W8A8 0
#endif
#if QWEN35_MOE && QWEN35_W8A8
#error "qwen35_w8a8 is the dense build; a routed int8 trunk is not a format this file serves"
#endif
/* The plugin's name for a message, expanded once more so it is QWEN35_NS's value. */
#define QWEN35_STR_X(x) #x
#define QWEN35_STR(x) QWEN35_STR_X(x)
#ifndef QWEN35_NS
#define QWEN35_NS qwen35_fp8
#endif
@@ -101,6 +122,10 @@ struct Model {
rad_kvgroup kv_full = 0, kv_state = 0, kv_conv = 0;
/* The trunk's linears are int8 (LinearFP8::i8), learned before the activations are declared
* because it decides whether they carry an int8 code pair. Only qwen35_w8a8 sets it. */
bool trunk_i8 = false;
/* the residual stream and the two vocabulary edges */
rad_buf b_x = 0, b_hout = 0, b_logits = 0;
ActFP8 a_h{};
@@ -178,6 +203,18 @@ static Model g_model[MAX_RANKS];
static int check_format(const RadModelMeta* meta) {
const char* method = rad_meta_gets(meta, "quantization_config.quant_method", nullptr);
const char* fmt = rad_meta_gets(meta, "quantization_config.fmt", nullptr);
#if QWEN35_W8A8
/* The format the convert stated (the recipe's --set keys); the trunk probe in declare() holds
* the weights to it. */
if (!method || std::strcmp(method, "w8a8") != 0 || !fmt || std::strcmp(fmt, "fwht128") != 0) {
fprintf(stderr, "radiance: qwen35_w8a8 serves a container converted for an int8 trunk "
"(quant_method 'w8a8', fmt 'fwht128': data/recipes/"
"q38-27b-w8a8-df2.recipe's --set keys); this one says '%s' / '%s'.\n",
method ? method : "(none)", fmt ? fmt : "(none)");
return RAD_E_UNSUPPORTED;
}
return RAD_OK;
#else
const char* block = rad_meta_gets(meta, "quantization_config.weight_block_size", nullptr);
if (method && std::strcmp(method, "fp8") != 0) {
@@ -204,6 +241,7 @@ static int check_format(const RadModelMeta* meta) {
}
}
return RAD_OK;
#endif
}
/* The DFlash2 drafter: its geometry, KV group, buffers and block.
@@ -406,8 +444,8 @@ static int declare(RadBuilder* b, const RadModelMeta* meta, const RadBuildCtx* c
}
#else
if (meta->n_expert > 0) {
fprintf(stderr, "radiance: qwen35_fp8 refuses a checkpoint with %lld experts; that is "
"qwen35moe\n", (long long)meta->n_expert);
fprintf(stderr, "radiance: " QWEN35_STR(QWEN35_NS) " refuses a checkpoint with %lld "
"experts; that is qwen35moe\n", (long long)meta->n_expert);
return RAD_E_UNSUPPORTED;
}
#endif
@@ -544,13 +582,41 @@ static int declare(RadBuilder* b, const RadModelMeta* meta, const RadBuildCtx* c
cd.conv_width = gc.conv_width;
m.kv_conv = rad_decl_kv_group(b, nm.f("kv_gdn_conv"), &cd);
#if QWEN35_W8A8
/* ---- the trunk's stored format, read from the first delta-net layer's input projection as
* qwen4exp_fp8 reads its own: the activations below carry an int8 code pair only for an int8
* trunk, and this build serves only the rotated one its descriptor names. The probe maps the
* weight through the layer's own LinearFP8, which then does not map it again; the resize
* before the layer loop keeps the layers sized here. */
m.layers.resize((size_t)m.n_main);
for (int64_t l = 0; l < m.n_main; ++l) {
if (is_full_attention(l, interval)) continue;
const char* pre = "model.language_model.layers";
RAD_ARCH_TRY(m.layers[(size_t)l].gdn.in.probe(
b, nm, g, nm.f("blk.%lld.ssm_inz", (long long)l),
{ nm.ckpt("%s.%lld.linear_attn.in_proj_qkv.weight", pre, (long long)l),
nm.ckpt("%s.%lld.linear_attn.in_proj_z.weight", pre, (long long)l) }));
RadEncoding enc{};
m.trunk_i8 = weight_enc(b, nm.f("blk.%lld.ssm_inz.weight", (long long)l), &enc) &&
linear_is_w8h(enc);
break;
}
if (!m.trunk_i8) {
fprintf(stderr, "radiance: qwen35_w8a8 serves a rotated int8 trunk (i8 codes with a bf16 "
"scale a [1 x 128], /fwht128), and this container's first delta-net input "
"projection is not one; convert with "
"data/recipes/q38-27b-w8a8-df2.recipe\n");
return RAD_E_DTYPE;
}
#endif
/* ---- activation buffers. Every activation that feeds a GEMM has an fp8 copy: an E4M3 plane
* of the same shape and an f32 scale plane with one column per 128. They are transients that
* liveness analysis can share, but not free: the largest, `ffn`'s, is 8192 x 17408 bytes
* (143 MiB) beside its 285 MiB bf16 buffer. */
m.b_x = decl_b(b, nm.f("x"), g.act_dtype, {g.max_tok, g.n_embd});
m.a_h.x = decl_b(b, nm.f("h"), g.act_dtype, {g.max_tok, g.n_embd});
RAD_ARCH_TRY(m.a_h.declare_qs(b, nm, g, "h", g.n_embd));
RAD_ARCH_TRY(m.a_h.declare_qs(b, nm, g, "h", g.n_embd, 0, m.trunk_i8));
m.b_qg = decl_b(b, nm.f("attn_qg"), g.act_dtype, {g.max_tok, g.n_head, 2 * g.head_dim});
m.b_k = decl_b(b, nm.f("attn_k"), g.act_dtype, {g.max_tok, kv_dim});
@@ -566,7 +632,7 @@ static int declare(RadBuilder* b, const RadModelMeta* meta, const RadBuildCtx* c
* it must not share storage with transients. */
m.b_rope_cs = decl_b(b, nm.f("rope_cs"), RAD_F32, {rope_table_rows(g), m.n_rot},
RAD_BUF_PERSIST);
RAD_ARCH_TRY(m.a_attn.declare_qs(b, nm, g, "attn_out", q_dim));
RAD_ARCH_TRY(m.a_attn.declare_qs(b, nm, g, "attn_out", q_dim, 0, m.trunk_i8));
/* `gdn_in` is conv_dim + v_dim, not in_dim: a and b have their own buffer because the
* checkpoint keeps them bf16, while the fp8 output gate is the tail of this one
@@ -586,7 +652,7 @@ static int declare(RadBuilder* b, const RadModelMeta* meta, const RadBuildCtx* c
/* Rank 3, as libr4d's scan and recurrent kernels require; the quantiser reads dim 0 as the
* row. */
m.a_go.x = decl_b(b, nm.f("gdn_o"), g.act_dtype, {g.max_tok, gc.n_head_v, gc.head_v});
RAD_ARCH_TRY(m.a_go.declare_qs(b, nm, g, "gdn_o", v_dim));
RAD_ARCH_TRY(m.a_go.declare_qs(b, nm, g, "gdn_o", v_dim, 0, m.trunk_i8));
#if QWEN35_MOE
/* ---- the routing geometry, read here so a refusal names the container's key. `n_ff` is
@@ -658,7 +724,7 @@ static int declare(RadBuilder* b, const RadModelMeta* meta, const RadBuildCtx* c
#else
m.b_gate_up = decl_b(b, nm.f("gate_up"), g.act_dtype, {g.max_tok, 2 * g.n_ff});
m.a_ffn.x = decl_b(b, nm.f("ffn"), g.act_dtype, {g.max_tok, g.n_ff});
RAD_ARCH_TRY(m.a_ffn.declare_qs(b, nm, g, "ffn", g.n_ff));
RAD_ARCH_TRY(m.a_ffn.declare_qs(b, nm, g, "ffn", g.n_ff, 0, m.trunk_i8));
#endif
m.b_hout = decl_b(b, nm.f("h_out"), g.act_dtype, {g.max_logit_rows, g.n_embd});
@@ -1137,6 +1203,14 @@ QWEN35_PLUGIN_X(QWEN35_NS, QWEN35_ARCH_ID, "fp8_e4m3", "0.1.0",
"dense graph with a routed feed-forward (256 experts, 8 a token, and a shared "
"expert), gated attention over paged KV every fourth layer and gated delta net "
"between")
#elif QWEN35_W8A8
QWEN35_PLUGIN_X(QWEN35_NS, QWEN35_ARCH_ID, "w8a8_fwht128", "0.1.0",
"Qwen3.5 / 3.6 / 3.8 dense (0.8B..27B), an int8 trunk: i8 weights with a bf16 "
"scale a 128 of K, rotated by a 128-wide Hadamard, against int8 activations the "
"same rotation quantises; gated attention over paged KV every fourth layer and "
"gated delta net between")
/* An imported checkpoint is never a rotated int8 trunk: qwen35_fp8 serves those. */
RAD_ARCH_SERVES_IMPORTS(0)
#else
QWEN35_PLUGIN_X(QWEN35_NS, QWEN35_ARCH_ID, "fp8_e4m3", "0.1.0",
"Qwen3.5 / 3.6 / 3.8 dense (0.8B..27B), block-scaled fp8 weights and fp8 "
+10
View File
@@ -0,0 +1,10 @@
# Built in radiance's tree, or standalone against an installed radiance
# (`cmake -S arch/qwen35_w8a8 -B build -DCMAKE_PREFIX_PATH=<radiance prefix>`); see cmake/RadAddPlugin.cmake.
if(NOT COMMAND rad_add_plugin)
cmake_minimum_required(VERSION 3.21)
project(qwen35_w8a8 LANGUAGES CXX)
find_package(radiance REQUIRED)
rad_plugin_defaults()
endif()
rad_add_plugin(qwen35_w8a8 architectures SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/qwen35_w8a8.cpp)
+19
View File
@@ -0,0 +1,19 @@
/* qwen35_w8a8 -- Qwen3.5 / 3.6 / 3.8 dense with an int8 trunk: i8 weights with a bf16 scale a 128
* of K, rotated by a 128-wide Hadamard, against int8 activations quantised under the same rotation.
*
* This is arch/qwen35_fp8/qwen35_fp8.cpp built again, as qwen35moe_fp8 is: the same gated
* attention, gated delta net, MLP, layer schedule, rope, vocabulary edges, drafters and vision
* tower. A linear's weight encoding makes it int8 (arch/common/rad_fp8.h: LinearFP8):
* `i8*bf16[1x128]/fwht128` is gemm_nt_q at i8a8h behind had_quant_act_i8g, each linear quantising
* its own input from the bf16 plane its producer already writes. The places this build differs are
* behind `#if QWEN35_W8A8` in that file.
*
* A plugin of its own rather than qwen35_fp8 serving any encoding it is handed, because the
* quantisation descriptor is half of the selection key (spec §2.4): a container converted with
* data/recipes/q38-27b-w8a8-df2.recipe says `w8a8_fwht128`.
*/
#define QWEN35_W8A8 1
#define QWEN35_NS qwen35_w8a8
#define QWEN35_ARCH_ID "qwen35"
#include "../qwen35_fp8/qwen35_fp8.cpp"