From 73a284d799d5caea63539ef3135da2fd7e21ab82 Mon Sep 17 00:00:00 2001 From: keptn42 Date: Tue, 17 Nov 2026 13:02:04 +0100 Subject: [PATCH] data/recipes: ling-3.0-flash-iq8r-w4nl64 The recipe of Ling-3.0-flash and its fine-tunes on an IQ8R trunk: the trunk lines of ling-3.0-tiny-iq8r.recipe, the 512 routed experts of a layer as rotated four-bit codes into the w4nl codebook at an E4M3 scale a (row, 64 of K). An empty CALIB directory rounds the experts to nearest with a scale search. Ling-3.0-flash-Sante converted with it (experts rounded to nearest) on four R9700 against the bf16 original, 80 MT-Bench questions, 42,767 tokens: mean KL 0.00461, 99th percentile 0.0494, top token the same 98.0 %. the_ling_flash_iq8r_w4nl64_recipe_decides_the_model_it_was_written_for reads the recipe as it ships over the plugin's names: the IQ8R trunk, the w4nl64 experts, the shared down projection, the f32 casts and the weights kept bf16. recipe_test: 14 of 14 cases; ctest -LE 'gpu|oot': 181 of 181 (3 skipped). --- .../recipes/ling-3.0-flash-iq8r-w4nl64.recipe | 41 +++++++++++ docs/ARCHITECTURES.md | 8 ++- tests/recipe_test.cpp | 71 +++++++++++++++++++ 3 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 data/recipes/ling-3.0-flash-iq8r-w4nl64.recipe diff --git a/data/recipes/ling-3.0-flash-iq8r-w4nl64.recipe b/data/recipes/ling-3.0-flash-iq8r-w4nl64.recipe new file mode 100644 index 00000000..a6205eb8 --- /dev/null +++ b/data/recipes/ling-3.0-flash-iq8r-w4nl64.recipe @@ -0,0 +1,41 @@ +# ling-3.0-flash-iq8r-w4nl64.recipe -- Ling-3.0-flash or a fine-tune (Ling-3.0-flash-Sante) from its +# bf16 checkpoint with an IQ8R trunk and four-bit rotated experts, served by bailing_hybrid. +# +# CALIB=DIR rad-convert \ +# --recipe data/recipes/ling-3.0-flash-iq8r-w4nl64.recipe -o ling-3.0-flash-iq8r-w4nl64.rad +# +# - The trunk as ling-3.0-tiny-iq8r.recipe: the KDA projections, the MLA output, the dense +# layers' feed-forward and the shared expert's gate/up as IQ8R, the shared expert's down +# projection int8 at one bf16 scale per (row, 128 of K), all rotated by fwht128. +# - The 512 routed experts of every layer as rotated u4 codes into the w4nl codebook with one E4M3 +# scale a (row, 64 of K) under a fixed f32 of 2^-13 (w4nl64a8i8h, as nemotron74-w4nl64-gptq), +# read against the trunk's rotated int8 codes. DIR holds the experts' Grams for GPTQ; an empty +# DIR rounds them to nearest with a scale search. +# - Kept bf16: the KDA beta projection, the MLA's q and kv projections and its gate, the conv1d +# weights, the router, the embedding and the lm_head. +# +# Flash clamps its SwiGLU in its last layers (routed 35-41, shared 34-41): there the gated product +# is the clamp into the bf16 plane and the rotating int8 quantiser after it. + +blk.*.attn_qkv.weight rtn codes=i8 group=256 scale=u8 scale2=bf16 block2=1x* transform=fwht128 clamp=sym rule=search +blk.*.attn_forget.weight rtn codes=i8 group=256 scale=u8 scale2=bf16 block2=1x* transform=fwht128 clamp=sym rule=search +blk.*.attn_gate.weight rtn codes=i8 group=256 scale=u8 scale2=bf16 block2=1x* transform=fwht128 clamp=sym rule=search +blk.*.attn_output.weight rtn codes=i8 group=256 scale=u8 scale2=bf16 block2=1x* transform=fwht128 clamp=sym rule=search +blk.*.ffn_gate_up.weight rtn codes=i8 group=256 scale=u8 scale2=bf16 block2=1x* transform=fwht128 clamp=sym rule=search +blk.*.ffn_down.weight rtn codes=i8 group=256 scale=u8 scale2=bf16 block2=1x* transform=fwht128 clamp=sym rule=search +blk.*.ffn_gate_up_shexp.weight rtn codes=i8 group=256 scale=u8 scale2=bf16 block2=1x* transform=fwht128 clamp=sym rule=search + +blk.*.ffn_*_exps.*.weight gptq table=w4nl group=64 scale=fp8_e4m3 scale2=f32 block2=*x* scale2_value=0.0001220703125 transform=fwht128 rule=search cd=3 calib=$CALIB +blk.*.ffn_down_shexp.weight rtn codes=i8 group=128 scale=bf16 transform=fwht128 clamp=sym rule=search + +# The shared blocks declare their gains and router correction as f32 planes (A_log and dt_bias +# ship f32 in the checkpoint), so they keep the f32 form the plugin reads. +blk.*.attn_norm.weight cast dtype=f32 +blk.*.attn_kv_a_norm.weight cast dtype=f32 +blk.*.ffn_norm.weight cast dtype=f32 +blk.*.ssm_norm.weight cast dtype=f32 +blk.*.ssm_a cast dtype=f32 +blk.*.ssm_dt_bias cast dtype=f32 +blk.*.glm_router.weight cast dtype=f32 +blk.*.glm_router.correction cast dtype=f32 +output_norm.weight cast dtype=f32 diff --git a/docs/ARCHITECTURES.md b/docs/ARCHITECTURES.md index 8f760ace..5ae298e1 100644 --- a/docs/ARCHITECTURES.md +++ b/docs/ARCHITECTURES.md @@ -22,7 +22,7 @@ plugin claims. | `arch/clef_fp8` | `clef` | `fp8_e4m3` | the same over `qwen35_fp8`'s trunk | | `arch/qwen4exp_fp8` | `qwen4exp` | *(empty)* | Qwen4-Exp (Qwen3.8-Flash-Next), a bf16 checkpoint quantised at convert (`data/recipes/qwen4exp-w4nl64-i8-hc8m.recipe`) or an AutoRound int4 release (`qwen4exp-autoround-i8-hc8m.recipe`) | | `arch/glm5next` | `glm5next` | *(empty)* | GLM-5.3-Flash: four mHC residual streams over 34 KDA and 11 sparse latent-attention (MLA) layers with a DSA indexer, 288 experts at top-8 under sigmoid routing, attention and dense layers as the container stores them; its MTP layer is a serial drafter. Pictures through its vision tower (`arch/common/rad_block_glm_vision.h`); bf16 KV | -| `arch/bailing_hybrid` | `bailinghybrid` | *(empty)* | Ling-3.0-flash and its fine-tunes (Ling-3.0-flash-Sante) from the bf16 checkpoint: 35 KDA and 7 dense latent-attention (MLA) layers with a rotary part and a head-wise gate, 512 experts at top-8 under group-limited sigmoid routing with an ungated shared expert, the routed experts as the recipe stores them (`data/recipes/ling3-w4a8-rtn.recipe`); its MTP layer is a serial drafter; Ling-3.0-tiny from its bf16 checkpoint with an IQ8R trunk and rotated int8 experts (`data/recipes/ling-3.0-tiny-iq8r.recipe`, TP1/2), and flash on the same trunk with rotated experts (its clamped layers clamp, then quantise); bf16 KV | +| `arch/bailing_hybrid` | `bailinghybrid` | *(empty)* | Ling-3.0-flash and its fine-tunes (Ling-3.0-flash-Sante) from the bf16 checkpoint: 35 KDA and 7 dense latent-attention (MLA) layers with a rotary part and a head-wise gate, 512 experts at top-8 under group-limited sigmoid routing with an ungated shared expert, the routed experts as the recipe stores them (`data/recipes/ling3-w4a8-rtn.recipe`); its MTP layer is a serial drafter; Ling-3.0-tiny from its bf16 checkpoint with an IQ8R trunk and rotated int8 experts (`data/recipes/ling-3.0-tiny-iq8r.recipe`, TP1/2), and flash on the same trunk with rotated four-bit experts (`data/recipes/ling-3.0-flash-iq8r-w4nl64.recipe`; its clamped layers clamp, then quantise); bf16 KV | | `arch/bailing_hybrid_gguf` | `bailinghybrid` | `gguf_ftype_25` | Ling-3.0-tiny (24 layers, MLA every fourth with a 256-wide query LoRA, 128 experts of 512 at top-8) as the IQ4_NL GGUF release, its experts re-quantised by `data/recipes/ling-3.0-tiny-iq4.recipe`; no MTP; bf16 KV | | `arch/bailing_hybrid_gguf_q80` | `bailinghybrid` | `gguf_ftype_7` | the same tiny family, Q8_0 GGUF release, served whole | | `arch/bailing_hybrid_gguf_q4km` | `bailinghybrid` | `gguf_ftype_15` | the same tiny family, Q4_K_M GGUF release, served whole | @@ -1090,6 +1090,12 @@ IQ8R (tiny, `data/recipes/ling-3.0-tiny-iq8r.recipe`): the KDA q|k|v, forget, ga the embedding and the head stay bf16. TP1 and TP2 (at TP4 the dense 1152-column slice cuts a 256-column group and is refused). +IQ8R with four-bit experts (flash, `data/recipes/ling-3.0-flash-iq8r-w4nl64.recipe`): the trunk + as above; the routed experts rotated four-bit codes into the w4nl codebook at an E4M3 scale a + (row, 64) (`moe_gemm_q` at `w4nl64a8i8h`), read against the trunk's rotated int8 codes. + The clamped layers write `swiglu_step`'s bf16 product and quantise it with `had_quant_act_i8g`. + Declared at one, two and four ranks; served on two and four cards. + GGUF releases (tiny): IQ4_NL, Q8_0, Q4_K_M, Q5_K_M, Q6_K -- the file's `general.file_type` is the claim (`gguf_ftype_25`, `_7`, `_15`, `_17`, `_18`); the release files carry their producer's renumbered ftable (IQ4_NL 25, Q4_K_M 15, Q5_K_M 17, Q6_K 18, Q8_0 7), not the diff --git a/tests/recipe_test.cpp b/tests/recipe_test.cpp index bb38cb07..a11de156 100644 --- a/tests/recipe_test.cpp +++ b/tests/recipe_test.cpp @@ -538,4 +538,75 @@ TEST(the_ling_tiny_iq8r_recipe_decides_the_model_it_was_written_for) { for (const char* n : kept) CHECK(r.match(n) == nullptr); } +/* The Ling-3.0-flash recipe as it ships, over arch/bailing_hybrid's declared names: the trunk as the + * tiny IQ8R recipe (KDA projections, MLA out, the two dense layers' pair, the shared expert's + * gate/up IQ8R; the shared expert's down projection rotated int8 at a bf16 scale a (row, 128 of + * K)), the 512 routed experts of a layer rotated four-bit codes into the w4nl codebook at an E4M3 + * scale a (row, 64 of K). Flash's MLA has no query LoRA, so no q_a norm is cast. The KDA beta, the + * MLA's q parts, kv projections and head gate, the convolution taps, the embedding and the head + * match no rule and keep the checkpoint's bf16. The experts name their statistics through $CALIB, so the test + * sets it. */ +TEST(the_ling_flash_iq8r_w4nl64_recipe_decides_the_model_it_was_written_for) { + ::setenv("CALIB", "/data/calib", 1); + const std::string dir = std::string(__FILE__).substr( + 0, std::string(__FILE__).find_last_of('/')) + "/../data/recipes"; + std::ifstream in(dir + "/ling-3.0-flash-iq8r-w4nl64.recipe"); + REQUIRE(in.good()); + std::string text((std::istreambuf_iterator(in)), std::istreambuf_iterator()); + Recipe r; + std::string why; + REQUIRE_EQ(r.add_text(text, "ling-3.0-flash-iq8r-w4nl64.recipe", &why), RAD_OK); + CHECK_EQ(r.rules().size(), (size_t)18); + const char* iq8r[] = { "blk.0.attn_qkv.weight", "blk.40.attn_forget.weight", + "blk.1.attn_gate.weight", "blk.2.attn_output.weight", + "blk.5.attn_output.weight", "blk.0.ffn_gate_up.weight", + "blk.1.ffn_down.weight", "blk.2.ffn_gate_up_shexp.weight", + "blk.41.ffn_gate_up_shexp.weight" }; + for (const char* n : iq8r) { + const RecipeRule* m = r.match(n); + REQUIRE(m != nullptr); + CHECK_EQ(m->quantizer, std::string("rtn")); + CHECK(has_opt(m, "codes", "i8")); + CHECK(has_opt(m, "group", "256")); + CHECK(has_opt(m, "scale", "u8")); + CHECK(has_opt(m, "scale2", "bf16")); + CHECK(has_opt(m, "transform", "fwht128")); + } + const char* w4nl[] = { "blk.2.ffn_gate_up_exps.0.weight", "blk.41.ffn_down_exps.511.weight" }; + for (const char* n : w4nl) { + const RecipeRule* m = r.match(n); + REQUIRE(m != nullptr); + CHECK_EQ(m->quantizer, std::string("gptq")); + CHECK(has_opt(m, "table", "w4nl")); + CHECK(has_opt(m, "group", "64")); + CHECK(has_opt(m, "scale", "fp8_e4m3")); + CHECK(has_opt(m, "transform", "fwht128")); + CHECK(has_opt(m, "calib", "/data/calib")); + } + { + const RecipeRule* m = r.match("blk.7.ffn_down_shexp.weight"); + REQUIRE(m != nullptr); + CHECK_EQ(m->quantizer, std::string("rtn")); + CHECK(has_opt(m, "codes", "i8")); + CHECK(has_opt(m, "group", "128")); + CHECK(has_opt(m, "scale", "bf16")); + CHECK(has_opt(m, "transform", "fwht128")); + } + const char* f32[] = { "blk.0.attn_norm.weight", "blk.5.attn_kv_a_norm.weight", + "blk.2.ffn_norm.weight", "blk.0.ssm_norm.weight", "blk.0.ssm_a", + "blk.0.ssm_dt_bias", "blk.2.glm_router.weight", + "blk.2.glm_router.correction", "output_norm.weight" }; + for (const char* n : f32) { + const RecipeRule* m = r.match(n); + REQUIRE(m != nullptr); + CHECK_EQ(m->quantizer, std::string("cast")); + CHECK(has_opt(m, "dtype", "f32")); + } + const char* kept[] = { "blk.0.attn_beta.weight", "blk.5.attn_q_rope.weight", + "blk.5.attn_q_nope.weight", "blk.5.attn_kv_a.weight", + "blk.5.attn_kv_b.weight", "blk.5.attn_head_gate.weight", + "blk.0.ssm_conv.weight", "token_embd.weight", "output.weight" }; + for (const char* n : kept) CHECK(r.match(n) == nullptr); +} + RAD_TEST_MAIN()