Archived
Radiance becomes a multi-model engine: one process serves several models behind one port, loads each when a request names it, parks it in host memory or restores it from its container, and shares the cards between them (docs/MULTIMODEL.md). The configuration is one YAML file; the command line flags are gone (`radiance --config FILE`, hot reload on SIGHUP). Formats. IQ8R (rotated int8) and IQR-V4 replace FP8 and MXFP4 as whole-model formats, with an int8 KV cache (`kv-cache-dtype: i8`) in place of the fp8 one. Containers whose weights are block FP8, MXFP4, M2XFP4, NVFP4 or ParoQuant are refused at startup by the name of the first such weight. Not served until they have int8 containers: GLM-5.3-Flash, Ornith-1.5, Sage-A1.5, Nemotron-3.5-Bolt-74B, Ling-3.0-flash, drama-3 and Anima's FP8 container; Nemotron-3.5-Bolt-E4B, the Gemma 4 31B DFlash containers and MiniCPM5-2B bf16 serve without their drafter. 1.17.0 serves all of them. Speed. Chained launches for Qwen3.8-27B, Gemma 4, Gemma 3 and the small bf16 models, a new Qwen3.8-Flash-Next container (IQR-V4 experts, int8 trunk) with its decode step and prefill reworked, and a reworked adaptive draft window. Deployment. deploy/compose has two fleet files, tp1.yaml and tp2.yaml, each with its configuration beside it, in place of the per-model files. `host-pool-mib` is a model's host pool in all, split among its ranks. The dashboard is rebuilt: an hour of history kept by the server, each accelerator's memory by model, model states over time. Merged since 1.17.0: Nemotron-3.5-Bolt-74B-A9B by keptn42 (#339); GLM-5.3-Flash on four cards by AnimusNull (#397); chained launches for Flash-Next's decode step (#396) and preempted requests keeping their prefix and place (#405) by mici81; --prefill-interleave auto by Code000 (#410); eight more libr3d kernels and the w4a4 reference by RikshaDriver (#403, #407, #408); libr3d large-BAR and E4M3 decode fixes by neuromanMD (#438, #439); int4/int5 decode tiles by Kezi (#426); attention for Nanbeige 4.3 33B by everplays (#417); expert_stats_report.py by baKon (#431). Fixed: #398, #402, #419, #437 (dschmitz's patch); added the metrics of #392, and multi-model serving as asked for in #367 and #109. Plugin ABI 39: out-of-tree plugins need to be rebuilt. Thanks to @keptn42, @AnimusNull, @mici81, @Code000, @RikshaDriver, @neuromanMD, @Kezi, @everplays, @baKon and @dschmitz.
251 lines
13 KiB
C++
251 lines
13 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);
|
|
}
|
|
}
|
|
|
|
RAD_TEST_MAIN()
|