This repository has been archived on 2026-11-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
radiance-sycl/tests/recipe_test.cpp
T
Deadcode 2a2b756371 radiance 2.1.0
New models. Recursive Flint (39.8B, about 2.5B active) by everplays (#422): `arch/flint`, as an
IQ8R container with rotated int8 experts or a four-bit one, with a sink-aware WMMA prefill
attention and the fused attention prologue at `rotary_dim` 0. Meta Muse Glimmer 30B by
launch80_assets (#423): bf16, an int4 trunk or IQ8R, its windowed vision tower, its DFlash
drafter, the ATEM tool dialect and context extension. Ling-3.0-tiny by RikshaDriver (#441):
served from its GGUF releases or as IQ8R on `bailing_hybrid`, with six more libr3d kernels. Block
FP8, MXFP4 and NVFP4 conversions of the three are not served. IQ8R containers of all three
(round to nearest, no calibration) are on Hugging Face under StillDeadcode: flint-iq8r,
muse-glimmer-30b-iq8r-dflash and ling-3.0-tiny-iq8r. They were checked for sane answers on two
R9700; nothing was benchmarked, and Muse Glimmer's pictures, video and tool calls were not tried.

Speech. Breeze-TTS-2 clones a voice from a reference recording and its transcript, with an
optional delivery direction, by farcryjohn (#436). The published Breeze container needs
converting again with the updated recipe before it can.

Tools. A model entry with `diagnose: DIR` runs a fixed workload on the engine instead of serving
and writes a report: step times, tokens a step, draft acceptance, TTFT and prefill rates by
category, concurrency and prompt length, and with `diagnose-baseline` a token-for-token comparison
against an earlier report (docs/DIAGNOSE.md), by Code000 (#418).

Scheduler. `mixed-step-target-ms` holds a mixed prefill and decode step to a service time, off by
default, by tnhnyzc (#413). `scheduler.stuck-exit` (60s by default, 0 never) ends the process when
the device has advanced nothing for that long, so a restart policy brings a hung server back
(#409, #415, #428).

Fixed. Draft trees with the int8 KV cache, which stopped Gemma 4 31B with DFlash2 on its first
request (#454, diagnosed by aelfwyne). The expert loan held at zero by a few leftover cache blocks
after long sessions (#455, diagnosed by thekk1). The mapped tier's pages kept in the page cache
across a load and a restore, by C_Tamas (#421). Replayed tool calls with blank arguments, and
arguments that are not JSON refused naming the call, by dschmitz (#444). The dashboard's card
temperature reads the junction sensor, by dschmitz (#453). The VRAM shortfall report says what the
KL mode needs, by baKon (#448). The out-of-tree plugin test builds its plugins in parallel and
takes its toolchain from the tree.

Plugin ABI 40: out-of-tree plugins need to be rebuilt.

Thanks to @everplays, @launch80_assets, @RikshaDriver, @farcryjohn, @Code000, @tnhnyzc, @C_Tamas, @dschmitz, @baKon, @aelfwyne and @thekk1.
2026-11-15 16:00:05 +01:00

481 lines
25 KiB
C++

/* recipe_test.cpp -- the rules rad-convert quantises by (core/format/recipe.h).
*
* A recipe decides every weight of a conversion that can take hours, and a rule that matches the
* wrong weights (or none) shows only when the container is measured afterwards. These cases pin
* the matching, the order and the two spellings to spec §4.4.
*/
#include "rad_test.h"
#include "format/recipe.h"
#include <cstdlib>
#include <fstream>
#include <iterator>
#include <string>
using namespace rad;
TEST(a_glob_matches_the_whole_name) {
CHECK(recipe_glob("blk.*.ffn_*_exps.*.weight", "blk.12.ffn_down_exps.511.weight"));
CHECK(recipe_glob("*", "output.weight"));
CHECK(recipe_glob("output.weight", "output.weight"));
CHECK(recipe_glob("blk.?.attn_q.weight", "blk.7.attn_q.weight"));
CHECK(!recipe_glob("blk.?.attn_q.weight", "blk.17.attn_q.weight")); /* ? is one character */
CHECK(recipe_glob("blk.*.weight", "blk.1.2.3.weight")); /* * crosses dots */
CHECK(!recipe_glob("blk.*.weight", "blk.1.scale"));
CHECK(!recipe_glob("output", "output.weight")); /* not a prefix match */
CHECK(recipe_glob("*_exps.*", "blk.0.ffn_gate_up_exps.3.weight"));
CHECK(recipe_glob("a*b*c", "aXXbYYbZc")); /* backtracks */
CHECK(!recipe_glob("a*b*c", "aXXbYY"));
}
TEST(the_first_rule_that_matches_decides) {
Recipe r;
std::string why;
REQUIRE_EQ(r.add_text("blk.*.ffn_down_exps.*.weight gptq codes=i4 group=128\n"
"blk.*.weight rtn codes=fp8_e4m3 block=128x128\n",
"r", &why), RAD_OK);
const RecipeRule* a = r.match("blk.3.ffn_down_exps.7.weight");
const RecipeRule* b = r.match("blk.3.attn_q.weight");
REQUIRE(a && b);
CHECK_EQ(a->quantizer, std::string("gptq"));
CHECK_EQ(b->quantizer, std::string("rtn"));
CHECK(r.match("output.weight") == nullptr); /* kept as the checkpoint holds it */
}
TEST(a_command_line_rule_goes_ahead_of_the_file) {
Recipe r;
std::string why;
REQUIRE_EQ(r.add_flag("output.weight=rtn:codes=fp8_e4m3,block=128x128,scale=bf16", &why),
RAD_OK);
REQUIRE_EQ(r.add_text("* rtn codes=i8 group=128\n", "file", &why), RAD_OK);
const RecipeRule* m = r.match("output.weight");
REQUIRE(m != nullptr);
CHECK_EQ(m->origin, std::string("--quant"));
CHECK_EQ(m->options.size(), (size_t)3);
CHECK_EQ(m->options[0].first, std::string("codes"));
CHECK_EQ(m->options[2].second, std::string("bf16"));
CHECK_EQ(r.match("blk.0.attn_q.weight")->origin, std::string("file:1"));
}
TEST(comments_and_blank_lines_are_not_rules_and_a_bad_line_is_named) {
Recipe r;
std::string why;
REQUIRE_EQ(r.add_text("# a recipe\n\n \nout* rtn codes=i8 # trailing\n", "x.recipe", &why),
RAD_OK);
CHECK_EQ(r.rules().size(), (size_t)1);
CHECK_EQ(r.rules()[0].options.size(), (size_t)1);
CHECK_EQ(r.rules()[0].origin, std::string("x.recipe:4"));
Recipe bad;
CHECK_EQ(bad.add_text("a rtn\nlonely\n", "y.recipe", &why), RAD_E_FORMAT);
CHECK(why.find("y.recipe:2") != std::string::npos);
CHECK_EQ(bad.add_text("a rtn group\n", "z", &why), RAD_E_FORMAT); /* not key=value */
CHECK_EQ(bad.add_text("a rtn k=1 k=2\n", "z", &why), RAD_E_FORMAT); /* given twice */
CHECK(why.find("twice") != std::string::npos);
CHECK_EQ(bad.add_flag("noquantiser", &why), RAD_E_FORMAT);
CHECK_EQ(bad.add_flag("p=:k=v", &why), RAD_E_FORMAT);
}
/* $NAME expands from the environment, so one recipe serves every machine. An unset name is
* refused: quantising against an empty calibration directory would silently do something else. */
TEST(a_variable_is_the_environments_and_an_unset_one_is_refused) {
::setenv("RAD_RECIPE_TEST_DIR", "/data/calib", 1);
::unsetenv("RAD_RECIPE_TEST_UNSET");
Recipe r;
std::string why;
REQUIRE_EQ(r.add_text("* gptq calib=$RAD_RECIPE_TEST_DIR/q38 tag=${RAD_RECIPE_TEST_DIR}x\n",
"v", &why), RAD_OK);
CHECK_EQ(r.rules()[0].options[0].second, std::string("/data/calib/q38"));
CHECK_EQ(r.rules()[0].options[1].second, std::string("/data/calibx"));
CHECK_EQ(r.add_text("* gptq calib=$RAD_RECIPE_TEST_UNSET\n", "v", &why), RAD_E_FORMAT);
CHECK(why.find("RAD_RECIPE_TEST_UNSET") != std::string::npos);
CHECK_EQ(r.add_text("* gptq calib=${RAD_RECIPE_TEST_DIR\n", "v", &why), RAD_E_FORMAT);
}
/* A container records the options in one canonical spelling, so --reuse compares two
* conversions by what they asked for, not by how the rule was typed. */
TEST(the_recorded_options_do_not_depend_on_how_they_were_written) {
Recipe a, b;
std::string why;
REQUIRE_EQ(a.add_text("* rtn scale=bf16 codes=i4 group=128\n", "a", &why), RAD_OK);
REQUIRE_EQ(b.add_flag("*=rtn:group=128,codes=i4,scale=bf16", &why), RAD_OK);
CHECK_EQ(a.rules()[0].options_text(), b.rules()[0].options_text());
CHECK_EQ(a.rules()[0].options_text(), std::string("codes=i4,group=128,scale=bf16"));
}
/* The recipe a container carries reads back as the same rules. */
TEST(the_recorded_recipe_reads_back_as_the_same_rules) {
Recipe r;
std::string why;
REQUIRE_EQ(r.add_flag("output.weight=rtn:codes=fp8_e4m3,block=128x128", &why), RAD_OK);
REQUIRE_EQ(r.add_text("blk.*.weight gptq codes=i4 group=128 damp=0.02\n", "f", &why), RAD_OK);
Recipe back;
REQUIRE_EQ(back.add_text(r.text(), "header", &why), RAD_OK);
REQUIRE_EQ(back.rules().size(), r.rules().size());
for (size_t i = 0; i < r.rules().size(); ++i) {
CHECK_EQ(back.rules()[i].pattern, r.rules()[i].pattern);
CHECK_EQ(back.rules()[i].quantizer, r.rules()[i].quantizer);
CHECK(back.rules()[i].options == r.rules()[i].options);
}
}
namespace {
bool has_opt(const RecipeRule* r, const char* k, const char* v) {
for (const auto& [kk, vv] : r->options)
if (kk == k && vv == v) return true;
return false;
}
} /* namespace */
/* 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<char>(in)), std::istreambuf_iterator<char>());
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);
}
/* The two Sage-A1.5 containers with the DFlash2 drafter in place of the MTP head: the trunk's
* rules unchanged in form (block fp8, or MXFP4 for the 4-bit sibling, whose lm_head stays block
* fp8), the drafter's linears in the trunk's form, its draft head the 2-bit copy, and no rule for
* an MTP head the container does not carry. The trunk's `blk.*` patterns do not reach the
* drafter's `dflash.blk.*` names, and the drafter's norms, selector and convolution stay as the
* checkpoint holds them. */
TEST(the_sage_dflash2_recipes_decide_the_trunk_and_the_drafter) {
std::string dir = __FILE__;
dir = dir.substr(0, dir.find_last_of('/')) + "/../data/recipes";
struct Case { const char* file; const char* codes; const char* grid_key; const char* grid; };
const Case cases[] = { { "sage-a1.5-fp8-df2.recipe", "fp8_e4m3", "block", "128x128" },
{ "sage-a1.5-mxfp4-df2.recipe", "fp4_e2m1", "group", "32" } };
for (const Case& c : cases) {
std::ifstream in(dir + "/" + c.file);
REQUIRE(in.good());
std::string text((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
Recipe r;
std::string why;
REQUIRE_EQ(r.add_text(text, c.file, &why), RAD_OK);
CHECK_EQ(r.rules().size(), (size_t)19);
const char* linears[] = { "blk.0.attn_qg.weight", "blk.39.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.39.ffn_down_exps.255.weight",
"blk.0.ffn_gate_up_shexp.weight", "blk.39.ffn_down_shexp.weight",
"dflash.fc.weight", "dflash.blk.0.attn_q.weight",
"dflash.blk.5.attn_k.weight", "dflash.blk.5.attn_v.weight",
"dflash.blk.5.attn_output.weight",
"dflash.blk.0.ffn_gate_up.weight",
"dflash.blk.5.ffn_down.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", c.codes));
CHECK(has_opt(m, c.grid_key, c.grid));
}
/* A drafter linear is decided by its own rule, not a trunk pattern. */
CHECK_EQ(r.match("dflash.blk.0.attn_k.weight")->pattern,
std::string("dflash.blk.*.attn_k.weight"));
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("dflash.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"));
const char* kept[] = { "blk.0.ffn_gate_inp.weight", "blk.0.ffn_gate_shexp.weight",
"blk.0.ssm_ab.weight", "blk.0.attn_norm.weight",
"token_embd.weight", "output_norm.weight",
"dflash.blk.0.attn_norm.weight", "dflash.norm.weight",
"dflash.hidden_norm.weight", "dflash.sel_proj.weight",
"dflash.blk.0.attn_conv_proj.weight",
"dflash.blk.0.ffn_conv_proj.weight", "mtp.draft_head.weight",
"v.blk.0.qkv.weight" };
for (const char* n : kept)
CHECK(r.match(n) == nullptr);
}
}
/* The Muse Glimmer recipes as they ship. The bf16 one is documentation only -- no rule, so every
* weight keeps the checkpoint's form. The w4a8 one routes every trunk linear to int4 on the
# 128-column grid (the value projection to int8), and nothing else: the layer norms, the
* embedding and the head match no rule. The patterns are the plugin's declared names:
* separate q and gate projections (this family's q_proj/gate_proj are two tensors), the gate|up
* concat, and the sliding/full two-group trunk. */
TEST(the_museglimmer_recipes_decide_the_model_they_were_written_for) {
const std::string dir = std::string(__FILE__).substr(
0, std::string(__FILE__).find_last_of('/')) + "/../data/recipes";
{
std::ifstream in(dir + "/museglimmer-30b-bf16.recipe");
REQUIRE(in.good());
std::string text((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
Recipe r;
std::string why;
REQUIRE_EQ(r.add_text(text, "museglimmer-30b-bf16.recipe", &why), RAD_OK);
CHECK_EQ(r.rules().size(), (size_t)0);
CHECK(r.match("blk.3.attn_q.weight") == nullptr);
}
{
std::ifstream in(dir + "/museglimmer-30b-w4a8.recipe");
REQUIRE(in.good());
std::string text((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
Recipe r;
std::string why;
REQUIRE_EQ(r.add_text(text, "museglimmer-30b-w4a8.recipe", &why), RAD_OK);
CHECK_EQ(r.rules().size(), (size_t)7);
const char* i4[] = { "blk.0.attn_q.weight", "blk.51.attn_k.weight", "blk.7.attn_gate.weight",
"blk.3.attn_output.weight", "blk.3.ffn_gate_up.weight",
"blk.3.ffn_down.weight" };
for (const char* n : i4) {
const RecipeRule* m = r.match(n);
REQUIRE(m != nullptr);
CHECK_EQ(m->quantizer, std::string("rtn"));
CHECK(has_opt(m, "codes", "i4"));
CHECK(has_opt(m, "group", "128"));
CHECK(has_opt(m, "scale", "f16"));
CHECK(has_opt(m, "rule", "search"));
}
const RecipeRule* v = r.match("blk.3.attn_v.weight");
REQUIRE(v != nullptr);
CHECK(has_opt(v, "codes", "i8"));
const char* kept[] = { "blk.3.attn_norm.weight", "blk.3.attn_post.weight",
"blk.3.ffn_norm.weight", "blk.3.ffn_post.weight",
"token_embd.weight", "output_norm.weight", "output.weight",
"model.vision_tower.layers.3.attn.q_proj.weight" };
for (const char* n : kept)
CHECK(r.match(n) == nullptr);
}
}
/* museglimmer-30b-iq8r as it ships: all seven trunk linears of every layer IQ8R, the head plain
* int8 (no rotation), and nothing else: the norms, the embedding, the vision tower and a merged
* drafter's `dspark.*` matrices match no rule. */
TEST(the_museglimmer_iq8r_recipe_decides_the_model_it_was_written_for) {
const std::string dir = std::string(__FILE__).substr(
0, std::string(__FILE__).find_last_of('/')) + "/../data/recipes";
std::ifstream in(dir + "/museglimmer-30b-iq8r.recipe");
REQUIRE(in.good());
std::string text((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
Recipe r;
std::string why;
REQUIRE_EQ(r.add_text(text, "museglimmer-30b-iq8r.recipe", &why), RAD_OK);
CHECK_EQ(r.rules().size(), (size_t)8);
const char* iq8r[] = { "blk.0.attn_q.weight", "blk.7.attn_gate.weight", "blk.51.attn_k.weight",
"blk.3.attn_v.weight", "blk.3.attn_output.weight",
"blk.0.ffn_gate_up.weight", "blk.51.ffn_down.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, "block2", "1x*"));
CHECK(has_opt(m, "transform", "fwht128"));
CHECK(has_opt(m, "clamp", "sym"));
CHECK(has_opt(m, "rule", "search"));
}
const RecipeRule* head = r.match("output.weight");
REQUIRE(head != nullptr);
CHECK(has_opt(head, "codes", "i8"));
CHECK(has_opt(head, "group", "128"));
CHECK(has_opt(head, "scale", "bf16"));
CHECK(!has_opt(head, "transform", "fwht128"));
const char* kept[] = { "blk.3.attn_norm.weight", "blk.3.attn_post.weight",
"blk.3.ffn_norm.weight", "blk.3.ffn_post.weight", "token_embd.weight",
"output_norm.weight", "v.blk.0.attn.q_proj.weight", "v.proj.weight",
"dspark.fc.weight", "dspark.blk.0.attn_q.weight",
"dspark.blk.4.ffn_down.weight",
"model.vision_tower.layers.3.attn.q_proj.weight" };
for (const char* n : kept)
CHECK(r.match(n) == nullptr);
}
/* The Flint recipes as they ship, over arch/flint's declared names. flint-iq8r: every trunk linear
* (attention, the two dense layers, the shared expert's gate/up) IQ8R, the routed experts and the
* shared expert's down projection rotated int8 at a bf16 scale a (row, 128 of K), the head plain
* int8. flint-bf16-q4: u4 attention, signed int4 experts, plain int8 dense, shared and head. In
* both the norms, the sinks, the router and its zero correction, and the embedding match no rule. */
TEST(the_flint_recipes_decide_the_model_they_were_written_for) {
const std::string dir = std::string(__FILE__).substr(
0, std::string(__FILE__).find_last_of('/')) + "/../data/recipes";
const char* kept[] = { "blk.0.attn_norm.weight", "blk.0.attn_q_norm.weight",
"blk.7.attn_k_norm.weight", "blk.0.attn_sinks", "blk.3.ffn_norm.weight",
"blk.3.glm_router.weight", "blk.3.glm_router.correction",
"token_embd.weight", "output_norm.weight" };
{
std::ifstream in(dir + "/flint-iq8r.recipe");
REQUIRE(in.good());
std::string text((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
Recipe r;
std::string why;
REQUIRE_EQ(r.add_text(text, "flint-iq8r.recipe", &why), RAD_OK);
CHECK_EQ(r.rules().size(), (size_t)13);
const char* iq8r[] = { "blk.0.attn_q.weight", "blk.48.attn_k.weight", "blk.3.attn_v.weight",
"blk.5.attn_output.weight", "blk.0.ffn_gate_up.weight",
"blk.1.ffn_down.weight", "blk.2.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* i8h[] = { "blk.2.ffn_gate_up_exps.0.weight", "blk.48.ffn_down_exps.255.weight",
"blk.17.ffn_down_shexp.weight" };
for (const char* n : i8h) {
const RecipeRule* m = r.match(n);
REQUIRE(m != nullptr);
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 RecipeRule* head = r.match("output.weight");
REQUIRE(head != nullptr);
CHECK(has_opt(head, "codes", "i8"));
CHECK(!has_opt(head, "transform", "fwht128"));
for (const char* n : kept) CHECK(r.match(n) == nullptr);
}
{
std::ifstream in(dir + "/flint-bf16-q4.recipe");
REQUIRE(in.good());
std::string text((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
Recipe r;
std::string why;
REQUIRE_EQ(r.add_text(text, "flint-bf16-q4.recipe", &why), RAD_OK);
const RecipeRule* a = r.match("blk.9.attn_output.weight");
REQUIRE(a != nullptr);
CHECK(has_opt(a, "codes", "u4"));
CHECK(has_opt(a, "zero", "u8"));
const RecipeRule* e = r.match("blk.30.ffn_down_exps.7.weight");
REQUIRE(e != nullptr);
CHECK(has_opt(e, "codes", "i4"));
for (const char* n : { "blk.1.ffn_gate_up.weight", "blk.40.ffn_down_shexp.weight",
"output.weight" }) {
const RecipeRule* m = r.match(n);
REQUIRE(m != nullptr);
CHECK(has_opt(m, "codes", "i8"));
}
for (const char* n : kept) CHECK(r.match(n) == nullptr);
}
}
/* The Ling-3.0-tiny IQ8R recipe as it ships, over arch/bailing_hybrid's declared names: the KDA
* projections (fused q|k|v, forget, output gate, out), the MLA out projection, the dense layer's
* pair and the shared expert's gate/up IQ8R; the routed experts and the shared expert's down
* projection rotated int8 at a bf16 scale a (row, 128 of K). The KDA beta, the MLA's low-rank q
* and kv projections, its query parts and its head gate, the convolution taps, the router, the
* embedding and the head match no rule and keep the checkpoint's bf16; the norms, the KDA
* parameters and the router are cast to the f32 the plugin declares. */
TEST(the_ling_tiny_iq8r_recipe_decides_the_model_it_was_written_for) {
const std::string dir = std::string(__FILE__).substr(
0, std::string(__FILE__).find_last_of('/')) + "/../data/recipes";
std::ifstream in(dir + "/ling-3.0-tiny-iq8r.recipe");
REQUIRE(in.good());
std::string text((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
Recipe r;
std::string why;
REQUIRE_EQ(r.add_text(text, "ling-3.0-tiny-iq8r.recipe", &why), RAD_OK);
CHECK_EQ(r.rules().size(), (size_t)20);
const char* iq8r[] = { "blk.0.attn_qkv.weight", "blk.22.attn_forget.weight",
"blk.1.attn_gate.weight", "blk.2.attn_output.weight",
"blk.3.attn_output.weight", "blk.0.ffn_gate_up.weight",
"blk.0.ffn_down.weight", "blk.1.ffn_gate_up_shexp.weight",
"blk.23.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* i8h[] = { "blk.1.ffn_gate_up_exps.0.weight", "blk.23.ffn_down_exps.127.weight",
"blk.7.ffn_down_shexp.weight" };
for (const char* n : i8h) {
const RecipeRule* m = r.match(n);
REQUIRE(m != nullptr);
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.3.attn_q_a_norm.weight",
"blk.3.attn_kv_a_norm.weight", "blk.1.ffn_norm.weight",
"blk.0.ssm_norm.weight", "blk.0.ssm_a", "blk.0.ssm_dt_bias",
"blk.1.glm_router.weight", "blk.1.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.3.attn_q_a.weight",
"blk.3.attn_q_rope.weight", "blk.3.attn_q_nope.weight",
"blk.3.attn_kv_a.weight", "blk.3.attn_kv_b.weight",
"blk.3.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()