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.
289 lines
11 KiB
C++
289 lines
11 KiB
C++
/* gen_config_test.cpp -- the sampling a checkpoint states for itself.
|
|
*
|
|
* SamplingParams' defaults are an untruncated sampler. A model tuned with a truncated tail and
|
|
* served that way occasionally draws a token from far down its distribution; end-of-turn is one
|
|
* such token, so the symptom is a reply that ends early and looks like a dropped request. A wrong
|
|
* default is silent, hence a tested component.
|
|
*
|
|
* No model and no container: the three sources (a string, a file and a key lookup) are reached
|
|
* directly.
|
|
*/
|
|
#include "rad_test.h"
|
|
|
|
#include "gen_config.h"
|
|
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <functional>
|
|
#include <map>
|
|
#include <string>
|
|
|
|
using namespace rad;
|
|
|
|
namespace {
|
|
|
|
/* The container's metadata table as gen_sampling_from_kv sees it: bare field names and string
|
|
* values, as rad-convert writes free-form metadata. */
|
|
std::function<const char*(const char*)> kv_of(const std::map<std::string, std::string>& m) {
|
|
return [&m](const char* k) -> const char* {
|
|
auto it = m.find(k);
|
|
return it == m.end() ? nullptr : it->second.c_str();
|
|
};
|
|
}
|
|
|
|
std::string write_temp(const char* name, const std::string& body) {
|
|
const std::string path = radtest::tmp_path(std::string(name) + ".json");
|
|
FILE* f = std::fopen(path.c_str(), "w");
|
|
if (!f) return std::string();
|
|
std::fwrite(body.data(), 1, body.size(), f);
|
|
std::fclose(f);
|
|
return path;
|
|
}
|
|
|
|
/* Qwen3.8-Flash-Next's generation_config.json, verbatim. */
|
|
const char* const kQwenGenConfig = R"({
|
|
"bos_token_id": 248044,
|
|
"do_sample": true,
|
|
"eos_token_id": [248046, 248044],
|
|
"pad_token_id": 248044,
|
|
"temperature": 1.0,
|
|
"top_k": 20,
|
|
"top_p": 0.95
|
|
})";
|
|
|
|
} /* namespace */
|
|
|
|
TEST(gen_config_reads_a_real_generation_config) {
|
|
GenSampling g;
|
|
CHECK(gen_sampling_parse(kQwenGenConfig, "test", &g));
|
|
CHECK_NEAR(g.temp, 1.0f, 1e-6);
|
|
CHECK_EQ(g.top_k, 20);
|
|
CHECK_NEAR(g.top_p, 0.95f, 1e-6);
|
|
CHECK_NEAR(g.min_p, -1.0f, 1e-6); /* not in the file, so not claimed */
|
|
|
|
/* Overlaid on the built-in defaults, it truncates the tail. */
|
|
const SamplingParams sp = g.onto(SamplingParams{});
|
|
CHECK_NEAR(sp.temp, 1.0f, 1e-6);
|
|
CHECK_EQ(sp.top_k, 20);
|
|
CHECK_NEAR(sp.top_p, 0.95f, 1e-6);
|
|
CHECK_NEAR(sp.min_p, 0.0f, 1e-6); /* untouched: the struct's default */
|
|
CHECK(!sp.greedy());
|
|
}
|
|
|
|
/* A field a source did not state is not claimed, so sources stack: a sidecar that sets only
|
|
* top_k keeps the temperature underneath it. */
|
|
TEST(gen_config_claims_only_what_a_source_states) {
|
|
GenSampling g;
|
|
CHECK(gen_sampling_parse(R"({"top_k": 40})", "test", &g));
|
|
CHECK_EQ(g.top_k, 40);
|
|
CHECK(g.temp < 0.0f);
|
|
CHECK(g.top_p < 0.0f);
|
|
|
|
SamplingParams base;
|
|
base.temp = 0.6f;
|
|
base.top_p = 0.8f;
|
|
const SamplingParams sp = g.onto(base);
|
|
CHECK_NEAR(sp.temp, 0.6f, 1e-6);
|
|
CHECK_NEAR(sp.top_p, 0.8f, 1e-6);
|
|
CHECK_EQ(sp.top_k, 40);
|
|
|
|
GenSampling none;
|
|
CHECK(!gen_sampling_parse(R"({"bos_token_id": 1})", "test", &none));
|
|
CHECK(!none.any());
|
|
}
|
|
|
|
/* `do_sample: false` is greedy and transformers ignores every other sampler field under it. */
|
|
TEST(gen_config_reads_do_sample_false_as_greedy) {
|
|
GenSampling g;
|
|
CHECK(gen_sampling_parse(R"({"do_sample": false, "temperature": 0.7, "top_k": 20})",
|
|
"test", &g));
|
|
CHECK_NEAR(g.temp, 0.0f, 1e-6);
|
|
CHECK_EQ(g.top_k, -1); /* not claimed under greedy */
|
|
CHECK(g.onto(SamplingParams{}).greedy());
|
|
|
|
/* do_sample true claims nothing by itself. */
|
|
GenSampling t;
|
|
CHECK(gen_sampling_parse(R"({"do_sample": true, "temperature": 0.7})", "test", &t));
|
|
CHECK_NEAR(t.temp, 0.7f, 1e-6);
|
|
}
|
|
|
|
/* transformers spells "no top_k" as -1 and this sampler spells it 0. */
|
|
TEST(gen_config_translates_top_k_minus_one_to_off) {
|
|
GenSampling g;
|
|
CHECK(gen_sampling_parse(R"({"top_k": -1})", "test", &g));
|
|
CHECK_EQ(g.top_k, 0);
|
|
}
|
|
|
|
/* The startup line names what top_k 0 does: the sampler draws from its 1024 most likely
|
|
* candidates, which is neither "off" nor the whole vocabulary. */
|
|
TEST(the_sampling_line_says_what_top_k_zero_samples_from) {
|
|
SamplingParams sp;
|
|
sp.top_k = 0;
|
|
const std::string zero = GenSampling::describe(sp);
|
|
CHECK(has(zero, "top_k 0 (the 1024 most likely tokens"));
|
|
CHECK(!has(zero, "(off)"));
|
|
sp.top_k = 20;
|
|
const std::string twenty = GenSampling::describe(sp);
|
|
CHECK(has(twenty, "top_k 20, top_p"));
|
|
}
|
|
|
|
/* An out-of-range value is dropped on its own, not refused: the config ships with the model,
|
|
* and one implausible entry should not discard the rest. */
|
|
TEST(gen_config_drops_an_out_of_range_field_and_keeps_the_rest) {
|
|
GenSampling g;
|
|
CHECK(gen_sampling_parse(R"({"temperature": 9.0, "top_p": 0.95, "top_k": 20})", "test", &g));
|
|
CHECK(g.temp < 0.0f); /* 9.0 is out of range, so not claimed */
|
|
CHECK_NEAR(g.top_p, 0.95f, 1e-6);
|
|
CHECK_EQ(g.top_k, 20);
|
|
|
|
/* top_p is a half-open range: 0 is not a nucleus, 1 is. */
|
|
GenSampling z;
|
|
CHECK(!gen_sampling_parse(R"({"top_p": 0.0})", "test", &z));
|
|
GenSampling one;
|
|
CHECK(gen_sampling_parse(R"({"top_p": 1.0})", "test", &one));
|
|
CHECK_NEAR(one.top_p, 1.0f, 1e-6);
|
|
}
|
|
|
|
TEST(gen_config_survives_text_that_is_not_a_config) {
|
|
GenSampling g;
|
|
CHECK(!gen_sampling_parse("{not json", "test", &g));
|
|
CHECK(!gen_sampling_parse("[1, 2, 3]", "test", &g));
|
|
CHECK(!gen_sampling_parse("", "test", &g));
|
|
CHECK(!g.any());
|
|
}
|
|
|
|
/* The container's copy, where rad-convert flattened every value to a string, and the original
|
|
* file resolve to the same sampler. */
|
|
TEST(gen_config_reads_the_container_table_as_the_file) {
|
|
GenSampling from_file;
|
|
CHECK(gen_sampling_parse(kQwenGenConfig, "test", &from_file));
|
|
|
|
const std::map<std::string, std::string> table = {
|
|
{ "do_sample", "1" },
|
|
{ "temperature", "1" },
|
|
{ "top_k", "20" },
|
|
{ "top_p", "0.95" },
|
|
};
|
|
GenSampling from_kv;
|
|
CHECK(gen_sampling_from_kv(kv_of(table), &from_kv));
|
|
CHECK_NEAR(from_kv.temp, from_file.temp, 1e-6);
|
|
CHECK_EQ(from_kv.top_k, from_file.top_k);
|
|
CHECK_NEAR(from_kv.top_p, from_file.top_p, 1e-6);
|
|
|
|
/* An empty table states nothing rather than stating zeros. */
|
|
GenSampling empty;
|
|
CHECK(!gen_sampling_from_kv(kv_of({}), &empty));
|
|
CHECK(!empty.any());
|
|
|
|
/* A value that is not a number is dropped, and the rest of the table still reads. */
|
|
GenSampling junk;
|
|
CHECK(gen_sampling_from_kv(kv_of({ { "temperature", "warm" }, { "top_k", "20" } }), &junk));
|
|
CHECK(junk.temp < 0.0f);
|
|
CHECK_EQ(junk.top_k, 20);
|
|
}
|
|
|
|
TEST(gen_config_reads_a_file_and_treats_absence_as_silence) {
|
|
const std::string path = write_temp("sidecar", kQwenGenConfig);
|
|
CHECK(!path.empty());
|
|
GenSampling g;
|
|
CHECK(gen_sampling_from_file(path, /*required=*/false, &g));
|
|
CHECK_EQ(g.top_k, 20);
|
|
|
|
/* A checkpoint without a generation config is served from the layers underneath, not
|
|
* refused: a missing file claims nothing and returns false. */
|
|
GenSampling missing;
|
|
CHECK(!gen_sampling_from_file("/nonexistent/generation_config.json", false, &missing));
|
|
CHECK(!missing.any());
|
|
}
|
|
|
|
/* The sidecar is the container's path with its extension replaced. The extension starts at the
|
|
* last dot in the basename, so a dot in a directory name is not one. */
|
|
TEST(gen_config_derives_the_sidecar_path) {
|
|
CHECK_EQ(gen_sidecar_path("/m/q38-flashnext-unc-w4-mtp.rad"),
|
|
std::string("/m/q38-flashnext-unc-w4-mtp.generation.json"));
|
|
CHECK_EQ(gen_sidecar_path("model.rad"), std::string("model.generation.json"));
|
|
CHECK_EQ(gen_sidecar_path("/a.b/model"), std::string("/a.b/model.generation.json"));
|
|
CHECK_EQ(gen_sidecar_path("/a.b/model.rad"), std::string("/a.b/model.generation.json"));
|
|
}
|
|
|
|
/* Unlimited-OCR's generation_config.json, verbatim: it states no temperature or top-k, only the
|
|
* windowed no-repeat-n-gram ban, so it must be claimed as stated (or the ban would never reach a
|
|
* request that sends no sampler fields). `do_sample: false` still means greedy and ignores it. */
|
|
TEST(gen_config_reads_the_ngram_ban) {
|
|
const char* const kUnlimitedOcr = R"({
|
|
"bos_token_id": 0,
|
|
"eos_token_id": 1,
|
|
"no_repeat_ngram_size": 35,
|
|
"no_repeat_ngram_window_size": 128,
|
|
"max_new_tokens": 32768,
|
|
"use_cache": true
|
|
})";
|
|
GenSampling g;
|
|
CHECK(gen_sampling_parse(kUnlimitedOcr, "test", &g));
|
|
CHECK_EQ(g.ngram_ban_n, 35);
|
|
CHECK_EQ(g.ngram_window, 128);
|
|
CHECK(g.temp < 0.0f);
|
|
const SamplingParams sp = g.onto(SamplingParams{});
|
|
CHECK_EQ(sp.ngram_ban_n, 35);
|
|
CHECK_EQ(sp.ngram_window, 128);
|
|
CHECK(GenSampling::describe(sp).find("ngram ban n 35 over the last 128 tokens") !=
|
|
std::string::npos);
|
|
|
|
/* The container's flattened copy reads the same. */
|
|
GenSampling kv;
|
|
CHECK(gen_sampling_from_kv(kv_of({ { "no_repeat_ngram_size", "35" },
|
|
{ "no_repeat_ngram_window_size", "128" } }),
|
|
&kv));
|
|
CHECK_EQ(kv.ngram_ban_n, 35);
|
|
CHECK_EQ(kv.ngram_window, 128);
|
|
|
|
/* This sampler's spellings, and the reference's negative window as "the whole sequence". */
|
|
GenSampling own;
|
|
CHECK(gen_sampling_parse(R"({"ngram_ban_n": 35, "ngram_window": -1})", "test", &own));
|
|
CHECK_EQ(own.ngram_ban_n, 35);
|
|
CHECK_EQ(own.ngram_window, 0);
|
|
|
|
/* A size outside [0, 256] is dropped on its own; the window still reads. */
|
|
GenSampling bad;
|
|
CHECK(gen_sampling_parse(R"({"no_repeat_ngram_size": 5000,
|
|
"no_repeat_ngram_window_size": 128})", "test", &bad));
|
|
CHECK_EQ(bad.ngram_ban_n, -1);
|
|
CHECK_EQ(bad.ngram_window, 128);
|
|
|
|
/* do_sample false is greedy: transformers ignores the ban under it, and so does this. */
|
|
GenSampling greedy;
|
|
CHECK(gen_sampling_parse(R"({"do_sample": false, "no_repeat_ngram_size": 35})", "test",
|
|
&greedy));
|
|
CHECK_EQ(greedy.ngram_ban_n, -1);
|
|
CHECK_EQ(greedy.onto(SamplingParams{}).ngram_ban_n, 0);
|
|
}
|
|
|
|
TEST(gen_config_reads_suppress_tokens) {
|
|
/* Gemma 4's generation_config.json: the end-of-image and end-of-audio markers. */
|
|
GenSampling g;
|
|
CHECK(gen_sampling_parse(R"({"temperature": 1.0, "suppress_tokens": [258883, 258882]})",
|
|
"test", &g));
|
|
REQUIRE_EQ((int)g.suppress.size(), 2);
|
|
CHECK_EQ(g.suppress[0], 258883);
|
|
CHECK_EQ(g.suppress[1], 258882);
|
|
const SamplingParams sp = g.onto(SamplingParams{});
|
|
CHECK_EQ((int)sp.suppress_tokens.size(), 2);
|
|
CHECK(SamplingParams{}.suppress_tokens.empty());
|
|
|
|
/* The container's flattened copy: the array as a space-separated string. */
|
|
GenSampling kv;
|
|
CHECK(gen_sampling_from_kv(kv_of({ { "suppress_tokens", "258883 258882" } }), &kv));
|
|
REQUIRE_EQ((int)kv.suppress.size(), 2);
|
|
CHECK_EQ(kv.suppress[1], 258882);
|
|
|
|
/* An entry that is no id is dropped on its own, and a non-array is dropped whole. */
|
|
GenSampling bad;
|
|
CHECK(gen_sampling_parse(R"({"top_k": 64, "suppress_tokens": [7, -1, "x", 9]})", "test", &bad));
|
|
CHECK_EQ((int)bad.suppress.size(), 2);
|
|
GenSampling flat;
|
|
CHECK(gen_sampling_parse(R"({"top_k": 64, "suppress_tokens": 7})", "test", &flat));
|
|
CHECK(flat.suppress.empty());
|
|
}
|
|
|
|
RAD_TEST_MAIN()
|