From ef219c21926c31cf72804df595cc40053ff724f9 Mon Sep 17 00:00:00 2001 From: Juup Date: Wed, 21 Oct 2026 19:09:59 +0000 Subject: [PATCH] arch, data/recipes, deploy: Sage-A1.5's routed trunk with its vision tower, and DFlash2 in place of the MTP head Sage-A1.5 (InternScience) is Qwen3.5-MoE's routed trunk with the Qwen3.5 vision tower beside it -- a shape qwen35moe_fp8 already declares, but no fixture covered the two together: the MoE fixture had no tower, the VL fixture was dense. arch_test gains q35moe_vl_meta, and checks the tower declares once for the build (not a copy a rank), that it is withheld when no encoder budget is given, and that the routed blocks, the folded shared expert and the MTP layer's own router are still declared beside it. sage-a1.5-fp8.recipe puts every trunk linear -- attention, the delta net's in- and out-projections, the routed and shared experts of all 40 blocks, and the MTP layer at index 40 -- into block fp8, the head likewise, and keeps the routers, the shared-expert gates, the delta net's parameters, the norms, the embedding and the whole vision tower as the checkpoint ships them. recipe_test reads the shipped file and asserts all of that. sage-a1.5-fp8-df2.recipe is the same trunk with incoai/Qwen3.6-35B-A3B-DFlash2's tensors in place of the MTP head, which the shared source declares through declare_dflash2. On two R9700s it decodes 392.9 tok/s against 281.6 with the MTP head, at 49.3% acceptance and depth 7; on one card, 231.6 against 168.3. Compose: sage-a1.5.yaml (two cards, four 32k sessions), sage-a1.5-tp1.yaml (one card, an 8 GiB pinned host pool, one 262,144-token session) and sage-a1.5-df2.yaml. README, DOCKER.md and ARCHITECTURES.md list the containers and the drafter. --- README.md | 2 + data/recipes/sage-a1.5-fp8-df2.recipe | 38 +++++++++++++++++ data/recipes/sage-a1.5-fp8.recipe | 39 +++++++++++++++++ deploy/compose/sage-a1.5-df2.yaml | 18 ++++++++ deploy/compose/sage-a1.5-tp1.yaml | 20 +++++++++ deploy/compose/sage-a1.5.yaml | 21 ++++++++++ docs/ARCHITECTURES.md | 10 +++++ docs/DOCKER.md | 3 ++ tests/arch_test.cpp | 60 +++++++++++++++++++++++++++ tests/recipe_test.cpp | 53 +++++++++++++++++++++++ 10 files changed, 264 insertions(+) create mode 100644 data/recipes/sage-a1.5-fp8-df2.recipe create mode 100644 data/recipes/sage-a1.5-fp8.recipe create mode 100644 deploy/compose/sage-a1.5-df2.yaml create mode 100644 deploy/compose/sage-a1.5-tp1.yaml create mode 100644 deploy/compose/sage-a1.5.yaml diff --git a/README.md b/README.md index 5d136741..b930ef91 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,8 @@ To support the development of radiance: [Patreon](https://patreon.com/StillDeadC | Qwen3.6-35B-A3B FP8, MTP | `qwen3.6-35b-a3b-fp8.rad` (35 GiB) | [download](https://huggingface.co/StillDeadcode/qwen3.6-35b-a3b-fp8) | `qwen3.6-35b-a3b.yaml` | | Ornith-1.5-35B-A3B FP8, MTP, vision | `ornith-1.5-35b-a3b-fp8.rad` (35 GiB) | [download](https://huggingface.co/keptn/ornith-1.5-35b-a3b-fp8) | `ornith-1.5-35b-a3b.yaml` | | Ornith-1.5-35B-A3B w4a8: 4-bit experts (GPTQ), MTP, vision, fits one card | `ornith-1.5-35b-a3b-w4a8.rad` (20 GiB) | [download](https://huggingface.co/keptn/ornith-1.5-35b-a3b-w4a8) | `ornith-1.5-35b-a3b-w4a8.yaml` | +| Sage-A1.5 FP8, MTP, vision | `sage-a1.5-fp8.rad` (35 GiB) | [download](https://huggingface.co/Aijuus/sage-a1.5-fp8) | `sage-a1.5.yaml`, `sage-a1.5-tp1.yaml` | +| Sage-A1.5 FP8, DFlash2 drafter, vision | `sage-a1.5-fp8-df2.rad` (34 GiB) | [download](https://huggingface.co/Aijuus/sage-a1.5-fp8-df2) | `sage-a1.5-df2.yaml` | | MiniCPM5-2B FP8, DSpark drafter | `minicpm5-2b-fp8.rad` (3 GiB) | [download](https://huggingface.co/StillDeadcode/minicpm5-2b-fp8) | `minicpm5-2b.yaml` | | MiniCPM5-2B bf16, DSpark drafter | `minicpm5-2b-bf16.rad` (5 GiB) | [download](https://huggingface.co/StillDeadcode/minicpm5-2b-bf16) | `minicpm5-2b-bf16.yaml` | | Gemma 4 31B: GPTQ int4 trunk, int8 activations, MTP, vision | `gemma4-31b-w4a8.rad` (20 GiB) | [download](https://huggingface.co/keptn/gemma4-31b-w4a8) | `gemma4-31b-w4a8.yaml` | diff --git a/data/recipes/sage-a1.5-fp8-df2.recipe b/data/recipes/sage-a1.5-fp8-df2.recipe new file mode 100644 index 00000000..92c43e27 --- /dev/null +++ b/data/recipes/sage-a1.5-fp8-df2.recipe @@ -0,0 +1,38 @@ +# sage-a1.5-fp8-df2.recipe -- Sage-A1.5 with incoai's Qwen3.6-35B-A3B DFlash2 drafter merged in +# place of the MTP head. The trunk rules are sage-a1.5-fp8.recipe's unchanged; the drafter's +# linears take the same 128x128 block form as the trunk, and its draft head is the target's +# lm_head as the 2-bit copy the draft rounds read. +# +# rad-convert InternScience/Sage-A1.5-FP8 \ +# --draft-model incoai/Qwen3.6-35B-A3B-DFlash2 \ +# --recipe data/recipes/sage-a1.5-fp8-df2.recipe -o sage-a1.5-fp8-df2.rad +# +# The drafter is a DFlash2DraftModel: six Qwen3-shaped layers at 2048, eight taps +# (target_layer_ids 1 6 11 16 22 27 32 37), block 8, selector rank 256 / top 16, vocab 248320. +# Sage's text_config is Qwen3.6-35B-A3B's key for key, so the drafter's geometry matches the +# trunk it was trained against. qwen35moe_fp8 (qwen35_fp8.cpp with QWEN35_MOE=1) declares it and +# drops the MTP head, which is then neither declared nor carried. +# +# The drafter's norms, the selector's projection and codebooks, and the convolution kernels and +# bases stay bf16/f32 as the checkpoint holds them. + +blk.*.attn_qg.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +blk.*.attn_k.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +blk.*.attn_v.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +blk.*.attn_output.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +blk.*.ssm_inz.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +blk.*.ssm_out.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +blk.*.ffn_gate_up_exps.*.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +blk.*.ffn_down_exps.*.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +blk.*.ffn_gate_up_shexp.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +blk.*.ffn_down_shexp.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +output.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 + +dflash.fc.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +dflash.blk.*.attn_q.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +dflash.blk.*.attn_k.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +dflash.blk.*.attn_v.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +dflash.blk.*.attn_output.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +dflash.blk.*.ffn_gate_up.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +dflash.blk.*.ffn_down.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +dflash.draft_head.weight rtn codes=u2 zero=u8 group=128 scale=f16 diff --git a/data/recipes/sage-a1.5-fp8.recipe b/data/recipes/sage-a1.5-fp8.recipe new file mode 100644 index 00000000..6810c178 --- /dev/null +++ b/data/recipes/sage-a1.5-fp8.recipe @@ -0,0 +1,39 @@ +# sage-a1.5-fp8.recipe -- Sage-A1.5, InternScience's post-train of Qwen3.5-35B-A3B-VL, as the +# qwen35moe_fp8 plugin serves it (256 experts of 512, top 8, a routed MTP head, the Qwen3.5 +# vision tower). +# +# rad-convert InternScience/Sage-A1.5-FP8 --recipe data/recipes/sage-a1.5-fp8.recipe \ +# -o sage-a1.5-fp8.rad +# +# The published FP8 release is compressed-tensors with one scale an output row, and it leaves +# the vision tower, the routers and the whole MTP head bf16. The engine's expert kernels read +# block-scaled fp8 only (a scale a 128x128 block) and its plugin refuses bf16 experts, so this +# re-expresses every linear into Qwen's own block form, the same weights in the same form as +# qwen3.6-35b-a3b-fp8.rad. From the bf16 release instead, the same recipe applies and the format +# has to be stated too: +# +# rad-convert InternScience/Sage-A1.5 --recipe data/recipes/sage-a1.5-fp8.recipe \ +# --set quantization_config.quant_method=fp8 --set quantization_config.fmt=e4m3 \ +# --set "quantization_config.weight_block_size=128 128" \ +# --set quantization_config.activation_scheme=dynamic -o sage-a1.5-fp8.rad +# +# The linears -- attention q/gate, k, v and output, the delta net's qkv/z and output +# projections, the routed and shared experts of all 40 blocks, and the MTP layer's, which the +# blk.* patterns reach at its own index 40 -- as E4M3 with one bf16 scale a 128x128 block. The +# lm_head likewise, and the MTP head's 2-bit copy of it, which the draft rounds read in place of +# the full head. The routers, the shared-expert gates, the delta net's a/b projection, its conv +# and decay parameters, the norms, the embedding and the vision tower stay as the checkpoint +# holds them. + +blk.*.attn_qg.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +blk.*.attn_k.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +blk.*.attn_v.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +blk.*.attn_output.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +blk.*.ssm_inz.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +blk.*.ssm_out.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +blk.*.ffn_gate_up_exps.*.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +blk.*.ffn_down_exps.*.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +blk.*.ffn_gate_up_shexp.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +blk.*.ffn_down_shexp.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +output.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +mtp.draft_head.weight rtn codes=u2 zero=u8 group=128 scale=f16 diff --git a/deploy/compose/sage-a1.5-df2.yaml b/deploy/compose/sage-a1.5-df2.yaml new file mode 100644 index 00000000..2fae0b59 --- /dev/null +++ b/deploy/compose/sage-a1.5-df2.yaml @@ -0,0 +1,18 @@ +# Sage-A1.5 with incoai's Qwen3.6-35B-A3B DFlash2 drafter in place of the MTP head, made by +# data/recipes/sage-a1.5-fp8-df2.recipe. The drafter proposes seven tokens in one block pass +# (block 8, acceptance ~49% at depth 7); measured 393 tok/s decode on two cards against 282 with +# MTP. Sampling is the model card's (temp 1.0, top_p 0.95, top_k 20, presence 1.5). +# +# The profile below is the measured one: four 32,768-token sessions, the whole expert plane in +# VRAM. A single 262,144-token session instead is `--max-num-seqs 1 --max-model-len 262144`. +name: radiance-sage-a1.5-df2 +services: + radiance: + extends: { file: common.yaml, service: radiance } + container_name: radiance-sage-a1.5-df2 + command: > + --model /models/sage-a1.5-fp8-df2.rad + --host :: --port ${PORT:-8000} --api-key ${RADIANCE_API_KEY:?set RADIANCE_API_KEY in .env} + --tp 2 --max-num-seqs 4 --max-model-len 32768 --kv-cache-dtype fp8 + --num-speculative-tokens auto --max-num-batched-tokens 2048 + --temp 1.0 --top-p 0.95 --top-k 20 --presence-penalty 1.5 diff --git a/deploy/compose/sage-a1.5-tp1.yaml b/deploy/compose/sage-a1.5-tp1.yaml new file mode 100644 index 00000000..e54650bb --- /dev/null +++ b/deploy/compose/sage-a1.5-tp1.yaml @@ -0,0 +1,20 @@ +# Sage-A1.5 on one card: the same block-fp8 container, its experts partly in a pinned host pool +# because 34.5 GiB of weights do not fit 31.9 GiB of VRAM. Measured on a R9700 (warm, 3 runs, +# --max-model-len 131072): 168 tok/s decode and ~11,000 tok/s prefill, against 282 tok/s decode +# and ~11,000 tok/s prefill at --tp 2. Prefill is bandwidth-bound and one card does it; the +# second card buys decode only. This profile: 25.12 GiB of experts in VRAM, 5.79 GiB in the 8 +# GiB pool (about 1.5 GiB more than the measured run), the cache holding one full 262,144-token +# session. For two short sessions instead use --max-num-seqs 2 --max-model-len 32768 +# --host-pool-mib 6144 (3.80 GiB of experts in the pool). Sampling is the model card's. +name: radiance-sage-a1.5-tp1 +services: + radiance: + extends: { file: common.yaml, service: radiance } + container_name: radiance-sage-a1.5-tp1 + command: > + --model /models/sage-a1.5-fp8.rad + --host :: --port ${PORT:-8000} --api-key ${RADIANCE_API_KEY:?set RADIANCE_API_KEY in .env} + --tp 1 --max-num-seqs 1 --max-model-len 262144 --kv-cache-dtype fp8 + --num-speculative-tokens 3 --max-num-batched-tokens 2048 + --placement expert_tiered --host-pool-mib 8192 + --temp 1.0 --top-p 0.95 --top-k 20 --presence-penalty 1.5 diff --git a/deploy/compose/sage-a1.5.yaml b/deploy/compose/sage-a1.5.yaml new file mode 100644 index 00000000..80babc0f --- /dev/null +++ b/deploy/compose/sage-a1.5.yaml @@ -0,0 +1,21 @@ +# Sage-A1.5, InternScience's Qwen3.5-35B-A3B-VL post-train: FP8 with one scale per 128x128 +# block, its routed MTP head and the vision tower, as data/recipes/sage-a1.5-fp8.recipe makes +# it. Sampling is the model card's (temp 1.0, top_p 0.95, top_k 20, presence 1.5). Thinking and +# the opt-in verification mode are switched per request (chat_template_kwargs). +# +# The profile below is the measured one: four 32,768-token sessions, the whole expert plane in +# VRAM. A single 262,144-token session instead is `--max-num-seqs 1 --max-model-len 262144`: +# the planner charges ~1.5 GiB of KV a card for it (1.49 GiB backs 262,176 tokens in the tp2 +# boot log). Eight of them are ~12 GiB of KV a card, which does not fit beside 15.5 GiB of +# resident experts and 1.9 GiB of static weights once the arena for eight sequences is charged. +name: radiance-sage-a1.5 +services: + radiance: + extends: { file: common.yaml, service: radiance } + container_name: radiance-sage-a1.5 + command: > + --model /models/sage-a1.5-fp8.rad + --host :: --port ${PORT:-8000} --api-key ${RADIANCE_API_KEY:?set RADIANCE_API_KEY in .env} + --tp 2 --max-num-seqs 4 --max-model-len 32768 --kv-cache-dtype fp8 + --num-speculative-tokens 3 --max-num-batched-tokens 2048 + --temp 1.0 --top-p 0.95 --top-k 20 --presence-penalty 1.5 diff --git a/docs/ARCHITECTURES.md b/docs/ARCHITECTURES.md index 7a259aab..8ad2deeb 100644 --- a/docs/ARCHITECTURES.md +++ b/docs/ARCHITECTURES.md @@ -263,6 +263,16 @@ 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. +**Drafters.** The container's own MTP head is the default, and `rad-convert --draft-model` can +replace it with a DFlash2 block drafter; the shared source declares it (`declare_dflash2`) and +does not declare the MTP head when a DFlash2 drafter is present, so the routed trunk carries a dense drafter +without further work. `sage-a1.5-fp8-df2.rad` is such a container: Sage-A1.5's routed trunk with +`incoai/Qwen3.6-35B-A3B-DFlash2`, whose six 2048-wide layers read eight taps +(`target_layer_ids` 1 6 11 16 22 27 32 37) and propose a block of seven tokens in one pass. At +depth 7 it accepts ~49% of the proposals and decodes 1.40x faster than the same trunk with its MTP +head (393 against 282 tok/s on two R9700s). `--num-speculative-tokens auto` takes the depth the +drafter states. + ## `qwen35_w8a8` The dense build again, behind `#if QWEN35_W8A8`, for a container `data/recipes/q38-27b-w8a8-df2.recipe` diff --git a/docs/DOCKER.md b/docs/DOCKER.md index 4d1bbb43..134ac407 100644 --- a/docs/DOCKER.md +++ b/docs/DOCKER.md @@ -131,6 +131,9 @@ the cards the engine runs on. | `flashnext-bf16.yaml` | `qwen3.8-flash-next-bf16.rad` | Qwen3.8-Flash-Next in bf16, streamed from the disk tier. A reference, not a production server | | `qwen3.6-35b-a3b.yaml` | `qwen3.6-35b-a3b-fp8.rad` | Qwen3.6-35B-A3B, FP8 | | `ornith-1.5-35b-a3b.yaml` | `ornith-1.5-35b-a3b-fp8.rad` | Ornith-1.5-35B-A3B, FP8, MTP, vision | +| `sage-a1.5.yaml` | `sage-a1.5-fp8.rad` | Sage-A1.5, FP8, MTP, vision | +| `sage-a1.5-tp1.yaml` | `sage-a1.5-fp8.rad` | The same on one card: the expert plane partly in an 8 GiB pinned host pool, one 262,144-token session | +| `sage-a1.5-df2.yaml` | `sage-a1.5-fp8-df2.rad` | Sage-A1.5 with incoai's Qwen3.6-35B-A3B DFlash2 drafter in place of the MTP head, vision | | `qwen3.8-27b-fp8.yaml` | `qwen3.8-27b-fp8.rad` | Qwen3.8-27B FP8 with its DFlash2 drafter and vision tower | | `qwen3.8-27b-mxfp4.yaml` | `qwen3.8-27b-mxfp4.rad` | Qwen3.8-27B with AMD's Quark AWQ-MXFP4 trunk, its DFlash2 drafter and vision tower | | `qwen3.8-27b-paro.yaml` | `qwen3.8-27b-paro-int4.rad` | Qwen3.8-27B ParoQuant int4 (learned rotations) with its DFlash2 drafter and vision tower, on one card; the int5 and MXFP4 containers serve from it too | diff --git a/tests/arch_test.cpp b/tests/arch_test.cpp index 4170cd29..b2097a34 100644 --- a/tests/arch_test.cpp +++ b/tests/arch_test.cpp @@ -6055,6 +6055,26 @@ MetaKV q35moe_meta() { return k; } +/* The 35B-A3B-VL: the routed trunk with the Qwen3.5 vision tower beside it, as Sage-A1.5 and + * Ornith-1.5 carry it. The fixture's trunk is q35fp8_meta's (5120 wide), so the tower emits + * that width; the shipped checkpoints' tower is 2048, the real trunk's width. */ +MetaKV q35moe_vl_meta() { + MetaKV k = q35moe_meta(); + k.set("vision_config.depth", "2") + .set("vision_config.hidden_size", "1152") + .set("vision_config.num_heads", "16") + .set("vision_config.intermediate_size", "4304") + .set("vision_config.patch_size", "16") + .set("vision_config.temporal_patch_size", "2") + .set("vision_config.in_channels", "3") + .set("vision_config.spatial_merge_size", "2") + .set("vision_config.out_hidden_size", "5120") + .set("vision_config.num_position_embeddings", "2304") + .set("vision_config.deepstack_visual_indexes", "") + .set("vision_config.hidden_act", "gelu_pytorch_tanh"); + return k; +} + /* A DFlash2 drafter merged under `draft.`: two layers reading trunk layers 1, 3 and 5, a block * of 8 (seven drafts), the selector of rank 64 over 8 candidates. */ MetaKV with_dflash2(MetaKV k) { @@ -6701,6 +6721,46 @@ TEST(qwen35moe_fp8_steps_lint_clean_with_its_routed_mtp_head) { lint_qwen35_fp8_family(qwen35moe_fp8::declare, qwen35moe_fp8::step, mk.meta(), 3, false, 0); } +/* The 35B-A3B-VL: the routed trunk and the vision tower declare together, the tower once and + * not a copy a rank, and the routed MTP head beside them -- Sage-A1.5's shape, which no fixture + * covered before (the MoE fixture had no tower, the VL fixture was dense). */ +TEST(qwen35moe_fp8_declares_the_vision_tower_beside_the_routed_trunk) { + MetaKV mk = q35moe_vl_meta(); + /* With no encoder budget the tower is not declared, whatever the container carries. */ + { + RadBuilder b; + RadBuildCtx ctx = vl_ctx(0); + REQUIRE_EQ(qwen35moe_fp8::declare(&b, mk.meta(), &ctx), RAD_OK); + CHECK(b.encoder_name.empty()); + CHECK(find_w(b, "v.patch.weight") == nullptr); + CHECK_EQ(count_op(b, "router_topk"), 8); + } + RadBuilder b; + RadBuildCtx ctx = vl_ctx(1024); + ctx.max_spec = 3; + REQUIRE_EQ(qwen35moe_fp8::declare(&b, mk.meta(), &ctx), RAD_OK); + + CHECK_EQ(b.encoder_name, std::string("vision")); + CHECK_EQ(b.encoder.modalities, (uint32_t)(RAD_MM_IMAGE | RAD_MM_VIDEO)); + CHECK_EQ(b.encoder.max_patches, 1024); + CHECK_EQ(b.encoder.n_embd, 5120); + CHECK_EQ(b.encoder.merge, 4); + + /* The trunk is still the routed one (eight blocks, plus the MTP layer's own router under + * --max-spec 3), and the shared expert is still folded in. */ + CHECK_EQ(count_op(b, "router_topk"), 9); + CHECK(count_op(b, "moe_gemm_q") >= 16); + + /* 3 stem + 12 a block + 6 merger, each mapped from the checkpoint's model.visual.*. */ + int nv = 0; + for (const auto& w : b.weights) + if (w.name.rfind("v.", 0) == 0) { + ++nv; + CHECK(find_map(b, w.name) != nullptr); + } + CHECK_EQ(nv, 3 + 12 * 2 + 6); +} + /* `layer_types` is checked against the interval rule, not ignored: a model built with the wrong * layers linear still generates fluent text. A disagreeing, short or unknown schedule is refused * by every plugin of the family; an agreeing one declares. */ diff --git a/tests/recipe_test.cpp b/tests/recipe_test.cpp index 2ac8b009..35fa45a7 100644 --- a/tests/recipe_test.cpp +++ b/tests/recipe_test.cpp @@ -175,4 +175,57 @@ TEST(the_nvfp4_recipe_decides_the_model_it_was_written_for) { CHECK(has_opt(dh, "codes", "u2")); } +/* The Sage-A1.5 recipe as it ships: every trunk linear -- attention, the delta net's in- and + * out-projections, the routed and shared experts of all 40 blocks and the MTP layer at its own + * index 40 -- goes to block fp8, the head likewise, and the routers, the shared-expert gates, + * the delta net's parameters, the norms, the embedding and the vision tower keep the + * checkpoint's form. */ +TEST(the_sage_recipe_decides_the_model_it_was_written_for) { + std::string dir = __FILE__; + dir = dir.substr(0, dir.find_last_of('/')) + "/../data/recipes"; + std::ifstream in(dir + "/sage-a1.5-fp8.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, "sage-a1.5-fp8.recipe", &why), RAD_OK); + CHECK_EQ(r.rules().size(), (size_t)12); + + const char* linears[] = { "blk.0.attn_qg.weight", "blk.3.attn_qg.weight", "blk.39.attn_qg.weight", + "blk.40.attn_qg.weight", "blk.3.attn_k.weight", "blk.3.attn_v.weight", + "blk.39.attn_output.weight", "blk.0.ssm_inz.weight", "blk.39.ssm_out.weight", + "blk.0.ffn_gate_up_exps.0.weight", "blk.19.ffn_down_exps.255.weight", + "blk.40.ffn_gate_up_exps.0.weight", "blk.40.ffn_down_exps.255.weight", + "blk.0.ffn_gate_up_shexp.weight", "blk.40.ffn_down_shexp.weight" }; + for (const char* n : linears) { + const RecipeRule* m = r.match(n); + REQUIRE(m != nullptr); + CHECK_EQ(m->quantizer, std::string("rtn")); + CHECK(has_opt(m, "codes", "fp8_e4m3")); + CHECK(has_opt(m, "block", "128x128")); + CHECK(has_opt(m, "scale", "bf16")); + } + const RecipeRule* head = r.match("output.weight"); + REQUIRE(head != nullptr); + CHECK(has_opt(head, "codes", "fp8_e4m3")); + CHECK(has_opt(head, "block", "128x128")); + const RecipeRule* dh = r.match("mtp.draft_head.weight"); + REQUIRE(dh != nullptr); + CHECK(has_opt(dh, "codes", "u2")); + CHECK(has_opt(dh, "zero", "u8")); + CHECK(has_opt(dh, "group", "128")); + CHECK(has_opt(dh, "scale", "f16")); + + /* kept as the checkpoint ships them: the routers, the gates, the delta net's parameters, + * the norms, the embedding and the whole vision tower */ + const char* kept[] = { "blk.0.ffn_norm.weight", "blk.0.attn_norm.weight", "blk.0.ssm_ab.weight", + "blk.0.ssm_conv1d.weight", "blk.0.ssm_a_log", "blk.0.ssm_dt.bias", + "blk.0.ssm_norm.weight", "blk.0.ffn_gate_inp.weight", + "blk.0.ffn_gate_shexp.weight", "blk.40.ffn_gate_inp.weight", + "token_embd.weight", "output_norm.weight", "mtp.fc.weight", + "mtp.norm.weight", "v.blk.0.qkv.weight", "v.merger.fc1.weight" }; + for (const char* n : kept) + CHECK(r.match(n) == nullptr); +} + RAD_TEST_MAIN()