New models. Thinking Machines' Inkling 2 Mini by gostar (#584-#586): its text backbone and loop, the release's NVFP4 and MXFP8 checkpoint read by the converter, an int8 trunk, the vision tower, tensor parallelism, tool calls (with Warzuponus) and an image processor that matches transformers bit for bit (millaguie). Inkling's routed experts are served in IQR-V4's four-bit trellis (moe_gemm_iqr), fitted by GPTQ against Hessians the plugin now records (`--calib-dir`), its token embedding in int8 (read in place by embed_lookup), and incoai's DFlash2 drafter in four bits in place of the release's DSpark. That container, 14.4 GiB with the vision tower, decodes 190 / 427 / 658 tokens a second at 1 / 4 / 8 streams at tp 2 on two R9700 with `draft-window: adaptive` (code 240 / 550 / 790, step-by-step arithmetic 358 / 811 / 1116): 19-43% ahead of the same target with the release's DSpark drafter and 45-83% ahead of the all-int8 container (26.1 GiB, 124 / 263 / 386), at a mean KL of 0.0066 against the release's weights (int8: 0.0042). DeepSeek-V4.1-Flash on 2.x by baKon (#583), with its vision tower, its IQ1_S and IQ2_XXS containers and linears and experts served in llama.cpp's own blocks; parts ported from mikoskinen/r9700-exact-serving by Dad_Vibes' fork. GLM-5.3-Flash on 2.x with its IQR / IQ8R container, an int8 latent cache and four-card serving by AnimusNull (#566). Gemma 4 dense on EXL3-V3 by keptn42 (#537), on the EXL3 dense rows and qwen35_exl3 tensor parallelism by Hero422. NVIDIA's 2-bit Nemotron-3.5-Bolt-74B-A9B on one card by keptn42 (#477). Wan 2.2 TI2V-5B text-to-video and first-frame video by rkcth (#535). LFM3-1.7B on RDNA3 iGPUs by DokterSmol (#578). Qwen3.8-27B in bf16 with the DFlash2 drafter, and bf16x12, bf16 weights packed losslessly in 12.25 bits, by eddie168 (#577). Int8 experts for drama-3 by morevgalex (#598). Speculative decoding. Draft trees for Qwen3.8-27B's DFlash2 drafts by Kezi (#450, opt-in): one card, +17% at one stream and +14% at two. --draft-max-lanes and --draft-min-accept, two gates on a block drafter, and --draft-window-ckpt, its window KV kept in the checkpoint slots, by rkcth (#600-#602). `draft-window: adaptive` verifies each sequence's drafts up to the first one unlikely to be kept. A verify's rows share each K and V tile in Inkling's attention by gostar (#608): 93 to 118 tokens a second at a 70k-token prompt on one card. Generation. Krea 2 instruction edits with one or two references and registered outfill, LoRA on the image generators with bias deltas and row-mixer adapters applied per request, and MiniMax-H3's model-declared sparse attention profiles, by rkcth (#534, #542, #543, #605-#609). MiniMax-H3's audio reference guide pinned from a frame by 1beb (#595). LTX-2's chunk ceiling raised to 40 by Itoash (#570). Fleets and memory. memory.queue-reserve, the hardware queues a card keeps ready, by kevinjd (#589). memory.pinned-numa-node by Foundry (#580). memory.card-headroom-mib on single-model tensor-parallel budgets by zihaomu (#624). Parked weights rebuilt on the CPU, memory ownership kept across a failed handoff and quiescent callbacks serialised, by rkcth (#557-#561). A warm load may unload a parked model (#592); the first card listed chooses the architecture (#458). Kernels. libr3d's packed dense IQR GEMM and routed IQR expert rows on gfx1100, and libhalo's GEMV decode for Qwen3.8-Flash-Next's MoE down, by zihaomu (#562, #620, #622). GGML IQ2_XXS and IQ3_XXS packed on the card by baKon. Dashboard. KV cache in tokens (in use, capacity now and with all flexible space), live figures through long prefill steps, step / decode / prefill / acceptance lines without holes, and expert hit rates only on tiered models. Seven tile and history defects fixed by Noblistic (#597), vision encoder and per-card hardware figures by davetha (#574), per-LoRA attribution by dowjames (#552). Fixed. return_tokens / return_token_ids on the OpenAI endpoints (#571). reasoning_effort "none" and "minimal" reach a template that takes them as levels, by millaguie (#608). Misaligned loads in the windowed paged attention over an int8 cache (#540). A retired 27B head refused by name (#541). rad-convert's GPU trellis jobs kept fed, and --reuse-only, by gostar (#575). jinja's tojson takes sort_keys by Warzuponus (#582). hfget measures file sizes with stat, by kepler_62f (#623). The tested C++ compiler is stated in the build guide by lowell80 (#551). The codebase was cleaned up: shared helpers instead of repeated blocks, and the int8 linear, activation and GEMM code no longer named after the retired fp8 formats. Inkling 2 Mini is served in one form: IQR-V4 experts with the DFlash2 drafter (StillDeadcode/inkling-2-mini-iq4r-v4 on Hugging Face, or data/recipes/inkling2-mini-iq4r-v4.recipe). A container with the release's DSpark drafter, or with NVFP4, int8 or 4-bit experts, is refused by name and needs converting again. Plugin ABI 44: out-of-tree plugins need to be rebuilt. Thanks to @gostar, @baKon, @Dad_Vibes, @AnimusNull, @keptn42, @Hero422, @rkcth, @DokterSmol, @eddie168, @morevgalex, @Kezi, @1beb, @Itoash, @kevinjd, @Foundry, @zihaomu, @Noblistic, @davetha, @dowjames, @Warzuponus, @millaguie, @kepler_62f, @lowell80 and @Code000.
284 lines
13 KiB
C++
284 lines
13 KiB
C++
/* clef_test.cpp -- clef's prompt, spans and answer (core/server/clef.h).
|
|
*
|
|
* The head reads spans of the prompt, so the spans are checked as text: the ids of a question's
|
|
* span decode to its rendered instructions, an option's to its rendered semantics. With a
|
|
* tokenizer.json from a clef release in RAD_CLEF_DIR, the ids and spans are also compared with
|
|
* the release's own encode_record over tests/data/golden/clef_encode.json (clef_encode_gen.py).
|
|
*/
|
|
#include "rad_test.h"
|
|
|
|
#include "server/adapters.h"
|
|
#include "server/clef.h"
|
|
#include "text/tokenizer.h"
|
|
#include "rad_clef.h"
|
|
|
|
#include "util/json.h"
|
|
|
|
#include <cmath>
|
|
#include <cstdlib>
|
|
#include <fstream>
|
|
|
|
using namespace rad;
|
|
using namespace rad::server;
|
|
|
|
namespace {
|
|
|
|
/* One id a byte, so a prompt decodes back to its exact text and a span to its exact piece. */
|
|
struct ByteTokenizer : ITokenizer {
|
|
std::vector<int32_t> encode(const std::string& s, bool, bool) const override {
|
|
std::vector<int32_t> v;
|
|
for (unsigned char c : s) v.push_back(c);
|
|
return v;
|
|
}
|
|
std::string token_bytes(int32_t id) const override { return std::string(1, (char)id); }
|
|
std::string decode(const std::vector<int32_t>& t) const override {
|
|
std::string s;
|
|
for (int32_t x : t) s += (char)x;
|
|
return s;
|
|
}
|
|
int32_t eos() const override { return 0; }
|
|
int32_t bos() const override { return -1; }
|
|
std::unique_ptr<IDetokenizer> detokenizer(const std::vector<std::string>&,
|
|
const std::vector<std::string>&) const override {
|
|
return nullptr;
|
|
}
|
|
};
|
|
|
|
int parse(const ITokenizer& tok, const std::string& body, ClefRequest* r, ApiError* e,
|
|
int64_t max_ctx = 0) {
|
|
OaiDeps d;
|
|
d.tok = const_cast<ITokenizer*>(&tok);
|
|
OaiLimits l;
|
|
l.model_id = "clef-flash";
|
|
l.max_ctx = max_ctx;
|
|
return parse_clef_request(body, d, l, "clef-flash", r, e);
|
|
}
|
|
|
|
std::string span(const ITokenizer& tok, const ClefRequest& r, TokenSpan s) {
|
|
return tok.decode(std::vector<int32_t>(r.tokens.begin() + s.first, r.tokens.begin() + s.second));
|
|
}
|
|
|
|
const char* const kBody = R"({"state": "I was charged twice.",
|
|
"questions": {
|
|
"refund": {"type": "noul", "instructions": "Refund?"},
|
|
"team": {"type": "choice", "instructions": "Which team?",
|
|
"criteria": {"technical": "Faults", "billing": "Charges"}},
|
|
"urgency": {"type": "score", "instructions": "How urgent?", "criteria": ["Later", "Now"]}}})";
|
|
|
|
} /* namespace */
|
|
|
|
TEST(the_prompt_is_the_releases_text) {
|
|
ByteTokenizer tok;
|
|
ClefRequest r;
|
|
ApiError e;
|
|
CHECK_OK(parse(tok, kBody, &r, &e));
|
|
CHECK_EQ(tok.decode(r.tokens),
|
|
"<|im_start|>system\nRead the complete state and schema. Decide every field jointly. "
|
|
"Each answer must be exactly one of that field's allowed options.<|im_end|>\n"
|
|
"<|im_start|>user\nSTATE:\nI was charged twice."
|
|
"\n\nSCHEMA FIELDS:\n"
|
|
"\nFIELD 1\nID: refund\nTYPE: noul\nINSTRUCTION: Refund?\nALLOWED OPTIONS:\n"
|
|
"OPTION 1: {\"description\":\"The proposition is true or the answer is yes.\",\"option_id\":\"true\"}\n"
|
|
"OPTION 2: {\"description\":\"The proposition is false or the answer is no.\",\"option_id\":\"false\"}\n"
|
|
"END FIELD\n"
|
|
"\nFIELD 2\nID: team\nTYPE: choice\nINSTRUCTION: Which team?\nALLOWED OPTIONS:\n"
|
|
"OPTION 1: {\"description\":\"Charges\",\"option_id\":\"billing\"}\n"
|
|
"OPTION 2: {\"description\":\"Faults\",\"option_id\":\"technical\"}\n"
|
|
"END FIELD\n"
|
|
"\nFIELD 3\nID: urgency\nTYPE: score\nINSTRUCTION: How urgent?\nALLOWED OPTIONS:\n"
|
|
"OPTION 1: {\"description\":\"Later\",\"option_id\":\"0\"}\n"
|
|
"OPTION 2: {\"description\":\"Now\",\"option_id\":\"1\"}\n"
|
|
"END FIELD\n"
|
|
"\n<|im_end|>\n<|im_start|>assistant\n<think>\n\n</think>\n\nJOINT SCHEMA DECISIONS:");
|
|
}
|
|
|
|
TEST(spans_cover_the_instructions_and_each_options_semantics) {
|
|
ByteTokenizer tok;
|
|
ClefRequest r;
|
|
ApiError e;
|
|
CHECK_OK(parse(tok, kBody, &r, &e));
|
|
REQUIRE(r.questions.size() == 3);
|
|
CHECK_EQ(span(tok, r, r.questions[0].question), "Refund?");
|
|
CHECK_EQ(r.questions[1].type_id, 1);
|
|
/* A choice's options are scored sorted; the response keeps the request's order. */
|
|
CHECK(r.questions[1].options == (std::vector<std::string>{ "billing", "technical" }));
|
|
CHECK(r.questions[1].response_order == (std::vector<std::string>{ "technical", "billing" }));
|
|
CHECK_EQ(span(tok, r, r.questions[1].option_spans[0]),
|
|
"{\"description\":\"Charges\",\"option_id\":\"billing\"}");
|
|
CHECK_EQ(span(tok, r, r.questions[2].option_spans[1]), "{\"description\":\"Now\",\"option_id\":\"1\"}");
|
|
}
|
|
|
|
TEST(render_sorts_keys_and_keeps_unicode) {
|
|
CHECK_EQ(clef_render(json::parse(R"({"b": [1, 2.5, null], "a": "ü\n"})")),
|
|
"{\"a\":\"ü\\n\",\"b\":[1,2.5,null]}");
|
|
CHECK_EQ(clef_render(json("as is")), "as is");
|
|
}
|
|
|
|
TEST(bad_requests_are_400s) {
|
|
ByteTokenizer tok;
|
|
ClefRequest r;
|
|
ApiError e;
|
|
CHECK(parse(tok, R"({"questions": {"q": {"type": "noul"}}})", &r, &e) < 0);
|
|
CHECK_EQ(e.param, "state");
|
|
CHECK(parse(tok, R"({"state": "", "questions": {"q": {"type": "noul"}}})", &r, &e) < 0);
|
|
CHECK(parse(tok, R"({"state": "s", "questions": {}})", &r, &e) < 0);
|
|
CHECK_EQ(e.param, "questions");
|
|
CHECK(parse(tok, R"({"state": "s", "questions": {"q": {"instructions": "x"}}})", &r, &e) < 0);
|
|
CHECK_EQ(e.param, "questions.q.type");
|
|
CHECK(parse(tok, R"({"state": "s", "questions": {"q": {"type": "choice", "criteria": {}}}})", &r, &e) < 0);
|
|
CHECK_EQ(e.param, "questions.q.criteria");
|
|
CHECK(parse(tok, R"({"state": "s", "questions": {"q": {"type": "noul", "criteria": {"maybe": "x"}}}})", &r, &e) < 0);
|
|
CHECK(parse(tok, R"({"state": "s", "questions": {"q": {"type": "noul"}}, "extra": 1})", &r, &e) < 0);
|
|
CHECK(parse(tok, R"({"model": "other", "state": "s", "questions": {"q": {"type": "noul"}}})", &r, &e) < 0);
|
|
CHECK_EQ(e.param, "model");
|
|
/* The whole prompt must fit; nothing is cut. */
|
|
CHECK(parse(tok, kBody, &r, &e, 100) < 0);
|
|
CHECK_EQ(e.code, "context_length_exceeded");
|
|
/* And it fits the head's own bound, whatever the context: a byte a token here. */
|
|
const std::string huge = R"({"state": ")" + std::string(RAD_CLEF_MAX_PROMPT, 'x') +
|
|
R"(", "questions": {"q": {"type": "noul"}}})";
|
|
CHECK(parse(tok, huge, &r, &e, 0) < 0);
|
|
CHECK_EQ(e.code, "context_length_exceeded");
|
|
CHECK_EQ(e.n_ctx, (int64_t)RAD_CLEF_MAX_PROMPT);
|
|
}
|
|
|
|
TEST(answers_are_softmaxes_in_the_releases_shape) {
|
|
ByteTokenizer tok;
|
|
ClefRequest r;
|
|
ApiError e;
|
|
CHECK_OK(parse(tok, kBody, &r, &e));
|
|
json a;
|
|
CHECK_OK(clef_answer(r.questions[0], { 2.0f, 0.0f }, &a, &e));
|
|
CHECK_EQ(a["noul"].get<double>(), std::round(1.0 / (1.0 + std::exp(-2.0)) * 1e4) / 1e4);
|
|
/* Options in head order (billing, technical); the response in request order. */
|
|
CHECK_OK(clef_answer(r.questions[1], { 0.0f, 1.0f }, &a, &e));
|
|
CHECK_EQ(a["choice"].get<std::string>(), "technical");
|
|
CHECK_EQ(a["probabilities"].begin().key(), "technical");
|
|
double total = 0.0;
|
|
for (const auto& kv : a["probabilities"].items()) total += kv.value().get<double>();
|
|
CHECK(std::fabs(total - 1.0) < 1e-3);
|
|
CHECK_OK(clef_answer(r.questions[2], { 0.0f, 0.0f }, &a, &e));
|
|
CHECK_EQ(a["score"].get<double>(), 0.5);
|
|
CHECK_EQ(a["legend"]["1"].get<std::string>(), "Now");
|
|
CHECK(clef_answer(r.questions[2], { 0.0f, NAN }, &a, &e) < 0);
|
|
CHECK(clef_answer(r.questions[2], { 0.0f }, &a, &e) < 0);
|
|
}
|
|
|
|
/* The request's words for the head: the prompt cut into segments at every span's edges, each
|
|
* span one whole segment, every option's tokens as the prompt holds them. */
|
|
TEST(the_words_cut_the_prompt_at_every_span_and_carry_the_option_tokens) {
|
|
ByteTokenizer tok;
|
|
ClefRequest r;
|
|
ApiError e;
|
|
CHECK_OK(parse(tok, kBody, &r, &e));
|
|
std::vector<int32_t> w;
|
|
CHECK_OK(clef_words(r, &w, &e));
|
|
const RadClefWords L = rad_clef_words_read(w.data());
|
|
CHECK_EQ((size_t)L.total, w.size());
|
|
CHECK_EQ(L.n, (int32_t)r.tokens.size());
|
|
CHECK_EQ(L.q, 3);
|
|
CHECK_EQ(L.o, 6);
|
|
CHECK_EQ(clef_option_count(r), (int64_t)6);
|
|
/* 9 spans, none adjacent: 18 cuts plus the ends, so 19 segments. */
|
|
CHECK_EQ(L.s, 19);
|
|
CHECK_EQ(w[(size_t)L.seg_cu], 0);
|
|
CHECK_EQ(w[(size_t)(L.seg_cu + L.s)], L.n);
|
|
for (int32_t i = 0; i < L.s; ++i) CHECK(w[(size_t)(L.seg_cu + i)] < w[(size_t)(L.seg_cu + i + 1)]);
|
|
/* Each question's segment is exactly its instruction span. */
|
|
for (size_t qi = 0; qi < r.questions.size(); ++qi) {
|
|
const int32_t s = w[(size_t)(L.q_seg + (int32_t)qi)];
|
|
CHECK_EQ((int64_t)w[(size_t)(L.seg_cu + s)], r.questions[qi].question.first);
|
|
CHECK_EQ((int64_t)w[(size_t)(L.seg_cu + s + 1)], r.questions[qi].question.second);
|
|
CHECK_EQ(w[(size_t)(L.type + (int32_t)qi)], r.questions[qi].type_id);
|
|
}
|
|
CHECK_EQ(w[(size_t)L.opt_cu], 0);
|
|
CHECK_EQ(w[(size_t)(L.opt_cu + 1)], 2);
|
|
CHECK_EQ(w[(size_t)(L.opt_cu + 3)], 6);
|
|
/* Option 2 is the choice's first option, "billing": its segment is its span and its tokens
|
|
* are the prompt's there. */
|
|
const TokenSpan sp = r.questions[1].option_spans[0];
|
|
const int32_t os = w[(size_t)(L.o_seg + 2)];
|
|
CHECK_EQ((int64_t)w[(size_t)(L.seg_cu + os)], sp.first);
|
|
CHECK_EQ(w[(size_t)(L.o_q + 2)], 1);
|
|
const int32_t l0 = w[(size_t)(L.lex_cu + 2)], l1 = w[(size_t)(L.lex_cu + 3)];
|
|
CHECK_EQ((int64_t)(l1 - l0), sp.second - sp.first);
|
|
std::vector<int32_t> lex(w.begin() + L.lex_ids + l0, w.begin() + L.lex_ids + l1);
|
|
CHECK_EQ(tok.decode(lex), "{\"description\":\"Charges\",\"option_id\":\"billing\"}");
|
|
CHECK_EQ(w[(size_t)(L.lex_cu + L.o)], L.l);
|
|
CHECK_EQ(w[(size_t)L.last], L.n - 1);
|
|
CHECK_EQ(w[(size_t)L.cu_k + 1], L.n);
|
|
CHECK_EQ(w[(size_t)L.cu_o + 1], L.o);
|
|
CHECK((int32_t)w.size() <= rad_clef_max_words());
|
|
/* The head's three values an option land in three stretches of the logits row. */
|
|
const std::vector<int32_t> ids = clef_score_ids(6);
|
|
REQUIRE_EQ(ids.size(), (size_t)18);
|
|
CHECK_EQ(ids[6], (int32_t)RAD_CLEF_MAX_OPTIONS);
|
|
CHECK_EQ(ids[17], (int32_t)(2 * RAD_CLEF_MAX_OPTIONS + 5));
|
|
}
|
|
|
|
TEST(too_many_questions_are_a_400) {
|
|
ByteTokenizer tok;
|
|
std::string body = R"({"state": "s", "questions": {)";
|
|
for (int i = 0; i <= RAD_CLEF_MAX_QUESTIONS; ++i)
|
|
body += (i ? "," : "") + std::string("\"q") + std::to_string(i) + R"(": {"type": "noul"})";
|
|
body += "}}";
|
|
ClefRequest r;
|
|
ApiError e;
|
|
CHECK_OK(parse(tok, body, &r, &e));
|
|
std::vector<int32_t> w;
|
|
CHECK(clef_words(r, &w, &e) < 0);
|
|
CHECK_EQ(e.param, "questions");
|
|
}
|
|
|
|
/* exp(prior_scale) * prior + sigmoid(gate) * (exp(joint_scale) * cosine + residual), the scales
|
|
* clamped at 100. The release's clef-flash values: both scales 2.296875, the gate -2. */
|
|
TEST(the_scalars_combine_the_heads_three_values) {
|
|
ClefScalars s;
|
|
s.prior_logit_scale = std::log(2.0);
|
|
s.joint_logit_scale = std::log(4.0);
|
|
s.residual_gate = 0.0; /* sigmoid 0.5 */
|
|
const std::vector<float> v = { 1.0f, 2.0f, /* prior */
|
|
0.5f, 0.25f, /* cosine */
|
|
3.0f, -1.0f }; /* residual */
|
|
const std::vector<float> l = clef_logits(v, 2, s);
|
|
CHECK(std::fabs(l[0] - (2.0 * 1.0 + 0.5 * (4.0 * 0.5 + 3.0))) < 1e-5);
|
|
CHECK(std::fabs(l[1] - (2.0 * 2.0 + 0.5 * (4.0 * 0.25 - 1.0))) < 1e-5);
|
|
s.prior_logit_scale = 10.0; /* past the clamp: 100 */
|
|
CHECK(std::fabs(clef_logits(v, 2, s)[0] - (100.0 + 0.5 * 5.0)) < 1e-3);
|
|
}
|
|
|
|
TEST(ids_and_spans_match_the_releases_encode_record) {
|
|
const char* dir = std::getenv("RAD_CLEF_DIR");
|
|
if (!dir) SKIP("RAD_CLEF_DIR names no clef release with a tokenizer.json");
|
|
VocabBuild vb;
|
|
REQUIRE(parse_tokenizer_json((std::string(dir) + "/tokenizer.json").c_str(), vb) == RAD_OK);
|
|
auto vocab = std::make_shared<Vocab>();
|
|
REQUIRE(vocab->load(std::move(vb)) == RAD_OK);
|
|
TokenizerBridge tok(vocab);
|
|
std::ifstream f(std::string(RAD_GOLDEN_FIXTURES) + "/clef_encode.json");
|
|
REQUIRE(f.is_open());
|
|
for (const auto& g : json::parse(f)) { /* ordered: the questions keep their order */
|
|
ClefRequest r;
|
|
ApiError e;
|
|
CHECK_OK(parse(tok, g["request"].dump(), &r, &e));
|
|
CHECK(r.tokens == g["input_ids"].get<std::vector<int32_t>>());
|
|
REQUIRE(r.questions.size() == g["questions"].size());
|
|
for (size_t i = 0; i < r.questions.size(); ++i) {
|
|
const auto& gq = g["questions"][i];
|
|
const ClefQuestion& q = r.questions[i];
|
|
CHECK_EQ(q.name, gq["id"].get<std::string>());
|
|
CHECK_EQ(q.type_id, gq["type"].get<int>());
|
|
CHECK_EQ(q.question.first, gq["span"][0].get<int64_t>());
|
|
CHECK_EQ(q.question.second, gq["span"][1].get<int64_t>());
|
|
CHECK(q.options == gq["option_ids"].get<std::vector<std::string>>());
|
|
REQUIRE(q.option_spans.size() == gq["option_spans"].size());
|
|
for (size_t k = 0; k < q.option_spans.size(); ++k) {
|
|
CHECK_EQ(q.option_spans[k].first, gq["option_spans"][k][0].get<int64_t>());
|
|
CHECK_EQ(q.option_spans[k].second, gq["option_spans"][k][1].get<int64_t>());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
RAD_TEST_MAIN()
|