diff --git a/arch/qwen35_fp8/qwen35_fp8.cpp b/arch/qwen35_fp8/qwen35_fp8.cpp index ce4e6659..c1b80735 100644 --- a/arch/qwen35_fp8/qwen35_fp8.cpp +++ b/arch/qwen35_fp8/qwen35_fp8.cpp @@ -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 " diff --git a/arch/qwen35_w8a8/CMakeLists.txt b/arch/qwen35_w8a8/CMakeLists.txt new file mode 100644 index 00000000..5a9963b8 --- /dev/null +++ b/arch/qwen35_w8a8/CMakeLists.txt @@ -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=`); 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) diff --git a/arch/qwen35_w8a8/qwen35_w8a8.cpp b/arch/qwen35_w8a8/qwen35_w8a8.cpp new file mode 100644 index 00000000..028b14d0 --- /dev/null +++ b/arch/qwen35_w8a8/qwen35_w8a8.cpp @@ -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" diff --git a/docs/ARCHITECTURES.md b/docs/ARCHITECTURES.md index 04a4b4ad..cec30f76 100644 --- a/docs/ARCHITECTURES.md +++ b/docs/ARCHITECTURES.md @@ -11,6 +11,7 @@ plugin claims. | `arch/llama_dense_fp8` | `llama` | *(empty)* | the same graph from a bf16 checkpoint, linears made block fp8 by a recipe or kept bf16. MiniCPM5-2B | | `arch/qwen35_bf16` | `qwen35` | *(empty)* | the Qwen3.5/3.6/3.8 dense hybrid, served bf16 | | `arch/qwen35_fp8` | `qwen35` | `fp8_e4m3` | the same, block-scaled FP8 weights and activations | +| `arch/qwen35_w8a8` | `qwen35` | `w8a8_fwht128` | `qwen35_fp8` with an int8 trunk: i8 weights with a bf16 scale per 128 of K, rotated by a 128-wide Hadamard, against int8 activations under the same rotation (`data/recipes/q38-27b-w8a8-df2.recipe`) | | `arch/qwen35moe_fp8` | `qwen35moe` | `fp8_e4m3` | `qwen35_fp8` with the feed-forward routed | | `arch/qwen4exp_fp8` | `qwen4exp` | *(empty)* | Qwen4-Exp (Qwen3.8-Flash-Next), a bf16 checkpoint quantised at convert | | `arch/lfm2_bf16` | `lfm2` | *(empty)* | LiquidAI's LFM2 and LFM2-VL, bf16, one rank | @@ -235,6 +236,29 @@ and every difference is behind `#if QWEN35_MOE` in the shared source. It is a se unit rather than a branch on `n_expert` because the id is half the selection key, and one `.so` cannot claim both ids. +## `qwen35_w8a8` + +The dense build again, behind `#if QWEN35_W8A8`, for a container `data/recipes/q38-27b-w8a8-df2.recipe` +converts from the bf16 checkpoint: the trunk's linears (the set Qwen's FP8 release quantises) as +`i8*bf16[1x128]/fwht128`, each 128 of K rotated by the unnormalised Hadamard before rounding, served +by `gemm_nt_q` at `i8a8h`. The descriptor `w8a8_fwht128` is what the convert's `--set` keys state; +a probe of the first delta-net input projection holds the weights to it before the activations are +declared, since only an int8 trunk gives them an int8 code pair. The descriptor names the rotation, so +a plain int8 trunk is refused. + +- **The 1/128 is the weight's.** `had_quant_act_i8g` rotates the activation and folds nothing, as + `had_quant_act_fp8` does; the per-row `had_*_i8` forms fold 1/sqrt(128) into the activation's + scale and against this weight give an output sqrt(128) too small. +- **The encoding is the only guard.** Rotated and plain int8 have the same bytes and extents, and + the rotated weight against the plain quantiser measures rel_l2 ~1.0 (r4d_selftest, `i8a8h_rot`), + so each dtype's layout hook takes only its own transform. +- **Each rotated linear quantises its own input** from the bf16 plane its producer writes: q, k and + v quantise one input three times, and no producer writes rotated codes yet. The MLP's gated fold + is an fp8a8 tile over E4M3 codes, so an int8 gate_up runs the pair. +- **It declines imported checkpoints** (`RAD_ARCH_SERVES_IMPORTS(0)`). An imported quantisation + goes to the family's one quantised plugin, and a second one would refuse every Quark, ParoQuant, + GPTQ or NVFP4 Qwen3.8 release; they stay with `qwen35_fp8`. + --- # `qwen4exp`: Qwen4-Exp / Qwen3.8-Flash-Next diff --git a/docs/GUIDE.md b/docs/GUIDE.md index 5d1a6bf6..c7d00abf 100644 --- a/docs/GUIDE.md +++ b/docs/GUIDE.md @@ -268,6 +268,7 @@ and runs. | `llama_fp8`, `llama_dense_fp8` | LLaMA-shaped decoders: MiniCPM5, Llama 3, anything reporting `model_type: llama` | | `qwen35_bf16` | Qwen3.5 / 3.6 / 3.8 dense (0.8B–27B), bf16 | | `qwen35_fp8` | the same, block-scaled fp8 | +| `qwen35_w8a8` | the same, an int8 trunk rotated by a 128-wide Hadamard | | `qwen35moe_fp8` | Qwen3.5 / 3.6 MoE (35B-A3B), 256 experts, 8 a token | | `qwen4exp_fp8` | Qwen4-Exp / Qwen3.8-Flash-Next: hybrid Gated DeltaNet + gated attention, 512 experts | | `gemma4` | Gemma 4 text decoders (26B-A4B MoE and the dense members): bf16 trunk, routed experts bf16 or block fp8, and the DFlash drafter | diff --git a/tests/arch_test.cpp b/tests/arch_test.cpp index 55a96735..29aa356e 100644 --- a/tests/arch_test.cpp +++ b/tests/arch_test.cpp @@ -464,6 +464,12 @@ extern "C" int rad_memset_async(void* dst, int value, int64_t bytes, RadStream s #undef QWEN35_NS #undef QWEN35_ARCH_ID #include "../arch/qwen35moe_fp8/qwen35moe_fp8.cpp" +/* The same source a third time, as qwen35_w8a8: the int8 trunk. */ +#undef QWEN35_MOE +#undef QWEN35_W8A8 +#undef QWEN35_NS +#undef QWEN35_ARCH_ID +#include "../arch/qwen35_w8a8/qwen35_w8a8.cpp" /* The LLaMA family from a dense checkpoint: llama_fp8 under its other descriptor. */ #undef LLAMA_DENSE_SRC #undef LLAMA_NS @@ -5939,6 +5945,126 @@ TEST(the_qwen35_family_refuses_a_layer_schedule_that_contradicts_its_interval) { RAD_E_UNSUPPORTED); } +/* ==================================================================== qwen35_w8a8 */ + +namespace { + +/* The dense fixture as data/recipes/q38-27b-w8a8-df2.recipe states it: w8a8 / fwht128. */ +MetaKV q35w8a8_meta() { + MetaKV k = q35fp8_meta(); + k.m.quant = "w8a8_fwht128"; + k.m.name = "test-qwen35-27b-w8a8"; + k.set("quantization_config.quant_method", "w8a8").set("quantization_config.fmt", "fwht128"); + return k; +} + +/* The recipe's encodings by declared name: the eight trunk linears int8 (`/fwht128` unless + * `rotated` is false, which the plugin refuses), an int8 lm_head, and the DFlash2 drafter's MXFP4 + * linears with its 2-bit head. The drafter's keys come first because its names contain the + * trunk's (dflash.blk.0.attn_k.weight), and the head's last because `output.weight` is in + * `attn_output.weight`. */ +void w8a8_encs(RadBuilder* b, bool rotated = true) { + RadEncoding i8 = rad_enc_affine(RAD_I8, RAD_BF16, 1, 128); + if (rotated) rad_enc_copy_str(i8.transform, "fwht128"); + RadEncoding u2 = rad_enc_affine(RAD_U2, RAD_F16, 1, 128); + rad_enc_add_plane(&u2, "zero", RAD_U8, 1, 128); + b->encs = { { "dflash.draft_head", u2 }, + { "dflash.", rad_enc_affine(RAD_FP4E2M1, RAD_E8M0, 1, 32) } }; + for (const char* t : { "attn_qg.weight", "attn_k.weight", "attn_v.weight", + "attn_output.weight", "ssm_inz.weight", "ssm_out.weight", + "ffn_gate_up.weight", "ffn_down.weight" }) + b->encs.push_back({ t, i8 }); + b->encs.push_back({ "output.weight", rad_enc_affine(RAD_I8, RAD_BF16, 1, 128) }); +} + +/* qwen35_w8a8::declare with the recipe's encodings, in lint_qwen35_fp8_family's shape. */ +int w8a8_declare(RadBuilder* b, const RadModelMeta* meta, const RadBuildCtx* ctx) { + w8a8_encs(b); + return qwen35_w8a8::declare(b, meta, ctx); +} + +} /* namespace */ + +/* Every trunk linear of a rotated int8 container is an i8a8h GEMM right behind its own + * had_quant_act_i8g, at one rank and two: 2 attention layers of four linears, 6 delta-net layers + * of two and 8 feed-forwards of two. None is left at fp8, which is what a linear that missed the + * encoding falls back to, and the MLP declares no gated fold (an fp8a8 tile over E4M3 codes). The + * four trunk activations carry an int8 pair; the delta net's `gdn_in` feeds no int8 linear. */ +TEST(qwen35_w8a8_serves_every_trunk_linear_rotated_int8) { + MetaKV mk = q35w8a8_meta(); + for (int world : { 1, 2 }) { + RadBuilder b; + w8a8_encs(&b); + RadBuildCtx ctx = build_ctx(0, world); + REQUIRE_EQ(qwen35_w8a8::declare(&b, mk.meta(), &ctx), RAD_OK); + int rot = 0, paired = 0; + for (size_t i = 0; i < b.ops.size(); ++i) { + const RecOp& o = b.ops[i]; + if (o.op != "gemm_nt_q") continue; + CHECK_EQ(pstr(&o, "dtype"), std::string("i8a8h")); + if (pstr(&o, "dtype") != "i8a8h") continue; + ++rot; + paired += i > 0 && b.ops[i - 1].op == "had_quant_act_i8g"; + } + CHECK_EQ(rot, 2 * 4 + 6 * 2 + 8 * 2); + CHECK_EQ(paired, rot); + CHECK_EQ(count_op(b, "quant_act_i8g"), 0); + CHECK_EQ(count_op(b, "gemm_nt_q_gated"), 0); + for (const char* a : { "h.q8", "attn_out.q8", "gdn_o.q8", "ffn.q8" }) + CHECK(find_b(b, a) != nullptr); + CHECK(find_b(b, "gdn_in.q8") == nullptr); + } +} + +/* What the int8 build refuses: a trunk that is not int8 (no stated encoding, which a block-fp8 + * plugin reads as fp8), a plain int8 trunk (the descriptor names the rotation, and a plain weight + * served behind the rotated quantiser would be wrong), and a container stated for another format + * or without the rotation's `fmt`. */ +TEST(qwen35_w8a8_refuses_what_is_not_a_rotated_int8_trunk) { + RadBuildCtx ctx = build_ctx(); + { + MetaKV mk = q35w8a8_meta(); + RadBuilder b; + CHECK_EQ(stderr_of_rc([&] { return qwen35_w8a8::declare(&b, mk.meta(), &ctx); }), + RAD_E_DTYPE); + } + { + MetaKV mk = q35w8a8_meta(); + RadBuilder b; + w8a8_encs(&b, false); + CHECK_EQ(stderr_of_rc([&] { return qwen35_w8a8::declare(&b, mk.meta(), &ctx); }), + RAD_E_DTYPE); + } + { + MetaKV mk = q35w8a8_meta(); + mk.set("quantization_config.quant_method", "fp8").set("quantization_config.fmt", "e4m3"); + RadBuilder b; + w8a8_encs(&b); + CHECK_EQ(stderr_of_rc([&] { return qwen35_w8a8::declare(&b, mk.meta(), &ctx); }), + RAD_E_UNSUPPORTED); + } + { + MetaKV mk = q35w8a8_meta(); + mk.drop("quantization_config.fmt"); + RadBuilder b; + w8a8_encs(&b); + CHECK_EQ(stderr_of_rc([&] { return qwen35_w8a8::declare(&b, mk.meta(), &ctx); }), + RAD_E_UNSUPPORTED); + } +} + +/* Every engine step lints clean at one and two ranks, with the MTP head's passes and with the + * DFlash2 drafter's, whose depth the probe fixes at its trained block as qwen35_fp8's does. */ +TEST(qwen35_w8a8_steps_lint_clean_with_its_mtp_head_and_a_dflash2_drafter) { + MetaKV mtp = q35w8a8_meta(); + lint_qwen35_fp8_family(w8a8_declare, qwen35_w8a8::step, mtp.meta(), 3, false, 0); + MetaKV df = with_dflash2(q35w8a8_meta()); + lint_qwen35_fp8_family(w8a8_declare, qwen35_w8a8::step, df.meta(), 7, true, 8); + RadArchProbe p{}; + CHECK_OK(qwen35_w8a8::probe(df.meta(), &p)); + CHECK_EQ(p.draft_depth, 7); +} + /* ==================================================================== llama_fp8 and DSpark */ namespace { @@ -6805,6 +6931,7 @@ struct ArchCase { /* Every architecture in the tree, at the fixtures above. */ struct ArchCases { MetaKV q35 = q35fp8_meta(), q35df = with_dflash2(q35fp8_meta()), q35moe = q35moe_meta(); + MetaKV q35w8df = with_dflash2(q35w8a8_meta()); MetaKV lla = with_dspark(llama_meta()), eg2 = eg2_meta(), qimg = qimg_meta(); MetaKV q4s = q4_small(); RadModelMeta q35b = qwen35_meta(), q4 = *q4s.meta(), lfm = lfm2_meta(); @@ -6843,6 +6970,12 @@ struct ArchCases { add("qwen35_fp8 + DFlash2", [this, sc](RadBuilder* b) { auto c = sc(1, 7); return qwen35_fp8::declare(b, q35df.meta(), &c); }, qwen35_fp8::step, 7, {}, 0xb5691456a0ce7e9dull); + add("qwen35_w8a8 + DFlash2", [this, sc](RadBuilder* b) { + auto c = sc(1, 7); return w8a8_declare(b, q35w8df.meta(), &c); }, + qwen35_w8a8::step, 7, {}, 0x88e964c824896422ull); + add("qwen35_w8a8 + DFlash2, two ranks", [this, sc](RadBuilder* b) { + auto c = sc(2, 7); return w8a8_declare(b, q35w8df.meta(), &c); }, + nullptr, 7, { "ar_rmsnorm_quant_fp8" }, 0x7c73e987c475e40dull); add("qwen35moe_fp8 + MTP", [this, sc](RadBuilder* b) { auto c = sc(1, 3); return qwen35moe_fp8::declare(b, q35moe.meta(), &c); }, qwen35moe_fp8::step, 3, {}, 0x3157a986f13a9a72ull); diff --git a/tests/shipped_plugins_test.cpp b/tests/shipped_plugins_test.cpp index a503ccd1..638c8118 100644 --- a/tests/shipped_plugins_test.cpp +++ b/tests/shipped_plugins_test.cpp @@ -12,6 +12,7 @@ #include #include #include +#include using namespace rad; @@ -90,7 +91,8 @@ TEST(the_shipped_architectures_load_with_distinct_selection_keys) { { "breeze", "" }, { "embeddinggemma2", "" }, { "gemma4", "" }, { "gemma4", "compressed-tensors" }, { "lfm2", "" }, { "llama", "" }, { "llama", "fp8_e4m3" }, { "qwen35", "" }, - { "qwen35", "fp8_e4m3" }, { "qwen35moe", "fp8_e4m3" }, { "qwen3asr", "" }, + { "qwen35", "fp8_e4m3" }, { "qwen35", "w8a8_fwht128" }, { "qwen35moe", "fp8_e4m3" }, + { "qwen3asr", "" }, { "minimaxh3", "" }, { "minimaxmusic3", "" }, { "qwen4exp", "" }, { "qwenimage21", "" } }; std::set> got; for (const auto& [k, name] : keys) got.insert(k); @@ -101,4 +103,32 @@ TEST(the_shipped_architectures_load_with_distinct_selection_keys) { CHECK(got == want); } +/* A checkpoint whose quantisation was imported weight by weight (Quark, ParoQuant, GPTQ, NVFP4) + * names a tool no plugin claims, so the family's one quantised plugin serves it, and two are + * refused (startup.h). So each family has at most one quantised plugin that takes imports: + * qwen35_w8a8 declines them (rad_arch_serves_imports), leaving Qwen3.8 imports to qwen35_fp8. */ +TEST(every_shipped_family_has_at_most_one_plugin_for_an_imported_checkpoint) { + Registry r; + const int st = r.load_dir(dir_of("architectures"), {}); + if (st == RAD_E_IO && r.plugins().empty()) + ARTIFACT_MISSING("the architecture plugins under " + dir_of("architectures")); + CHECK_OK(st); + std::map> takers; + for (const Plugin& p : r.plugins()) + if (p.kind == RAD_PLUGIN_ARCH && !p.arch_quant.empty() && p.arch_serves_imports) + takers[p.arch_id].push_back(p.name); + for (const auto& [id, names] : takers) { + if (names.size() > 1) + for (const auto& n : names) + fprintf(stderr, " '%s' would take an imported %s checkpoint\n", n.c_str(), + id.c_str()); + CHECK_EQ(names.size(), 1u); + } + REQUIRE(takers.count("qwen35")); + CHECK_EQ(takers["qwen35"][0], std::string("qwen35_fp8")); + const Plugin* w8 = r.plugin("qwen35_w8a8"); + REQUIRE(w8 != nullptr); + CHECK(!w8->arch_serves_imports); +} + RAD_TEST_MAIN()