Archived
radiance 1.17.0
IQR-V4 for Qwen3.8-27B: - 15 recipes, data/recipes/q38-27b-iq2r-v4 .. q38-27b-iq8r-v4 (2.5 to 8 bits a weight), docs/IQR.md "IQR-V4". On the quantisation board's private split every entry has 2-19% less KL than its V3 twin of the same size (10-19% from 2.5 to 5.4 bits); IQ4R-L-V4 is 24% below the official FP8 checkpoint at 55% of its size, and IQ2R-L-V4 (2.8 bpw) is below the MXFP4 checkpoint. Containers with the DFlash2 drafter and the vision tower: huggingface.co/StillDeadcode/qwen3.8-27b-iqr-v4, served by deploy/compose/qwen3.8-27b-iqr-v4.yaml (IQR_V4 names the size) - GPTQ runs in act order inside the column trellis (tcq_order=1); the head-fed projections (attn_output, ssm_out) take a bf16 scale a (row, 128) block from five bits up; widths from measured prices - A vocabulary-weighted lm_head: four width classes of the computed trellis (output.k<B>), the tokens carrying the probability on the widest, decoded in one launch by logits_gemm_vocab with 16-bit head activations; 0.62 ms at one token on a TP2 rank against the int8 head's 1.02 ms. tools/vhead.py and data/vhead/ build the class split from the bf16 checkpoint; libquant reads the head's input Hessian for every class - At IQ6R-L and up, the int8 lm_head is GPTQ'd against its input Hessian (same bytes, median KL -8..-12%) - embed_lookup_iqr takes u7/u8 tables under a zero point and the 4096-state trellis at 6 and 7 bits - The whitepaper: radiance.stilldeadco.de/whitepapers/iqr-v4.pdf Faster IQR kernels: - The one-token GEMV gives each 16-row weight tile a block whose waves split K (5120 x 6144 at one token 42.3 -> 30.0 us), with a biased-int fold, a v_perm activation broadcast and one code stream a column - A 16-token WMMA tile without block barriers serves 2 to 16 tokens (6- and 7-bit codes from one token): a 4-bit weight takes 0.52-0.66 of FP8's time from one token to sixteen, 1.15-1.74x V3's kernels from four tokens up - The activation quantisers after the IQR gate_up (gemm_iqr_gated), the delta net's decode conv fold (gdn_conv_recurrent_update_had) and the attention gate (gate_had_quant_i8g) are folded into their producers, byte for byte the same codes: 128 fewer launches a decode step - End to end on one R9700 (TP1, no speculation): IQ4R-S-V4 decodes one stream in 24.7 ms against the MXFP4 checkpoint's 25.8 at five times lower KL; IQ3R-S-V4 is faster than MXFP4 at 1 to 8 streams. Prefill stays 8-9% behind MXFP4's 4-bit tile Quantisation tooling: - rescale=1 refits each row's scale to its codes after GPTQ; gptqsim measures a tensor's W16A16 form (tcq_code=mad16); an int8 trunk's calibration Grams can be recorded from the codes its GEMMs read (--calib-dir, TP1) - Fixed: the GPU trellis packs tcq_code=mad16's values two int16 a register New models (merged): - Spark 2.5 (spark25: bf16 and rotated-int8 IQ8R checkpoints, tensor parallelism with exact collectives, reasoning and tagged tool calls) with its DSpark drafter (exact attention and Markov walk ops), docs/SPARK25-IQ8R.md (@gostar) - Ling-3.0-flash (bailing_hybrid: KDA, dense latent attention with mla_attn_paged, group-limited sigmoid routing, the clipped SwiGLU and its MTP layer as a serial drafter), its w4a8 recipes and compose files for four and two cards (@keptn42) - Gemma 4 12B (gemma4_unified, served by the gemma4 plugins): its picture and audio embedders, a picture's placeholders read both ways on the sliding layers as the model was trained (the scheduler ends no prefill chunk inside such a run; RadBatch::n_bidi), windowed attention at head_dim 512, the assistant head as MTP drafter at one, two and four ranks, suppress_tokens from generation_config, bf16 and i8g compose files (@keptn42) Merged: - The prefill KV split sized by the live KV length rather than the model's max_ctx, recorded passes keyed by their split geometry, and --gpu-memory-mib, the inverse of --gpu-headroom-mib (@gostar) - Possessive quantifiers in tokenizer patterns where the greedy reading provably matches the same (Ling-3.0's), and the Grafana dashboard's first screen of totals (@keptn42) - The dashboard's history line (decode, prefill and TTFT over finished requests, kept in the browser, JSON export), session extremes that age and reset on a restart, card-count changes, an Advanced tab for the poll intervals, each request's prefill time from admission in /stats (prefill_s), and the page's JavaScript run by tests/js (@Memoria) - From PR #390: the file tier reads a routed layer with its own router's counts and waits for its deposits; the stop-string hold-back keeps back only a tail that can still become a stop string (before, every delta waited up to the longest stop's length); the sampler's planes are sized by the step's token bound, the n-gram ban runs beside a drafter, and a top-1 row issues no candidate cut (@Code000) - The n-gram reader refills its reads as they land, and a decode gather waits on the other rank's read of a row instead of reading it again (#369, @pokesjw) - libr3d's GEMM structs value-initialised so the tape audit sees no padding (@RikshaDriver) Added: - --ngram-placement disk=DIR: the n-gram table read from its own file, DIR/ngram-<id>.bin, filled from the container at the first start, on a faster or separate drive (#130) Fixed: - input_reference's H.264 round trip runs on libopenh264, which the image carries, at a quantiser held at the crf (a side under 16 padded and cut back); a build with no H.264 encoder answers 501 (#163) - kvtier: at most 1024 session rows under one shared first block; with one shared prompt the list grew a row a request and prefill fell from 9k to 2.5k tok/s after 500K requests (#375) - Speculative steps on an architecture with no pass-key callback keep their recorded passes under the live-KV prefill split Plugin ABI 35: - RadArgs::kv_used_max_h and wgp_count, RadBatch::kv_used_max_h and positions_h, the optional rad_arch_pass_key export and RAD_KERNEL_CAP_DYNAMIC_PREFILL_SPLIT; RadEncoderDecl::bidirectional and RadBatch's n_bidi runs. The layout fingerprint table is regenerated; out-of-tree plugins rebuild against 35 Thanks to @gostar, @keptn42, @Memoria, @Code000, @pokesjw and @RikshaDriver.
This commit is contained in:
1 parent
3af8065cc6
commit
19d4e8fe0e
102 files changed
+9794
-692
No files matched your search
+26
-22
@@ -9699,9 +9699,11 @@ int w8a8_declare(RadBuilder* b, const RadModelMeta* meta, const RadBuildCtx* ctx
|
||||
|
||||
} /* namespace */
|
||||
|
||||
/* The `_had_quant_i8g` producers, which libr4d serves and libref does not. */
|
||||
/* The `_had_quant_i8g` producers and the ops that write those codes in their epilogue (the
|
||||
* attention gate's, the delta net's decode conv fold's), which libr4d serves and libref does not. */
|
||||
const char* const kW8a8Fused[] = { "rmsnorm_had_quant_i8g", "ar_rmsnorm_had_quant_i8g",
|
||||
"gated_had_quant_i8g" };
|
||||
"gated_had_quant_i8g", "gate_had_quant_i8g",
|
||||
"gdn_conv_recurrent_update_had" };
|
||||
|
||||
/* Where the `_had_quant_i8g` producers are not served, every trunk linear of a rotated int8
|
||||
* container is an i8a8h GEMM right behind its own had_quant_act_i8g, at one rank and two: 2
|
||||
@@ -9736,11 +9738,13 @@ TEST(qwen35_w8a8_serves_every_trunk_linear_rotated_int8) {
|
||||
}
|
||||
}
|
||||
|
||||
/* Where they are served, the norms and the gated product write had_quant_act_i8g's codes into the
|
||||
* int8 pair, and the projections reading them declare no quantiser: had_quant_act_i8g is left only
|
||||
* before the attention and delta-net output projections (2 + 6), every norm is the rotated twin (at
|
||||
* two ranks with its fused all-reduce form beside it), and every feed-forward's product is
|
||||
* gated_had_quant_i8g. No E4M3 norm or gated quantiser is left, and the 36 GEMMs are unchanged. */
|
||||
/* Where they are served, the norms, the gated product, the attention gate and the delta net's
|
||||
* decode conv fold write had_quant_act_i8g's codes into the int8 pair, and the projections reading
|
||||
* them declare no quantiser: had_quant_act_i8g is left only as the delta net's quantiser of the
|
||||
* rows its decode fold does not serve (6), every norm is the rotated twin (at two ranks with its
|
||||
* fused all-reduce form beside it), every feed-forward's product is gated_had_quant_i8g and every
|
||||
* attention gate gate_had_quant_i8g. No E4M3 norm or gated quantiser is left, and the 36 GEMMs are
|
||||
* unchanged. */
|
||||
TEST(qwen35_w8a8_feeds_its_rotated_codes_from_the_producers_where_libr4d_serves_them) {
|
||||
MetaKV mk = q35w8a8_meta();
|
||||
for (int world : { 1, 2 }) {
|
||||
@@ -9751,9 +9755,11 @@ TEST(qwen35_w8a8_feeds_its_rotated_codes_from_the_producers_where_libr4d_serves_
|
||||
int rot = 0;
|
||||
for (const RecOp& o : b.ops) rot += o.op == "gemm_nt_q" && pstr(&o, "dtype") == "i8a8h";
|
||||
CHECK_EQ(rot, 2 * 4 + 6 * 2 + 8 * 2);
|
||||
CHECK_EQ(count_op(b, "had_quant_act_i8g"), 2 + 6);
|
||||
CHECK_EQ(count_op(b, "had_quant_act_i8g"), 6);
|
||||
CHECK_EQ(count_op(b, "rmsnorm_had_quant_i8g"), 8 + 8);
|
||||
CHECK_EQ(count_op(b, "gated_had_quant_i8g"), 8);
|
||||
CHECK_EQ(count_op(b, "gate_had_quant_i8g"), 2);
|
||||
CHECK_EQ(count_op(b, "gdn_conv_recurrent_update_had"), 6);
|
||||
for (const char* op : { "rmsnorm_quant_fp8", "ar_rmsnorm_quant_fp8", "gated_quant_fp8",
|
||||
"quant_act_i8g" })
|
||||
CHECK_EQ(count_op(b, op), 0);
|
||||
@@ -10767,7 +10773,7 @@ TEST(the_gemma4_12b_embeds_images_and_audio_without_an_encoder) {
|
||||
* bound (its window two-sided), the encoder says so to the core (RadEncoderDecl::bidirectional),
|
||||
* and on a pass with a run (RadBatch::n_bidi) each sliding layer attends the run's rows again over
|
||||
* their sequence's cache up to the run's end, written over the causal result in the same rows.
|
||||
* Without the config key, or with RADIANCE_MEDIA_BIDI=0, nothing of it. */
|
||||
* Without the config key, nothing of it. */
|
||||
TEST(the_gemma4_12b_reads_a_pictures_rows_both_ways) {
|
||||
std::vector<const char*> keys(std::begin(k_gem12_keys), std::end(k_gem12_keys));
|
||||
std::vector<const char*> vals(std::begin(k_gem12_vals), std::end(k_gem12_vals));
|
||||
@@ -10784,7 +10790,7 @@ TEST(the_gemma4_12b_reads_a_pictures_rows_both_ways) {
|
||||
const int32_t run = 10;
|
||||
static const int32_t rows[] = { run };
|
||||
for (const int win : { 1024, 8 })
|
||||
for (int mode = 0; mode < 3; ++mode) { /* 0 on, 1 no key, 2 RADIANCE_MEDIA_BIDI=0 */
|
||||
for (int mode = 0; mode < 2; ++mode) { /* 0 on, 1 no key */
|
||||
std::vector<const char*> wvals = vals;
|
||||
for (size_t k = 0; k < keys.size(); ++k)
|
||||
if (!std::strcmp(keys[k], "sliding_window")) wvals[k] = win == 8 ? "8" : "1024";
|
||||
@@ -10802,9 +10808,7 @@ TEST(the_gemma4_12b_reads_a_pictures_rows_both_ways) {
|
||||
meta.kv_key = keys.data(); meta.kv_val = wvals.data();
|
||||
RadBuildCtx ctx = build_ctx(rank, world);
|
||||
ctx.max_enc_patches = 1120;
|
||||
if (mode == 2) setenv("RADIANCE_MEDIA_BIDI", "0", 1);
|
||||
const int rc = gemma4_bf16::declare(&b, &meta, &ctx);
|
||||
unsetenv("RADIANCE_MEDIA_BIDI");
|
||||
REQUIRE_EQ(rc, RAD_OK);
|
||||
const bool on = mode == 0;
|
||||
CHECK_EQ(b.encoder.bidirectional, on ? 1 : 0);
|
||||
@@ -11518,22 +11522,22 @@ struct ArchCases {
|
||||
qwen35_bf16::step, 0, {}, 0xf82117051023e608ull);
|
||||
add("qwen35_fp8 + MTP", [this, sc](RadBuilder* b) {
|
||||
auto c = sc(1, 3); return qwen35_fp8::declare(b, q35.meta(), &c); },
|
||||
qwen35_fp8::step, 3, {}, 0x20ab9ed24e409329ull);
|
||||
qwen35_fp8::step, 3, {}, 0x958b83102809266bull);
|
||||
add("qwen35_fp8 + MTP, two ranks", [this, sc](RadBuilder* b) {
|
||||
auto c = sc(2, 3); return qwen35_fp8::declare(b, q35.meta(), &c); },
|
||||
nullptr, 3, { "ar_rmsnorm_quant_fp8" }, 0x5b52afb1706a954eull);
|
||||
nullptr, 3, { "ar_rmsnorm_quant_fp8" }, 0x91408682a38a1754ull);
|
||||
add("qwen35_fp8 + DFlash2", [this, sc](RadBuilder* b) {
|
||||
auto c = sc(1, 7); return qwen35_fp8::declare(b, q35df.meta(), &c); },
|
||||
qwen35_fp8::step, 7, {}, 0x365e4cbb415ac284ull);
|
||||
qwen35_fp8::step, 7, {}, 0x60d33ded99aa451eull);
|
||||
add("qwen35_w8a8 + DFlash2", [this, sc](RadBuilder* b) {
|
||||
auto c = sc(1, 7); return w8a8_declare(b, q35w8df.meta(), &c); },
|
||||
qwen35_w8a8::step, 7, {}, 0x742a596708bbda1dull);
|
||||
qwen35_w8a8::step, 7, {}, 0x570d3bc8fc15f701ull);
|
||||
add("qwen35_w8a8 + DFlash2, two ranks", [this, sc](RadBuilder* b) {
|
||||
auto c = sc(2, 7); return w8a8_declare(b, q35w8df.meta(), &c); },
|
||||
nullptr, 7, { "ar_rmsnorm_quant_fp8" }, 0x93b6390d30e59953ull);
|
||||
nullptr, 7, { "ar_rmsnorm_quant_fp8" }, 0x6c5267846652829full);
|
||||
add("qwen35moe_fp8 + MTP", [this, sc](RadBuilder* b) {
|
||||
auto c = sc(1, 3); return qwen35moe_fp8::declare(b, q35moe.meta(), &c); },
|
||||
qwen35moe_fp8::step, 3, {}, 0x4c7e42e71f167042ull);
|
||||
qwen35moe_fp8::step, 3, {}, 0x325d0299495a0dd8ull);
|
||||
add("qwen4exp_fp8", [this](RadBuilder* b) {
|
||||
auto c = q4_ctx(0, 1); return qwen4exp_fp8::declare(b, &q4, &c); },
|
||||
qwen4exp_fp8::step, 3, {}, 0x9454e9dff6db286bull);
|
||||
@@ -12276,10 +12280,10 @@ TEST(a_4096_budget_without_a_span_is_the_pinned_graph_and_steps) {
|
||||
{ "qwen4exp_fp8", 2, 1, 0x4bc19e44d0743e49ull, 0x959ef6b7c6f57d8bull },
|
||||
{ "qwen4exp_fp8", 4, 0, 0xea29df78a9297c5cull, 0xfbe74f2b9d7020bfull },
|
||||
{ "qwen4exp_fp8", 4, 3, 0x1e4ba87a0d9619f4ull, 0x36df57cac613c6cfull },
|
||||
{ "qwen35_fp8", 1, 0, 0xc56a518087e3f4b4ull, 0xa7ec3cf6252cd441ull },
|
||||
{ "qwen35_fp8", 2, 1, 0x6e644b3d13bac619ull, 0xdd5d65ef158c4136ull },
|
||||
{ "qwen35moe_fp8", 1, 0, 0x7a9330e0da08f97cull, 0x2b5989b2a6dbc7dfull },
|
||||
{ "qwen35moe_fp8", 2, 0, 0x3a2761e9546797f1ull, 0x4a597c66b5868eeeull },
|
||||
{ "qwen35_fp8", 1, 0, 0x0f08ba5027cba71aull, 0xa7ec3cf6252cd441ull },
|
||||
{ "qwen35_fp8", 2, 1, 0xe7780f241685a18bull, 0xdd5d65ef158c4136ull },
|
||||
{ "qwen35moe_fp8", 1, 0, 0xb1e6173bd121dc2aull, 0x2b5989b2a6dbc7dfull },
|
||||
{ "qwen35moe_fp8", 2, 0, 0x46d061a0de9a8933ull, 0x4a597c66b5868eeeull },
|
||||
};
|
||||
for (const Case& cs : cases) {
|
||||
RadBuilder b;
|
||||
|
||||
+20
-1
@@ -902,9 +902,28 @@ TEST(the_ngram_table_takes_a_directory_for_a_shared_ram_copy) {
|
||||
CHECK(s.ngram_placement == TablePlacement::Ram);
|
||||
CHECK(s.ngram_share_dir.empty());
|
||||
Config c;
|
||||
for (const char* bad : { "ram=", "vram=/tmp/x", "disk=/tmp/x", "auto=/tmp/x" })
|
||||
for (const char* bad : { "ram=", "disk=", "vram=/tmp/x", "auto=/tmp/x" })
|
||||
CHECK_EQ(parse({ "--ngram-placement", bad }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--embedding-placement", "ram=/tmp/x" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--embedding-placement", "disk=/tmp/x" }, &c), RAD_E_INVAL);
|
||||
}
|
||||
|
||||
/* disk=DIR is disk read from the table's own file in DIR (#130); it and ram=DIR replace each
|
||||
* other, and a plain placement drops both directories. */
|
||||
TEST(the_ngram_table_takes_a_directory_for_its_own_file_on_disk) {
|
||||
Config s;
|
||||
CHECK_EQ(parse({ "--ngram-placement", "disk=/mnt/optane" }, &s), RAD_OK);
|
||||
CHECK(s.ngram_placement == TablePlacement::Disk);
|
||||
CHECK_EQ(s.ngram_disk_dir, std::string("/mnt/optane"));
|
||||
CHECK(s.ngram_share_dir.empty());
|
||||
CHECK_EQ(parse({ "--ngram-placement", "disk=/mnt/optane", "--ngram-placement", "ram=/dev/shm" },
|
||||
&s), RAD_OK);
|
||||
CHECK(s.ngram_placement == TablePlacement::Ram);
|
||||
CHECK(s.ngram_disk_dir.empty());
|
||||
CHECK_EQ(s.ngram_share_dir, std::string("/dev/shm"));
|
||||
CHECK_EQ(parse({ "--ngram-placement", "disk=/mnt/optane", "--ngram-placement", "disk" }, &s),
|
||||
RAD_OK);
|
||||
CHECK(s.ngram_disk_dir.empty());
|
||||
}
|
||||
|
||||
/* --draft-window takes exactly two names; the default is kDraftWindowDefault, which the help text
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <fcntl.h>
|
||||
#include <fstream>
|
||||
#include <functional>
|
||||
#include <signal.h>
|
||||
#include <string>
|
||||
@@ -26,6 +27,7 @@
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include <cstring>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -453,6 +455,70 @@ TEST(a_table_copied_into_locked_memory_is_the_mapping_byte_for_byte) {
|
||||
f.close();
|
||||
}
|
||||
|
||||
/* --ngram-placement disk=DIR (#130): the first open fills the table's own file from the container,
|
||||
* renamed into place whole; the mapping holds the container's bytes and is that file's (the disk
|
||||
* gather finds the file behind its mapping); a second open reuses it unfilled; a file that is not
|
||||
* this table is refused rather than served. */
|
||||
TEST(a_table_file_on_another_disk_is_filled_once_and_mapped_in_place_of_the_container) {
|
||||
const std::string p = radtest::tmp_path("tfile");
|
||||
RadWriter w;
|
||||
REQUIRE(w.begin(p.c_str()) >= 0);
|
||||
w.set_arch("radtest");
|
||||
const RadWriter::Weight x = mkw("ngram.weight", plain_bf16(), 1500, 999, -1, -1, 0);
|
||||
const Planes want = planes_of(x, 7);
|
||||
REQUIRE(w.add_weight(x, want.ptr.data()) >= 0);
|
||||
REQUIRE(w.finish() >= 0);
|
||||
RadFile f;
|
||||
REQUIRE(f.open(p.c_str()) >= 0);
|
||||
const RadFilePlane& pl = f.plane(*f.find("ngram.weight"), 0);
|
||||
const uint8_t* src = f.data(pl);
|
||||
const int64_t n = (int64_t)pl.bytes;
|
||||
const std::string tab = radtest::tmp_path("tfile-table");
|
||||
::unlink(tab.c_str());
|
||||
|
||||
TableCopy a;
|
||||
bool filled = false;
|
||||
std::string why;
|
||||
REQUIRE_EQ(table_file_open(f, src, n, (int64_t)pl.offset, tab, &a, &filled, &why), (int)RAD_OK);
|
||||
CHECK(filled);
|
||||
CHECK_EQ(a.bytes, (size_t)n);
|
||||
CHECK(std::memcmp(a.base, src, (size_t)n) == 0);
|
||||
CHECK(::access((tab + ".part").c_str(), F_OK) != 0);
|
||||
/* The mapping is the file's, as /proc/self/maps names it. */
|
||||
{
|
||||
std::ifstream maps("/proc/self/maps");
|
||||
bool backed = false;
|
||||
for (std::string line; std::getline(maps, line);) {
|
||||
unsigned long long lo = 0, hi = 0;
|
||||
if (std::sscanf(line.c_str(), "%llx-%llx", &lo, &hi) != 2) continue;
|
||||
if ((uintptr_t)a.base >= lo && (uintptr_t)a.base < hi)
|
||||
backed = line.size() >= tab.size() && line.compare(line.size() - tab.size(), tab.size(), tab) == 0;
|
||||
}
|
||||
CHECK(backed);
|
||||
}
|
||||
::munmap(a.base, a.bytes);
|
||||
|
||||
TableCopy b;
|
||||
REQUIRE_EQ(table_file_open(f, src, n, (int64_t)pl.offset, tab, &b, &filled, &why), (int)RAD_OK);
|
||||
CHECK(!filled);
|
||||
CHECK(std::memcmp(b.base, src, (size_t)n) == 0);
|
||||
::munmap(b.base, b.bytes);
|
||||
|
||||
/* Same size, other bytes: refused, and left for the operator to remove. */
|
||||
{
|
||||
std::fstream t(tab, std::ios::in | std::ios::out | std::ios::binary);
|
||||
t.seekp(0);
|
||||
const char junk[16] = "not the table..";
|
||||
t.write(junk, sizeof junk);
|
||||
}
|
||||
TableCopy c;
|
||||
CHECK_EQ(table_file_open(f, src, n, (int64_t)pl.offset, tab, &c, &filled, &why), (int)RAD_E_IO);
|
||||
CHECK(c.base == nullptr);
|
||||
CHECK(why.find("does not match") != std::string::npos);
|
||||
::unlink(tab.c_str());
|
||||
f.close();
|
||||
}
|
||||
|
||||
/* --ngram-placement ram=DIR: the first holder to open the file fills it, a later one finds it
|
||||
* ready (a second descriptor in one process is a second holder, since flock locks belong to the
|
||||
* open file description), and the file goes when the last holder leaves. A file whose header is
|
||||
|
||||
@@ -1614,12 +1614,13 @@ TEST(glm53_is_the_pinned_graph_and_steps) {
|
||||
/* Pins from this test's own `pin:` printout: the head form (heads_only, which declares the
|
||||
* streamed ops) and the row form, at one and eight ranks. Re-recorded after every graph
|
||||
* change -- the merge re-recorded them for main's builder plus this branch's file-direct
|
||||
* expert ops. */
|
||||
const Case cases[] = { { 1, 0x8e12725b3ed3548dull, 0x68ffc03d2b640d51ull },
|
||||
* expert ops, and the graphs again when the routing counts became RAD_BUF_PERSIST (the
|
||||
* steps did not change). */
|
||||
const Case cases[] = { { 1, 0x74395d49106a3042ull, 0x68ffc03d2b640d51ull },
|
||||
/* World 8 is this branch's expert-parallel graph (288/world whole
|
||||
* experts, file-direct), so its pins differ from main's. */
|
||||
{ 8, 0x6232b56d6f971d61ull, 0x1b80576ba8f1ecc7ull },
|
||||
{ 8, 0x3e4b89352f01b57bull, 0xed8cc595e8eeb593ull, true } };
|
||||
{ 8, 0x1a0da8de6bd0be62ull, 0x1b80576ba8f1ecc7ull },
|
||||
{ 8, 0xe3751c4cc46e027aull, 0xed8cc595e8eeb593ull, true } };
|
||||
for (const Case& cs : cases) {
|
||||
RadBuilder b;
|
||||
b.kv_block = 4;
|
||||
|
||||
+5
-17
@@ -4,8 +4,8 @@ The dashboard is one C++ string: `core/server/dashboard.cpp` embeds the whole pa
|
||||
so its JavaScript has no file of its own to test. These harnesses extract the page
|
||||
from the translation unit (`page.js`) and **execute the shipped functions**, sliced
|
||||
by line range, against mocked DOM. A retyped copy would test the copy, not the bytes
|
||||
that ship — and a sliced function that is defined but never *called* proves nothing,
|
||||
which has already happened once here.
|
||||
that ship, and each harness calls the functions it slices: one that is only defined proves
|
||||
nothing.
|
||||
|
||||
node tests/js/poll_spark.test.js
|
||||
node tests/js/extremes.test.js
|
||||
@@ -39,11 +39,9 @@ are deliberately not repo dependencies:
|
||||
node tests/js/render_align.js http://127.0.0.1:8800/
|
||||
|
||||
Exits nonzero when the two bottoms land on different device rows. Run it after touching glyph or
|
||||
header geometry. Three claims about alignment and spacing went through this branch on the strength
|
||||
of reading the CSS and the SVG viewBox, and all three were wrong -- collapsed whitespace made a
|
||||
"wide" separator zero pixels wide, and an SVG whose box is flush with the baseline still floats,
|
||||
because the baseline sits above the box bottom. None of that is visible in the source. Measure the
|
||||
rendered page.
|
||||
header geometry: alignment cannot be read off the CSS and the SVG viewBox (collapsed whitespace can
|
||||
make a separator zero pixels wide, and an SVG flush with the baseline still floats, because the
|
||||
baseline sits above the box bottom), so measure the rendered page.
|
||||
|
||||
## Why these are not in ctest
|
||||
|
||||
@@ -51,13 +49,3 @@ They need node, which is not a build dependency of this project and will not be
|
||||
present on a contributor's box or in the ROCm build image. Wiring them into ctest
|
||||
would turn a missing optional tool into a red build, so they stay opt-in and are run
|
||||
by hand when the page changes. `dashboard_test` covers the C++ side only.
|
||||
|
||||
## History
|
||||
|
||||
Both files came out of the 2026-11-01 dashboard review. Commit `9cc237f` claimed
|
||||
"18 checks execute the shipped noteSample, triple, acceptTriple, resetWindows and
|
||||
newEngineRun" while the harness lived only in `/tmp` — true when written, not
|
||||
reproducible by anyone else, which an independent review correctly rejected. They are
|
||||
in the tree so that claim can be re-run. `history.test.js` and `download.test.js` came from the
|
||||
dashboard work that followed, on the same rule: a check that lives in `/tmp` is a claim about the
|
||||
author's machine.
|
||||
@@ -4363,6 +4363,31 @@ TEST(the_session_view_says_what_a_return_reuses_and_what_is_off_the_card) {
|
||||
}
|
||||
}
|
||||
|
||||
/* Conversations under one shared first block (a decision model's instructions, which no request
|
||||
* evicts) keep at most 1024 rows: the least recently used row goes, the newest stay. Before, every
|
||||
* request added a row and each insert walked all of them (#375). */
|
||||
TEST(a_shared_root_keeps_a_bounded_session_table) {
|
||||
IdleTiers t;
|
||||
CHECK_OK(t.configure(tier_config(0, 1024)));
|
||||
constexpr uint64_t kRows = 1500;
|
||||
for (uint64_t i = 1; i <= kRows; ++i)
|
||||
t.note_session(i, {bh(1), bh(1000 + i)}, 32, i * SEC);
|
||||
std::vector<IdleTiers::SessionInfo> s = t.sessions();
|
||||
CHECK_EQ(s.size(), 1024u);
|
||||
bool newest = false, oldest = false;
|
||||
for (const auto& r : s) {
|
||||
newest |= r.id == kRows;
|
||||
oldest |= r.id == 1;
|
||||
}
|
||||
CHECK(newest);
|
||||
CHECK(!oldest);
|
||||
/* A later turn of a kept conversation still absorbs its row. */
|
||||
t.note_session(kRows + 1, {bh(1), bh(1000 + kRows), bh(7)}, 48, (kRows + 1) * SEC);
|
||||
s = t.sessions();
|
||||
CHECK_EQ(s.size(), 1024u);
|
||||
for (const auto& r : s) CHECK(r.id != kRows);
|
||||
}
|
||||
|
||||
TEST(tiers_stay_off_until_a_size_is_given) {
|
||||
IdleTiers t;
|
||||
CHECK_OK(t.configure(tier_config(0, 1024)));
|
||||
|
||||
@@ -1460,6 +1460,535 @@ TEST(the_file_stager_reads_each_routed_layer_from_the_container) {
|
||||
std::remove(path.c_str());
|
||||
}
|
||||
|
||||
namespace {
|
||||
/* Every weight of `f` in a container image, each on RAD_ALIGN_UNIT in declared order with a 2 MiB
|
||||
* hole between layers, written to `path` with each byte container_byte(offset). Empty when the
|
||||
* working directory has no O_DIRECT (the caller skips). */
|
||||
std::vector<uint8_t> write_container(Fixture& f, const std::string& path) {
|
||||
int64_t off = 4 * (int64_t)RAD_ALIGN_UNIT;
|
||||
int32_t prev = -1;
|
||||
for (rad_weight w = 1; (size_t)w < f.prog.weights.size(); ++w) {
|
||||
WeightInfo& wi = f.prog.weights[w];
|
||||
if (prev >= 0 && wi.decl.group.layer != prev) off += 2 * MiB;
|
||||
prev = wi.decl.group.layer;
|
||||
wi.stored_bytes = wi.logical_bytes;
|
||||
wi.file_offset = (uint64_t)off;
|
||||
off = align_up(off + wi.stored_bytes, RAD_ALIGN_UNIT);
|
||||
}
|
||||
std::vector<uint8_t> img((size_t)off);
|
||||
for (int64_t i = 0; i < off; ++i) img[(size_t)i] = container_byte(i);
|
||||
FILE* fp = std::fopen(path.c_str(), "wb");
|
||||
if (!fp) return {};
|
||||
const bool wrote = std::fwrite(img.data(), 1, img.size(), fp) == img.size();
|
||||
std::fclose(fp);
|
||||
DirectFile probe;
|
||||
if (!wrote || probe.open(path.c_str(), RAD_DIO_READ) < 0) {
|
||||
std::remove(path.c_str());
|
||||
return {};
|
||||
}
|
||||
return img;
|
||||
}
|
||||
|
||||
/* A routing-count source like Ctx::route_counts_device over a MoE block declared once: one counts
|
||||
* buffer that every routed layer's router rewrites (glm5next shares its counts this way), so a
|
||||
* read that took the counts before its own layer's router ran would see another layer's. A layer
|
||||
* in `missing` has not reported yet. `asked` counts the stager's questions. */
|
||||
struct SharedCounts {
|
||||
int32_t* dev = nullptr;
|
||||
int64_t n = 0;
|
||||
std::vector<int32_t> missing;
|
||||
int asked = 0;
|
||||
explicit SharedCounts(int64_t n_expert) : n(n_expert) {
|
||||
dev = (int32_t*)rad_dev_alloc(n_expert * (int64_t)sizeof(int32_t), RAD_MEM_DEVICE);
|
||||
}
|
||||
~SharedCounts() { if (dev) rad_dev_free(dev, RAD_MEM_DEVICE); }
|
||||
/* The router of the rows about to run, on the host backend's shared memory. */
|
||||
void route(std::initializer_list<int32_t> c) {
|
||||
int64_t i = 0;
|
||||
for (int32_t v : c) dev[i++] = v;
|
||||
}
|
||||
static const int32_t* get(void* ud, int32_t layer, int64_t* n_expert) {
|
||||
SharedCounts& s = *(SharedCounts*)ud;
|
||||
++s.asked;
|
||||
*n_expert = 0;
|
||||
if (std::find(s.missing.begin(), s.missing.end(), layer) != s.missing.end()) return nullptr;
|
||||
*n_expert = s.n;
|
||||
return s.dev;
|
||||
}
|
||||
};
|
||||
|
||||
/* What one routed unit's weights are published as right now: the container's bytes, the zero
|
||||
* region (a skipped expert), or nothing. */
|
||||
enum class Pub { Bytes, Zeros, Null, Other };
|
||||
Pub published(Mover& m, const Plan& p, const Program& prog, int32_t unit,
|
||||
const std::vector<uint8_t>& img, RadStream s) {
|
||||
Pub got = Pub::Bytes;
|
||||
for (rad_weight w : p.units[(size_t)unit].weights) {
|
||||
const WeightSlot* slot = m.residency()->lookup(w);
|
||||
if (!slot || !slot->ptr) return Pub::Null;
|
||||
if (published_matches(m, prog, w, img, s)) continue;
|
||||
std::vector<uint8_t> head(256);
|
||||
rad_stream_sync(m.transfer_stream());
|
||||
if (rad_memcpy_async(head.data(), slot->ptr, (int64_t)head.size(), s) < 0) return Pub::Other;
|
||||
rad_stream_sync(s);
|
||||
bool zero = true;
|
||||
for (uint8_t v : head) zero = zero && v == 0;
|
||||
got = zero ? Pub::Zeros : Pub::Other;
|
||||
}
|
||||
return got;
|
||||
}
|
||||
|
||||
int32_t unit_at(const Plan& p, int32_t layer, int32_t expert) {
|
||||
for (int32_t i = 0; i < (int32_t)p.units.size(); ++i)
|
||||
if (p.units[(size_t)i].layer == layer && p.units[(size_t)i].expert == expert) return i;
|
||||
return -1;
|
||||
}
|
||||
} /* namespace */
|
||||
|
||||
/* A layer is read with the counts its own router wrote, at its own trigger. Three routed layers
|
||||
* of four 3 MiB experts, 1 and 3 on the file tier, every router writing one shared counts buffer.
|
||||
* A read taken before a layer's router ran -- at the pass's first op, or ahead at the previous
|
||||
* layer's trigger -- would filter the layer by another layer's counts and leave a routed expert
|
||||
* to be computed from the zero region. A second slice of a layer's rows routes again, and what it
|
||||
* routes that the first did not is read then. */
|
||||
TEST(the_file_stager_reads_a_layer_with_the_counts_its_own_router_wrote) {
|
||||
Fixture f;
|
||||
const int L = 3;
|
||||
build_moe_layers(f, L, 4, 2 * MiB + 1000, MiB + 24);
|
||||
f.prog.meta.n_expert = 4;
|
||||
const std::string path = "place_test_counts.rad";
|
||||
const std::vector<uint8_t> img = write_container(f, path);
|
||||
if (img.empty()) {
|
||||
std::printf(" SKIP the working directory has no O_DIRECT\n");
|
||||
return;
|
||||
}
|
||||
std::vector<RadFileProfile> prof;
|
||||
for (int l = 0; l < L; ++l)
|
||||
for (int e = 0; e < 4; ++e)
|
||||
prof.push_back(RadFileProfile{l, e, e == 0 ? 0.5f : e == 2 ? 0.4f : 0.01f, 0.0f});
|
||||
/* Six residents, the two file buffers and the embedding fill the card; the host pool is the
|
||||
* file tier's staging and nothing more. */
|
||||
const int64_t stride = align_up(align_up(2 * MiB + 1000, RAD_ALIGN_UNIT) + MiB + 24,
|
||||
RAD_ALIGN_UNIT);
|
||||
Config c = base_config();
|
||||
c.placement = "expert_tiered";
|
||||
c.deterministic = true;
|
||||
c.vram_weights_mib = 32;
|
||||
c.host_pool_mib = (RAD_PLACE_FILE_STAGE_SLOTS * stride +
|
||||
RAD_PLACE_FILE_WINDOWS * RAD_PLACE_FILE_WINDOW_BYTES) / MiB + 1;
|
||||
c.weights_disk_tier = true;
|
||||
PlannerInput in{&f.prog, &c, 0, 1, prof.data(), (int64_t)prof.size()};
|
||||
Plan p;
|
||||
CHECK_OK(Planner(in).plan(&p));
|
||||
for (const MoveUnit& mu : p.units)
|
||||
if (mu.expert >= 0) CHECK(mu.tier == ((mu.expert & 1) ? Tier::SSD : Tier::VRAM));
|
||||
|
||||
Mover m;
|
||||
MoverConfig mc;
|
||||
mc.container_path = path;
|
||||
CHECK_OK(m.init(f.prog, p, mc));
|
||||
RadStream s = nullptr;
|
||||
CHECK_OK(rad_stream_create(&s, 0));
|
||||
CHECK_OK(m.bind_compute_stream(s));
|
||||
SharedCounts counts(4);
|
||||
/* What the last pass's last router left: both file-tier experts of every layer routed. */
|
||||
counts.route({0, 1, 0, 1});
|
||||
FileStager fs;
|
||||
CHECK_OK(fs.init(f.prog, p, &m, &SharedCounts::get, &counts));
|
||||
REQUIRE_EQ(fs.n_layers(), (size_t)L);
|
||||
auto pub = [&](int l, int e) { return published(m, p, f.prog, unit_at(p, l, e), img, s); };
|
||||
auto none = [&](int l) { return pub(l, 1) == Pub::Null && pub(l, 3) == Pub::Null; };
|
||||
|
||||
/* Op 0 is the embedding; layer l's expert ops are 2l+1 and 2l+2. */
|
||||
RadBatch b{};
|
||||
CHECK(fs.begin_pass(&b));
|
||||
bool resync = false;
|
||||
CHECK_OK(fs.before_op(0, s, &resync));
|
||||
/* Nothing yet: no counts for layer 0 exist before its router has run. */
|
||||
CHECK(!resync);
|
||||
for (int l = 0; l < L; ++l) CHECK(none(l));
|
||||
|
||||
counts.route({0, 2, 0, 0}); /* layer 0's router: expert 1 only */
|
||||
CHECK_OK(fs.before_op(1, s, &resync));
|
||||
CHECK(resync);
|
||||
CHECK(pub(0, 1) == Pub::Bytes);
|
||||
CHECK(pub(0, 3) == Pub::Zeros); /* not routed: the zero region, not read */
|
||||
CHECK(none(1)); /* layer 1's router has not run */
|
||||
CHECK(none(2));
|
||||
CHECK_OK(fs.after_op(1, s));
|
||||
/* A second slice of layer 0's rows that routes nothing new reads and publishes nothing. */
|
||||
const int64_t waits0 = fs.waits();
|
||||
counts.route({0, 5, 0, 0});
|
||||
CHECK_OK(fs.before_op(1, s, &resync));
|
||||
CHECK(!resync);
|
||||
CHECK_EQ(fs.waits(), waits0);
|
||||
CHECK(pub(0, 1) == Pub::Bytes && pub(0, 3) == Pub::Zeros);
|
||||
CHECK_OK(fs.after_op(1, s));
|
||||
CHECK_OK(fs.before_op(2, s, &resync));
|
||||
|
||||
counts.route({0, 0, 0, 5}); /* layer 1's router: expert 3 only */
|
||||
CHECK_OK(fs.before_op(3, s, &resync));
|
||||
CHECK(none(0)); /* released */
|
||||
CHECK(pub(1, 3) == Pub::Bytes);
|
||||
CHECK(pub(1, 1) == Pub::Zeros);
|
||||
CHECK(none(2));
|
||||
/* A second slice of layer 1's rows routes expert 1 as well: read now, and waited on. */
|
||||
const int64_t waits = fs.waits();
|
||||
counts.route({0, 7, 0, 0});
|
||||
CHECK_OK(fs.before_op(3, s, &resync));
|
||||
CHECK(resync);
|
||||
CHECK_EQ(fs.waits(), waits + 1);
|
||||
CHECK(pub(1, 1) == Pub::Bytes);
|
||||
CHECK(pub(1, 3) == Pub::Bytes);
|
||||
/* A third routes nothing new: no read, no wait. */
|
||||
counts.route({0, 0, 0, 1});
|
||||
CHECK_OK(fs.before_op(3, s, &resync));
|
||||
CHECK(!resync);
|
||||
CHECK_EQ(fs.waits(), waits + 1);
|
||||
CHECK_OK(fs.before_op(4, s, &resync));
|
||||
|
||||
counts.route({0, 1, 0, 1});
|
||||
CHECK_OK(fs.before_op(5, s, &resync));
|
||||
CHECK(none(0) && none(1));
|
||||
CHECK(pub(2, 1) == Pub::Bytes && pub(2, 3) == Pub::Bytes);
|
||||
CHECK_OK(fs.before_op(6, s, &resync));
|
||||
CHECK_OK(fs.end_pass(s));
|
||||
for (int l = 0; l < L; ++l) CHECK(none(l));
|
||||
/* Two experts skipped at a trigger (layer 0's 3, layer 1's 1), one of them read by the
|
||||
* second slice; five units read, each once. */
|
||||
CHECK_EQ(m.stats().ssd_skipped_units, (uint64_t)2);
|
||||
CHECK_EQ(m.stats().ssd_units, (uint64_t)5);
|
||||
|
||||
/* A layer the source has no counts for (it has not reported) is read whole, so it can be read
|
||||
* ahead as before: layer 1 at layer 0's trigger. A counted one is not. */
|
||||
counts.missing = {1};
|
||||
CHECK(fs.begin_pass(&b));
|
||||
CHECK_OK(fs.before_op(0, s, &resync));
|
||||
counts.route({0, 0, 0, 3});
|
||||
CHECK_OK(fs.before_op(1, s, &resync));
|
||||
CHECK(pub(0, 3) == Pub::Bytes && pub(0, 1) == Pub::Zeros);
|
||||
CHECK(pub(1, 1) == Pub::Bytes && pub(1, 3) == Pub::Bytes);
|
||||
CHECK(none(2));
|
||||
CHECK_OK(fs.before_op(2, s, &resync));
|
||||
CHECK_OK(fs.before_op(3, s, &resync));
|
||||
CHECK(pub(1, 1) == Pub::Bytes && pub(1, 3) == Pub::Bytes);
|
||||
CHECK(none(2));
|
||||
CHECK_OK(fs.before_op(4, s, &resync));
|
||||
counts.route({0, 4, 0, 0});
|
||||
CHECK_OK(fs.before_op(5, s, &resync));
|
||||
CHECK(pub(2, 1) == Pub::Bytes && pub(2, 3) == Pub::Zeros);
|
||||
CHECK_OK(fs.before_op(6, s, &resync));
|
||||
CHECK_OK(fs.end_pass(s));
|
||||
for (int l = 0; l < L; ++l) CHECK(none(l));
|
||||
|
||||
/* With no layer counted, the first one is read at the pass's first op, as before. */
|
||||
counts.missing = {0, 1, 2};
|
||||
CHECK(fs.begin_pass(&b));
|
||||
CHECK_OK(fs.before_op(0, s, &resync));
|
||||
CHECK(resync);
|
||||
CHECK(pub(0, 1) == Pub::Bytes && pub(0, 3) == Pub::Bytes);
|
||||
CHECK(none(1));
|
||||
CHECK_OK(fs.end_pass(s));
|
||||
for (int l = 0; l < L; ++l) CHECK(none(l));
|
||||
|
||||
/* A pass whose rows route nearly every expert -- 64 rows an expert on average, here four
|
||||
* experts at top-1, so 256 rows -- is read whole and ahead like a layer without counts: the
|
||||
* counts are never asked for, so no trigger drains the stream, though they are there. One
|
||||
* row fewer is read exactly. */
|
||||
f.prog.meta.n_expert_used = 1;
|
||||
counts.missing.clear();
|
||||
FileStager wf;
|
||||
CHECK_OK(wf.init(f.prog, p, &m, &SharedCounts::get, &counts));
|
||||
CHECK_EQ(wf.whole_rows(), (int64_t)256);
|
||||
CHECK_EQ(fs.whole_rows(), (int64_t)0); /* top-k unknown: always exact */
|
||||
counts.route({0, 0, 0, 0}); /* routes nothing, were it asked */
|
||||
const int asked = counts.asked;
|
||||
RadBatch big{};
|
||||
big.n_tok = 256;
|
||||
CHECK(wf.begin_pass(&big));
|
||||
CHECK_OK(wf.before_op(0, s, &resync));
|
||||
CHECK(resync);
|
||||
CHECK(pub(0, 1) == Pub::Bytes && pub(0, 3) == Pub::Bytes);
|
||||
CHECK(none(1));
|
||||
CHECK_OK(wf.before_op(1, s, &resync));
|
||||
CHECK(pub(0, 1) == Pub::Bytes && pub(0, 3) == Pub::Bytes);
|
||||
CHECK(pub(1, 1) == Pub::Bytes && pub(1, 3) == Pub::Bytes); /* ahead, at layer 0's trigger */
|
||||
CHECK_OK(wf.before_op(1, s, &resync)); /* another slice: nothing left to read */
|
||||
CHECK(!resync);
|
||||
CHECK_OK(wf.before_op(2, s, &resync));
|
||||
CHECK_OK(wf.before_op(3, s, &resync));
|
||||
CHECK(none(0));
|
||||
CHECK(pub(2, 1) == Pub::Bytes && pub(2, 3) == Pub::Bytes);
|
||||
for (rad_op op = 4; op <= 6; ++op) CHECK_OK(wf.before_op(op, s, &resync));
|
||||
CHECK_OK(wf.end_pass(s));
|
||||
CHECK_EQ(counts.asked, asked);
|
||||
for (int l = 0; l < L; ++l) CHECK(none(l));
|
||||
|
||||
big.n_tok = 255;
|
||||
CHECK(wf.begin_pass(&big));
|
||||
CHECK_OK(wf.before_op(0, s, &resync));
|
||||
CHECK(none(0));
|
||||
counts.route({0, 2, 0, 0});
|
||||
CHECK_OK(wf.before_op(1, s, &resync));
|
||||
CHECK(pub(0, 1) == Pub::Bytes && pub(0, 3) == Pub::Zeros);
|
||||
CHECK(none(1));
|
||||
CHECK(counts.asked > asked);
|
||||
CHECK_OK(wf.end_pass(s));
|
||||
|
||||
rad_stream_sync(m.transfer_stream());
|
||||
rad_stream_destroy(s);
|
||||
std::remove(path.c_str());
|
||||
}
|
||||
|
||||
/* The pool is a cache of the file tier under a dynamic plan. A read that finds it full gives its
|
||||
* coldest pooled unit back to the file tier when that unit is colder than the one read, never one
|
||||
* of the layer being read or of one whose ops are about to run; the unit given back -- here one
|
||||
* the plan put in the pool, in a layer with nothing on the file tier -- is read back by its own
|
||||
* layer's trigger; and a read whose only copy is a deposit is waited on before the layer's ops. */
|
||||
TEST(a_full_pool_gives_back_its_coldest_unit_and_the_stager_reads_it_again) {
|
||||
Fixture f;
|
||||
const int L = 3;
|
||||
build_moe_layers(f, L, 4, MiB + 1000, MiB / 2 + 24);
|
||||
f.prog.meta.n_expert = 4;
|
||||
const std::string path = "place_test_cache.rad";
|
||||
const std::vector<uint8_t> img = write_container(f, path);
|
||||
if (img.empty()) {
|
||||
std::printf(" SKIP the working directory has no O_DIRECT\n");
|
||||
return;
|
||||
}
|
||||
/* Rank order: layer 0's experts, then layer 1's, then layer 2's. Layer 0's four fill the
|
||||
* pool and the rest go to the file tier, so layer 0 has nothing there. The card holds the
|
||||
* embedding and the two file buffers; a resident would also need a hot-cache shadow slot,
|
||||
* and the plan has no room for the pair. */
|
||||
std::vector<RadFileProfile> prof;
|
||||
for (int l = 0; l < L; ++l)
|
||||
for (int e = 0; e < 4; ++e)
|
||||
prof.push_back(RadFileProfile{l, e, 0.9f - 0.3f * (float)l - 0.05f * (float)e, 0.0f});
|
||||
const int64_t stride = align_up(align_up(MiB + 1000, RAD_ALIGN_UNIT) + MiB / 2 + 24,
|
||||
RAD_ALIGN_UNIT);
|
||||
Config c = base_config();
|
||||
c.placement = "expert_tiered";
|
||||
c.vram_weights_mib = 15;
|
||||
const int64_t reserve = RAD_PLACE_FILE_STAGE_SLOTS * stride +
|
||||
RAD_PLACE_FILE_WINDOWS * RAD_PLACE_FILE_WINDOW_BYTES;
|
||||
c.host_pool_mib = (reserve + 4 * stride) / MiB + 1;
|
||||
c.weights_disk_tier = true;
|
||||
PlannerInput in{&f.prog, &c, 0, 1, prof.data(), (int64_t)prof.size()};
|
||||
Plan p;
|
||||
CHECK_OK(Planner(in).plan(&p));
|
||||
REQUIRE(p.dynamic);
|
||||
auto tier_of = [&](int l, int e) { return p.units[(size_t)unit_at(p, l, e)].tier; };
|
||||
for (int e = 0; e < 4; ++e) {
|
||||
REQUIRE(tier_of(0, e) == Tier::HostPinned);
|
||||
REQUIRE(tier_of(1, e) == Tier::SSD);
|
||||
REQUIRE(tier_of(2, e) == Tier::SSD);
|
||||
}
|
||||
|
||||
Mover m;
|
||||
MoverConfig mc;
|
||||
mc.container_path = path;
|
||||
CHECK_OK(m.init(f.prog, p, mc));
|
||||
RadStream s = nullptr;
|
||||
CHECK_OK(rad_stream_create(&s, 0));
|
||||
CHECK_OK(m.bind_compute_stream(s));
|
||||
HeatEngine h;
|
||||
CHECK_OK(h.init(p, HeatParams{}));
|
||||
REQUIRE(h.enabled());
|
||||
SharedCounts counts(4);
|
||||
FileStager fs;
|
||||
CHECK_OK(fs.init(f.prog, p, &m, &SharedCounts::get, &counts));
|
||||
/* Layer 0 is covered though the plan put none of it on the file tier: a deposit may give its
|
||||
* pooled units back to the file tier. */
|
||||
REQUIRE_EQ(fs.n_layers(), (size_t)L);
|
||||
auto pub = [&](int l, int e) { return published(m, p, f.prog, unit_at(p, l, e), img, s); };
|
||||
|
||||
/* Where the pooled units are published: their pool slots, which this test never fills (the
|
||||
* load phase does), so they are compared by address. */
|
||||
auto addr = [&](int l, int e) {
|
||||
return m.residency()->lookup(p.units[(size_t)unit_at(p, l, e)].weights.front())->ptr;
|
||||
};
|
||||
void* const pooled[3] = { addr(0, 1), addr(0, 2), addr(0, 3) };
|
||||
for (void* q : pooled) CHECK(q != nullptr);
|
||||
|
||||
/* Layer 2's expert 0 has routed before; nothing else has. */
|
||||
const int32_t hist[4] = {3, 0, 0, 0};
|
||||
h.observe(2, hist, 4);
|
||||
CHECK_OK(m.begin_dispatch(1, &h));
|
||||
|
||||
RadBatch b{};
|
||||
bool resync = false;
|
||||
CHECK(fs.begin_pass(&b));
|
||||
CHECK_OK(fs.before_op(0, s, &resync));
|
||||
counts.route({1, 0, 0, 0});
|
||||
CHECK_OK(fs.before_op(1, s, &resync)); /* layer 0: nothing on the file tier */
|
||||
CHECK(!resync);
|
||||
CHECK_OK(fs.before_op(2, s, &resync));
|
||||
/* Layer 1's expert 2 is as cold as every pooled unit: not worth a slot, read into the
|
||||
* buffer. */
|
||||
counts.route({0, 0, 2, 0});
|
||||
CHECK_OK(fs.before_op(3, s, &resync));
|
||||
CHECK(pub(1, 2) == Pub::Bytes);
|
||||
CHECK_EQ(m.stats().pool_evictions, (uint64_t)0);
|
||||
CHECK_OK(fs.before_op(4, s, &resync));
|
||||
/* Layer 2's expert 0 is warmer: the coldest pooled unit outside layer 2 goes back to the file
|
||||
* tier, the lowest of the equally cold ones -- layer 0's expert 0 -- and its weights point at
|
||||
* the zero region until its own layer reads it. */
|
||||
counts.route({3, 0, 0, 0});
|
||||
CHECK_OK(fs.before_op(5, s, &resync));
|
||||
CHECK(pub(2, 0) == Pub::Bytes);
|
||||
CHECK_EQ(m.stats().pool_evictions, (uint64_t)1);
|
||||
CHECK(pub(0, 0) == Pub::Zeros);
|
||||
CHECK(m.on_file_tier({unit_at(p, 0, 0)}));
|
||||
CHECK(addr(0, 1) == pooled[0] && addr(0, 2) == pooled[1] && addr(0, 3) == pooled[2]);
|
||||
CHECK_OK(fs.before_op(6, s, &resync));
|
||||
CHECK_OK(fs.end_pass(s));
|
||||
|
||||
/* The pool slot it gave up comes back after its quarantine. */
|
||||
for (int d = 2; d < 5; ++d) {
|
||||
CHECK_OK(rad_stream_sync(s));
|
||||
CHECK_OK(m.begin_dispatch(d, &h));
|
||||
}
|
||||
|
||||
/* Layer 0's trigger routes the unit back: it is read into the free pool slot -- a read
|
||||
* whose only copy is that deposit, which the stream waits on all the same. */
|
||||
CHECK(fs.begin_pass(&b));
|
||||
CHECK_OK(fs.before_op(0, s, &resync));
|
||||
counts.route({1, 0, 0, 0});
|
||||
const int64_t waits = fs.waits();
|
||||
CHECK_OK(fs.before_op(1, s, &resync));
|
||||
CHECK(resync);
|
||||
CHECK_EQ(m.stats().ssd_deposits, (uint64_t)1);
|
||||
CHECK_EQ(fs.waits(), waits + 1);
|
||||
CHECK(pub(0, 0) == Pub::Bytes);
|
||||
CHECK(!m.on_file_tier({unit_at(p, 0, 0)}));
|
||||
counts.route({0, 0, 0, 0});
|
||||
for (rad_op op = 2; op <= 6; ++op) CHECK_OK(fs.before_op(op, s, &resync));
|
||||
CHECK_OK(fs.end_pass(s));
|
||||
/* A deposit outlives the pass: the unit stays in its pool slot. */
|
||||
CHECK(pub(0, 0) == Pub::Bytes);
|
||||
|
||||
rad_stream_sync(m.transfer_stream());
|
||||
rad_stream_sync(s);
|
||||
rad_stream_destroy(s);
|
||||
std::remove(path.c_str());
|
||||
}
|
||||
|
||||
/* A layer with nothing on the file tier is held by neither buffer, yet its ops are about to be
|
||||
* issued: a read-ahead of the next layer that finds the pool full must not give one of its pooled
|
||||
* units back (the weights would point at the zero region for an op still to come), while the same
|
||||
* pass's read-ahead from the next layer on is free to take it. */
|
||||
TEST(a_read_ahead_never_takes_a_pooled_unit_of_the_layer_about_to_run) {
|
||||
Fixture f;
|
||||
const int L = 3;
|
||||
build_moe_layers(f, L, 4, MiB + 1000, MiB / 2 + 24);
|
||||
f.prog.meta.n_expert = 4;
|
||||
const std::string path = "place_test_cache2.rad";
|
||||
const std::vector<uint8_t> img = write_container(f, path);
|
||||
if (img.empty()) {
|
||||
SKIP("the working directory has no O_DIRECT");
|
||||
}
|
||||
/* Rank order: layer 0's experts, then layer 1's, then layer 2's. Layer 0's four fill the
|
||||
* pool and the rest go to the file tier, so layer 0 has nothing there. The card holds the
|
||||
* embedding and the two file buffers; a resident would also need a hot-cache shadow slot,
|
||||
* and the plan has no room for the pair. */
|
||||
std::vector<RadFileProfile> prof;
|
||||
for (int l = 0; l < L; ++l)
|
||||
for (int e = 0; e < 4; ++e)
|
||||
prof.push_back(RadFileProfile{l, e, 0.9f - 0.3f * (float)l - 0.05f * (float)e, 0.0f});
|
||||
const int64_t stride = align_up(align_up(MiB + 1000, RAD_ALIGN_UNIT) + MiB / 2 + 24,
|
||||
RAD_ALIGN_UNIT);
|
||||
Config c = base_config();
|
||||
c.placement = "expert_tiered";
|
||||
c.vram_weights_mib = 15;
|
||||
const int64_t reserve = RAD_PLACE_FILE_STAGE_SLOTS * stride +
|
||||
RAD_PLACE_FILE_WINDOWS * RAD_PLACE_FILE_WINDOW_BYTES;
|
||||
c.host_pool_mib = (reserve + 4 * stride) / MiB + 1;
|
||||
c.weights_disk_tier = true;
|
||||
PlannerInput in{&f.prog, &c, 0, 1, prof.data(), (int64_t)prof.size()};
|
||||
Plan p;
|
||||
CHECK_OK(Planner(in).plan(&p));
|
||||
REQUIRE(p.dynamic);
|
||||
auto tier_of = [&](int l, int e) { return p.units[(size_t)unit_at(p, l, e)].tier; };
|
||||
for (int e = 0; e < 4; ++e) {
|
||||
REQUIRE(tier_of(0, e) == Tier::HostPinned);
|
||||
REQUIRE(tier_of(1, e) == Tier::SSD);
|
||||
REQUIRE(tier_of(2, e) == Tier::SSD);
|
||||
}
|
||||
|
||||
Mover m;
|
||||
MoverConfig mc;
|
||||
mc.container_path = path;
|
||||
CHECK_OK(m.init(f.prog, p, mc));
|
||||
RadStream s = nullptr;
|
||||
CHECK_OK(rad_stream_create(&s, 0));
|
||||
CHECK_OK(m.bind_compute_stream(s));
|
||||
HeatEngine h;
|
||||
CHECK_OK(h.init(p, HeatParams{}));
|
||||
REQUIRE(h.enabled());
|
||||
SharedCounts counts(4);
|
||||
FileStager fs;
|
||||
CHECK_OK(fs.init(f.prog, p, &m, &SharedCounts::get, &counts));
|
||||
/* Layer 0 is covered though the plan put none of it on the file tier: a deposit may give its
|
||||
* pooled units back to the file tier. */
|
||||
REQUIRE_EQ(fs.n_layers(), (size_t)L);
|
||||
auto pub = [&](int l, int e) { return published(m, p, f.prog, unit_at(p, l, e), img, s); };
|
||||
|
||||
/* Where the pooled units are published: their pool slots, which this test never fills (the
|
||||
* load phase does), so they are compared by address. */
|
||||
auto addr = [&](int l, int e) {
|
||||
return m.residency()->lookup(p.units[(size_t)unit_at(p, l, e)].weights.front())->ptr;
|
||||
};
|
||||
void* const pooled[3] = { addr(0, 1), addr(0, 2), addr(0, 3) };
|
||||
for (void* q : pooled) CHECK(q != nullptr);
|
||||
|
||||
void* const pooled0 = addr(0, 0);
|
||||
/* Layers 1 and 2 are read whole, ahead (no counts for them); each has one warm expert. */
|
||||
counts.missing = {1, 2};
|
||||
const int32_t hist1[4] = {0, 0, 5, 0}, hist2[4] = {3, 0, 0, 0};
|
||||
h.observe(1, hist1, 4);
|
||||
h.observe(2, hist2, 4);
|
||||
CHECK_OK(m.begin_dispatch(1, &h));
|
||||
|
||||
RadBatch b{};
|
||||
bool resync = false;
|
||||
CHECK(fs.begin_pass(&b));
|
||||
CHECK_OK(fs.before_op(0, s, &resync));
|
||||
counts.route({1, 0, 0, 0});
|
||||
CHECK_OK(fs.before_op(1, s, &resync)); /* layer 0 starts; layer 1 read ahead */
|
||||
CHECK_EQ(m.stats().pool_evictions, (uint64_t)0);
|
||||
CHECK(addr(0, 0) == pooled0);
|
||||
CHECK(addr(0, 1) == pooled[0] && addr(0, 2) == pooled[1] && addr(0, 3) == pooled[2]);
|
||||
CHECK(pub(1, 2) == Pub::Bytes);
|
||||
CHECK_OK(fs.before_op(2, s, &resync));
|
||||
CHECK_OK(fs.before_op(3, s, &resync)); /* layer 1 starts; layer 2 read ahead */
|
||||
CHECK_EQ(m.stats().pool_evictions, (uint64_t)1);
|
||||
CHECK(pub(2, 0) == Pub::Bytes);
|
||||
CHECK_OK(fs.before_op(4, s, &resync));
|
||||
CHECK_OK(fs.before_op(5, s, &resync));
|
||||
CHECK_OK(fs.before_op(6, s, &resync));
|
||||
CHECK_OK(fs.end_pass(s));
|
||||
|
||||
/* A read-ahead the pass never reaches still copied (a deposit into the pool, say), and the
|
||||
* stream is ordered behind it when the pass ends. Once the slot layer 0 gave up is back, layer
|
||||
* 1 is read ahead at layer 0's trigger and the pass stops there. */
|
||||
for (int d = 2; d < 5; ++d) {
|
||||
CHECK_OK(rad_stream_sync(s));
|
||||
CHECK_OK(m.begin_dispatch(d, &h));
|
||||
}
|
||||
CHECK(fs.begin_pass(&b));
|
||||
CHECK_OK(fs.before_op(0, s, &resync));
|
||||
counts.route({1, 0, 0, 0});
|
||||
CHECK_OK(fs.before_op(1, s, &resync));
|
||||
const int64_t waits = fs.waits();
|
||||
CHECK_OK(fs.end_pass(s));
|
||||
CHECK_EQ(fs.waits(), waits + 1);
|
||||
|
||||
rad_stream_sync(m.transfer_stream());
|
||||
rad_stream_sync(s);
|
||||
rad_stream_destroy(s);
|
||||
std::remove(path.c_str());
|
||||
}
|
||||
|
||||
TEST(mover_promotes_and_demotes_through_the_shadow_slots) {
|
||||
HeatFixture hf;
|
||||
HeatEngine h;
|
||||
|
||||
@@ -272,6 +272,25 @@ TEST(an_expert_reads_its_own_hessian_before_its_layers) {
|
||||
CHECK(same_planes(run(both, e11), run(only_pool, e11)));
|
||||
}
|
||||
|
||||
TEST(a_vocabulary_heads_width_class_reads_the_heads_hessian) {
|
||||
/* A calibration run records the lm_head's input as `output`; the vocabulary-weighted head's
|
||||
* classes (output.k3, output.k4, ...) are rows of that one weight and quantise against it, as
|
||||
* a weight named `output` does. With no Gram at all GPTQ rounds to nearest, which differs. */
|
||||
NEED_LIBQUANT();
|
||||
const TempDir t("rad_quant_vhead"), e("rad_quant_novhead");
|
||||
REQUIRE(!t.path.empty() && !e.path.empty());
|
||||
REQUIRE(write_gram(t.path + "/gram.r0.output.bin", kC, kT, H()));
|
||||
auto run = [&](const std::string& dir, const char* name) -> Quantised {
|
||||
Opts o;
|
||||
o.s("codes", "i4").i("group", 32).s("scale", "f16").s("calib", dir.c_str());
|
||||
Quantised q = quantise(quantizer("gptq"), o, name, kR, kC, weight());
|
||||
CHECK_EQ(q.status, RAD_OK);
|
||||
return q;
|
||||
};
|
||||
CHECK(same_planes(run(t.path, "output.k4.weight"), run(t.path, "output.weight")));
|
||||
CHECK(!same_planes(run(t.path, "output.k4.weight"), run(e.path, "output.k4.weight")));
|
||||
}
|
||||
|
||||
TEST(gptq_through_lapack_matches_the_loops) {
|
||||
/* Where OpenBLAS was found the factorisations go through LAPACK; RAD_LQ_LAPACK=0 takes the
|
||||
* single-threaded loops, the reference. The same Gram in two directories (the factor cache is
|
||||
|
||||
+49
-3
@@ -746,6 +746,42 @@ TEST(route_report_is_asynchronous_and_drains_oldest_first) {
|
||||
CHECK_EQ(f.ctx.route_report(99, &r), RAD_E_INVAL);
|
||||
}
|
||||
|
||||
/* The file stager reads a layer's counts through the address the layer's last report named, at
|
||||
* the layer's next trigger. That holds for a buffer in the arena's fixed region or outside the
|
||||
* arena. A transient buffer is at another offset at another arena level, and a later transient
|
||||
* may share its bytes since no declared op reads the counts, so the source declines it and the
|
||||
* stager reads that layer whole. */
|
||||
TEST(the_counts_source_declines_a_transient_buffer) {
|
||||
Fixture f;
|
||||
f.P.arena_fixed_bytes = 4096;
|
||||
f.add_buffer("x", RAD_BF16, 64, 4, 0);
|
||||
CHECK_OK(f.start());
|
||||
char* const base = (char*)f.ctx.arena_base();
|
||||
REQUIRE(base != nullptr);
|
||||
int64_t n = -1;
|
||||
CHECK(f.ctx.route_counts_device(0, &n) == nullptr); /* nothing reported yet */
|
||||
CHECK_EQ(n, (int64_t)0);
|
||||
|
||||
RadRouting r{};
|
||||
r.n_expert = 4;
|
||||
r.top_k = 2;
|
||||
r.expert_count = (const int32_t*)(base + 256); /* the fixed region */
|
||||
CHECK_OK(f.step(1, 0, [&](Ctx& c) { CHECK_OK(c.route_report(0, &r)); }));
|
||||
CHECK(f.ctx.route_counts_device(0, &n) == r.expert_count);
|
||||
CHECK_EQ(n, (int64_t)4);
|
||||
|
||||
r.expert_count = (const int32_t*)(base + 4096 + 512); /* a transient */
|
||||
CHECK_OK(f.step(1, 1, [&](Ctx& c) { CHECK_OK(c.route_report(1, &r)); }));
|
||||
CHECK(f.ctx.route_counts_device(1, &n) == nullptr);
|
||||
CHECK_EQ(n, (int64_t)0);
|
||||
|
||||
static const int32_t outside[4] = { 1, 2, 3, 4 }; /* not the arena's */
|
||||
r.expert_count = outside;
|
||||
CHECK_OK(f.step(1, 2, [&](Ctx& c) { CHECK_OK(c.route_report(1, &r)); }));
|
||||
CHECK(f.ctx.route_counts_device(1, &n) == outside);
|
||||
CHECK_OK(rad_stream_sync(f.ctx.stream()));
|
||||
}
|
||||
|
||||
/* A step that drafts reports the same layer once per pass, all into the step's one bank. The drain
|
||||
* runs before every pass, so it must not take that bank until the step is over; taken early, it
|
||||
* would cover only the passes so far and miss the rest. */
|
||||
@@ -2373,12 +2409,14 @@ TEST(legacy_prefill_keying_only_fails_closed_for_dynamic_split_rows) {
|
||||
CHECK_EQ(f.ctx.pass_key(&b), (uint64_t)0);
|
||||
b.phase = RAD_PHASE_MIXED;
|
||||
CHECK_EQ(f.ctx.pass_key(&b), (uint64_t)0);
|
||||
/* Decode, verify and draft passes stay recordable: their launches read the keyed
|
||||
* context bound, not the live maximum (issue_passes_only_proven_kv_host_summaries). */
|
||||
b.phase = RAD_PHASE_DECODE; b.n_spec = 1;
|
||||
CHECK_EQ(f.ctx.pass_key(&b), (uint64_t)0);
|
||||
CHECK(f.ctx.pass_key(&b) != 0);
|
||||
b.n_spec = 0; b.draft_pass = -1;
|
||||
CHECK_EQ(f.ctx.pass_key(&b), (uint64_t)0);
|
||||
CHECK(f.ctx.pass_key(&b) != 0);
|
||||
b.draft_pass = 0;
|
||||
CHECK(f.ctx.pass_key(&b) != 0); // Ordinary decode remains recordable.
|
||||
CHECK(f.ctx.pass_key(&b) != 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2427,6 +2465,14 @@ TEST(issue_passes_only_proven_kv_host_summaries) {
|
||||
CHECK_EQ(issue(positions_device + 128, 1, 1, RAD_PHASE_PREFILL, 0), -1); // past step end
|
||||
CHECK_EQ(issue(positions_device + 64, 1, 1, RAD_PHASE_MIXED, 0), -1);
|
||||
CHECK_EQ(issue(positions_device + 64, 1, 1, RAD_PHASE_PREFILL, 1), -1);
|
||||
/* A plugin with no pass-key callback records its decode passes, so a launch there reads the
|
||||
* step's context bound plus its longest query, which the key holds, never the live maximum. */
|
||||
f.batch.max_ctx_len = 2048;
|
||||
f.batch.max_q_len = 2;
|
||||
CHECK_EQ(issue(used_device, 2, 2, RAD_PHASE_DECODE, 1), 2050);
|
||||
CHECK_EQ(issue(used_device + 1, 1, 2, RAD_PHASE_DECODE, 0), 2050);
|
||||
CHECK_EQ(issue(used_device, 3, 2, RAD_PHASE_DECODE, 1), -1); // still nothing to bound
|
||||
CHECK_EQ(issue(used_device, 2, 2, RAD_PHASE_PREFILL, 0), 1152); // prefill keeps the exact one
|
||||
}
|
||||
|
||||
TEST(the_prefill_geometry_key_reuses_equal_grids_and_separates_changed_grids) {
|
||||
|
||||
@@ -3560,4 +3560,124 @@ TEST(the_coupled_evidence_survives_the_drafters_greedy_build) {
|
||||
CHECK_EQ(ev.rows, (int64_t)6);
|
||||
}
|
||||
|
||||
/* The planes are sized for the rows a step can sample: one per token the step carries, so never
|
||||
* more than max_tok, and never fewer than max_seqs (a drafter's greedy pass). */
|
||||
TEST(the_sampler_rows_are_bounded_by_the_steps_tokens) {
|
||||
Registry reg;
|
||||
(void)reg.load_plugin(home() + "/kernels/libref.so", 0);
|
||||
RadModelMeta meta{};
|
||||
meta.arch_id = "sampler_rows";
|
||||
meta.name = "sampler_rows";
|
||||
RadBuildCtx bc{};
|
||||
bc.max_seqs = 4;
|
||||
bc.max_tok = 8;
|
||||
bc.max_ctx = 64;
|
||||
bc.max_spec = 7;
|
||||
bc.scope = "";
|
||||
Builder b(reg, meta, bc);
|
||||
Sampler s;
|
||||
SamplerConfig cfg;
|
||||
cfg.n_vocab = 16;
|
||||
cfg.n_vocab_local = 16;
|
||||
cfg.max_seqs = 4;
|
||||
cfg.max_spec = 7;
|
||||
cfg.max_tok = 8;
|
||||
cfg.max_hist = 16;
|
||||
cfg.max_candidates = 8;
|
||||
CHECK_OK(s.declare(&b, cfg));
|
||||
const int32_t d[7] = { 1, 2, 3, 4, 5, 6, 7 };
|
||||
Request r = make_req(1, { 1 }, greedy_params());
|
||||
r.n_draft = 7;
|
||||
r.draft = d;
|
||||
CHECK_OK(s.build_step({ &r }));
|
||||
Request q = make_req(2, { 1 }, greedy_params());
|
||||
CHECK_EQ(s.build_step({ &r, &q }), RAD_E_FULL);
|
||||
CHECK_OK(s.build_greedy(4));
|
||||
|
||||
/* A token bound below the sequences: a greedy pass still fits every sequence. */
|
||||
Builder b2(reg, meta, bc);
|
||||
Sampler t;
|
||||
cfg.max_tok = 2;
|
||||
CHECK_OK(t.declare(&b2, cfg));
|
||||
CHECK_OK(t.build_greedy(4));
|
||||
CHECK_EQ(t.build_greedy(5), RAD_E_FULL);
|
||||
}
|
||||
|
||||
/* A DRAFT PASS'S BUILD LEAVES THE STEP'S STAGING TO ITS UPLOAD.
|
||||
*
|
||||
* issue_serial_drafter and block_pass build their greedy passes right after the step's chain was
|
||||
* issued, and on a card that chain's uploads read the pinned staging only when the stream reaches
|
||||
* them, behind the step's forward pass. build_greedy zeroed the n-gram pairs there, so on a server
|
||||
* with a drafter a banning request uploaded n = 0 and was never banned on the card. Host-site ops
|
||||
* join their stream before they run, so the race itself cannot show on the host backend; the
|
||||
* pairs are checked instead, and the ban still runs in the step after the greedy build. */
|
||||
TEST(a_drafters_greedy_build_leaves_the_steps_ngram_pairs_to_its_upload) {
|
||||
HostChain ch(16, 2, 0);
|
||||
NEED_CHAIN(ch)
|
||||
SamplingParams sp = greedy_params();
|
||||
sp.ngram_ban_n = 2;
|
||||
sp.ngram_window = 8;
|
||||
/* 4 followed 3 once, so after the last 3 the ban removes 4 and 5 is the argmax. */
|
||||
std::vector<float> lg(16, 0.0f);
|
||||
lg[4] = 2.0f;
|
||||
lg[5] = 1.0f;
|
||||
Request a = make_req(1, { 3, 4, 3 }, sp);
|
||||
std::vector<int32_t> tok;
|
||||
CHECK_OK(ch.step({ &a }, lg, &tok));
|
||||
CHECK_EQ(tok[0], 5);
|
||||
CHECK_EQ(ch.s.staged_ngram(0)[0], 2);
|
||||
CHECK_EQ(ch.s.staged_ngram(0)[1], 8);
|
||||
|
||||
CHECK_OK(ch.s.build_greedy(2));
|
||||
CHECK_EQ(ch.s.staged_ngram(0)[0], 2);
|
||||
CHECK_EQ(ch.s.staged_ngram(0)[1], 8);
|
||||
|
||||
Request b = make_req(2, { 3, 4, 3 }, sp);
|
||||
CHECK_OK(ch.step({ &b }, lg, &tok));
|
||||
CHECK_EQ(tok[0], 5);
|
||||
}
|
||||
|
||||
/* A top-1 row keeps its one candidate through every cut, so a step of top-1 rows issues none: a
|
||||
* greedy row asking for logprobs (a top-1 chain row, as every greedy row is under a split
|
||||
* vocabulary) with top-p, min-p, typical and XTC set samples its argmax and its logprob without
|
||||
* them. A row with more than one candidate issues all four. Every row of a drafter's greedy pass
|
||||
* is top-1 too, with those fields at 0; under a split vocabulary it issued top-p and typical, a
|
||||
* max and a sum over the candidate width a row, every round. */
|
||||
TEST(a_top1_row_issues_no_candidate_cut) {
|
||||
HostChain ch(32, 2, 0);
|
||||
NEED_CHAIN(ch)
|
||||
auto issued = [&](const char* name) {
|
||||
ch.ctx.flush_issued();
|
||||
for (const OpInfo& o : ch.prog.ops)
|
||||
if (o.op == name && o.issued) return true;
|
||||
return false;
|
||||
};
|
||||
static const char* const kCuts[] = { "sample_topp", "sample_minp", "sample_typical",
|
||||
"sample_xtc" };
|
||||
SamplingParams g = greedy_params();
|
||||
g.n_probs = 1;
|
||||
g.top_p = 0.5f;
|
||||
g.min_p = 0.1f;
|
||||
g.typical_p = 0.5f;
|
||||
g.xtc_probability = 1.0f;
|
||||
g.xtc_threshold = 0.01f;
|
||||
std::vector<float> lg(32);
|
||||
for (int t = 0; t < 32; ++t) lg[(size_t)t] = 0.1f * (float)t;
|
||||
Request a = make_req(1, { 1 }, g);
|
||||
std::vector<int32_t> tok;
|
||||
CHECK_OK(ch.step({ &a }, lg, &tok));
|
||||
CHECK_EQ(tok[0], 31);
|
||||
TokenLogprobs lp;
|
||||
CHECK_OK(ch.s.logprobs_for(0, tok[0], &lp));
|
||||
CHECK_NEAR(lp.logprob, lg[31] - log_sum_exp(lg), 1e-5);
|
||||
for (const char* op : kCuts) CHECK(!issued(op));
|
||||
|
||||
SamplingParams two = g;
|
||||
two.temp = 1.0f;
|
||||
two.top_k = 2;
|
||||
Request b = make_req(2, { 1 }, two);
|
||||
CHECK_OK(ch.step({ &b }, lg, &tok));
|
||||
for (const char* op : kCuts) CHECK(issued(op));
|
||||
}
|
||||
|
||||
RAD_TEST_MAIN()
|
||||
+151
-6
@@ -9,7 +9,9 @@
|
||||
* a time, and the assembly must equal the buffered body built by the same server.
|
||||
*/
|
||||
#include "server_fakes.h"
|
||||
#include "work_counter.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
namespace {
|
||||
@@ -558,12 +560,12 @@ Text text_streamed(const std::string& path, const std::string& body) {
|
||||
|
||||
} /* namespace */
|
||||
|
||||
/* What the server holds back while a reply runs (the longest stop string less a byte, an unfinished
|
||||
* character, a half-written escape) and releases at the end: for every split into two drains and
|
||||
* one byte a drain, the streamed text of chat, completions and llama-server's native completion is
|
||||
* the buffered text, and the finish agrees. A stop string's bytes never reach the wire, or the
|
||||
* concatenation would hold them. On chat a reply that starts inside its reasoning block applies
|
||||
* its stop strings only after the closer. */
|
||||
/* What the server holds back while a reply runs (a tail that may still become a stop string, an
|
||||
* unfinished character, a half-written escape) and releases at the end: for every split into two
|
||||
* drains and one byte a drain, the streamed text of chat, completions and llama-server's native
|
||||
* completion is the buffered text, and the finish agrees. A stop string's bytes never reach the
|
||||
* wire, or the concatenation would hold them. On chat a reply that starts inside its reasoning
|
||||
* block applies its stop strings only after the closer. */
|
||||
TEST(a_streamed_text_is_the_buffered_text_at_every_drain_boundary) {
|
||||
struct Case {
|
||||
const char* name;
|
||||
@@ -578,6 +580,8 @@ TEST(a_streamed_text_is_the_buffered_text_at_every_drain_boundary) {
|
||||
{ "characters around a stop", "\xC3\xA9STOP\xC3\xA9", "STOP", false },
|
||||
{ "escapes", "q\\u12\\\\\"x\\", "", false },
|
||||
{ "a stop longer than the reply's tail", "abcZZ", "ZZZ", false },
|
||||
{ "a tail that stops being a stop's start", "abSTxSTOPy", "STOP", false },
|
||||
{ "a stop's start that starts it again", "xSTASTARy", "STAR", false },
|
||||
};
|
||||
for (const char* path : { "/v1/chat/completions", "/v1/completions", "/completion" }) {
|
||||
for (const Case& c : cases) {
|
||||
@@ -608,6 +612,147 @@ TEST(a_streamed_text_is_the_buffered_text_at_every_drain_boundary) {
|
||||
}
|
||||
}
|
||||
|
||||
/* A running choice holds back only a tail that may still become a stop string: what precedes it is
|
||||
* on the wire after the drain that produced it, on chat, completions and llama-server's native
|
||||
* completion. The hold-back this replaced kept the longest stop string less a byte off the wire
|
||||
* whatever the tail was, so with a ten-byte stop every delta trailed by nine bytes and a short
|
||||
* reply showed nothing before its end. */
|
||||
TEST(a_running_choice_holds_back_only_what_may_still_become_a_stop_string) {
|
||||
struct Step {
|
||||
const char* piece; /* the drain's new bytes */
|
||||
const char* wire; /* everything on the wire after it */
|
||||
};
|
||||
const Step steps[] = {
|
||||
{ "Hello", "Hello" },
|
||||
{ " ENDOF", "Hello " }, /* "ENDOF" may still become "ENDOFREPLY" */
|
||||
{ "X\n", "Hello ENDOFX" }, /* it cannot now, but "\n" may become "\n\n" */
|
||||
{ "ENDO", "Hello ENDOFX\n" }, /* "\nE" cannot, "ENDO" may become "ENDOFREPLY" */
|
||||
{ "FREPLY tail", "Hello ENDOFX\n" }, /* the stop is cut, and nothing of it went out */
|
||||
};
|
||||
for (const char* path : { "/v1/chat/completions", "/v1/completions", "/completion" }) {
|
||||
Fixture f;
|
||||
const std::string stop = R"(,"stop":["ENDOFREPLY","\n\n"],"stream":true})";
|
||||
const std::string body = std::string(path) == "/v1/chat/completions"
|
||||
? R"({"messages":[{"role":"user","content":"hi"}],"max_tokens":1000)" + stop
|
||||
: R"({"prompt":"hi","max_tokens":1000)" + stop;
|
||||
f.sched.manual = true;
|
||||
HttpResponse r = f.post(path, body);
|
||||
f.sched.manual = false;
|
||||
REQUIRE(r.status == 200);
|
||||
REQUIRE(r.streaming());
|
||||
const size_t i = f.sched.seen.size() - 1;
|
||||
std::string out, c;
|
||||
r.next(c);
|
||||
out += c;
|
||||
for (const Step& s : steps) {
|
||||
f.sched.push(i, s.piece);
|
||||
c.clear();
|
||||
r.next(c);
|
||||
out += c;
|
||||
const Text got = text_streamed(path, out);
|
||||
if (got.text == s.wire) continue;
|
||||
CHECK_EQ(got.text, std::string(s.wire));
|
||||
fprintf(stderr, " %s, after \"%s\"\n", path, s.piece);
|
||||
}
|
||||
f.sched.finish(i, Finish::Stop);
|
||||
for (int k = 0; k < 64; ++k) {
|
||||
c.clear();
|
||||
const bool more = r.next(c);
|
||||
out += c;
|
||||
if (!more) break;
|
||||
}
|
||||
r.on_close(true);
|
||||
const Text all = text_streamed(path, out);
|
||||
CHECK_EQ(all.text, std::string("Hello ENDOFX\n"));
|
||||
CHECK_EQ(all.finish, std::string(std::string(path) == "/completion" ? "word" : "stop"));
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
/* The work of 24 drains of a streamed completion, in radtest::Work's unit, each after a short
|
||||
* piece of text, once the text is longer than any stop string: what each drain holds back is then
|
||||
* looked for in as many tails as the longest stop string is long. 20 pieces of 300 bytes, each
|
||||
* the next byte of `fill`, come first. Also checks the text arrives. */
|
||||
uint64_t drains_work(const std::string& stops, const std::string& fill = "the quick brown ") {
|
||||
Fixture f;
|
||||
f.sched.manual = true;
|
||||
HttpResponse r = f.post("/v1/completions", R"({"prompt":"hi","max_tokens":100000,"stream":true,)"
|
||||
R"("stop":)" + stops + "}");
|
||||
f.sched.manual = false;
|
||||
CHECK_EQ(r.status, 200);
|
||||
CHECK(r.streaming());
|
||||
if (r.status != 200 || !r.streaming()) return 0;
|
||||
const size_t i = f.sched.seen.size() - 1;
|
||||
std::string out, c;
|
||||
r.next(c);
|
||||
out += c;
|
||||
std::string sent;
|
||||
for (int k = 0; k < 20; ++k) {
|
||||
const std::string part(300, fill[(size_t)k % fill.size()]);
|
||||
sent += part;
|
||||
f.sched.push(i, part);
|
||||
c.clear();
|
||||
r.next(c);
|
||||
out += c;
|
||||
}
|
||||
uint64_t w = 0;
|
||||
for (int k = 0; k < 24; ++k) {
|
||||
const std::string piece = "word " + std::to_string(k) + ", ";
|
||||
sent += piece;
|
||||
f.sched.push(i, piece);
|
||||
c.clear();
|
||||
w += radtest::work().of([&] { r.next(c); });
|
||||
out += c;
|
||||
}
|
||||
f.sched.finish(i, Finish::Stop);
|
||||
for (int k = 0; k < 64; ++k) {
|
||||
c.clear();
|
||||
const bool more = r.next(c);
|
||||
out += c;
|
||||
if (!more) break;
|
||||
}
|
||||
r.on_close(true);
|
||||
CHECK_EQ(text_streamed("/v1/completions", out).text, sent);
|
||||
return w;
|
||||
}
|
||||
|
||||
} /* namespace */
|
||||
|
||||
/* A request may send 64 stop strings of 4 KiB, and a running choice's hold-back looks at the tails
|
||||
* of what it has not sent, up to the longest stop string, on each drain. A tail is compared only
|
||||
* where it starts with a byte some stop string starts with, so stop strings the text cannot start
|
||||
* cost a drain a lookup per tail: such a drain costs about as much as one with a single two-byte
|
||||
* stop. Comparing every tail with every stop string, 262 080 calls a drain, cost three hundred
|
||||
* times. */
|
||||
TEST(a_drain_looks_for_long_stop_strings_only_where_they_can_start) {
|
||||
json many = json::array();
|
||||
for (int k = 0; k < 64; ++k) many.push_back("~" + std::string(4095, (char)('a' + k % 26)));
|
||||
const uint64_t one = drains_work(R"(["~~"])"), all = drains_work(many.dump());
|
||||
std::fprintf(stderr, " one stop %llu, 64 of 4 KiB %llu %s, ratio %.2f\n",
|
||||
(unsigned long long)one, (unsigned long long)all, radtest::work().unit(),
|
||||
(double)all / (double)one);
|
||||
CHECK((double)all / (double)one < (radtest::work().exact() ? 20.0 : 40.0));
|
||||
}
|
||||
|
||||
/* The client sets the stop strings and steers the text: 64 stop strings of 4 KiB that all begin
|
||||
* with 4093 'a', and a reply that is thousands of 'a' and then something else, matches them for
|
||||
* as long as there are 'a' and then no more, at every one of the 4095 tails of every one of the
|
||||
* 64 strings, which is 500 million bytes compared on a drain with no bound. The comparisons share
|
||||
* a budget past which a drain holds back all it has not sent, so the cost of a drain is bounded
|
||||
* whatever the text. */
|
||||
TEST(a_drain_that_almost_matches_long_stop_strings_costs_a_bounded_amount) {
|
||||
json many = json::array();
|
||||
for (int k = 0; k < 64; ++k)
|
||||
many.push_back(std::string(4093, 'a') + (char)('0' + k / 8) + (char)('0' + k % 8));
|
||||
const uint64_t one = drains_work(R"(["~~"])");
|
||||
const uint64_t all = drains_work(many.dump(), "aaaaaaaaaaaaaaaaaaax");
|
||||
std::fprintf(stderr, " one stop %llu, 64 of 4 KiB almost matched %llu %s, ratio %.2f\n",
|
||||
(unsigned long long)one, (unsigned long long)all, radtest::work().unit(),
|
||||
(double)all / (double)one);
|
||||
CHECK((double)all / (double)one < (radtest::work().exact() ? 40.0 : 80.0));
|
||||
}
|
||||
|
||||
/* ================================================================== Anthropic's stop reasons */
|
||||
|
||||
/* Anthropic's stop_reason and stop_sequence say why a reply ended, buffered and streamed alike: a
|
||||
|
||||
+10
-3
@@ -416,13 +416,20 @@ void wait_windows(GbnfGrammar& g, const Vocab& vb, int n) {
|
||||
/* Waiting costs the same at any length. A lazy grammar sees every token of the reply until its
|
||||
* word appears, and each speculative window copies its state twice; the last tokens of a long
|
||||
* reply must cost what the first did. Counted in work, 20,000 windows at the start and again after
|
||||
* 200,000 more. */
|
||||
* 200,000 more, each the least of three runs: under the CPU-time fallback (a container build, tests
|
||||
* beside it) one run alone came out 1.65x the other. */
|
||||
TEST(lazy_grammar_waiting_work_does_not_grow_with_the_reply) {
|
||||
Vocab vb;
|
||||
auto g = make(vb, true, { "<tool_call>\n" }, {});
|
||||
const uint64_t first = radtest::work().of([&] { wait_windows(*g, vb, 20000); });
|
||||
auto least = [&] {
|
||||
uint64_t m = UINT64_MAX;
|
||||
for (int k = 0; k < 3; ++k)
|
||||
m = std::min(m, radtest::work().of([&] { wait_windows(*g, vb, 20000); }));
|
||||
return m;
|
||||
};
|
||||
const uint64_t first = least();
|
||||
wait_windows(*g, vb, 200000);
|
||||
const uint64_t last = radtest::work().of([&] { wait_windows(*g, vb, 20000); });
|
||||
const uint64_t last = least();
|
||||
CHECK(g->awaiting_trigger());
|
||||
std::printf(" lazy wait: %llu then %llu %s per 20k windows\n", (unsigned long long)first,
|
||||
(unsigned long long)last, radtest::work().unit());
|
||||
|
||||
@@ -1144,7 +1144,7 @@ TEST(input_reference_takes_the_models_h264_round_trip) {
|
||||
guided(v, 18);
|
||||
const std::string pic = png_rgb(301, 171, 200, 40, 90);
|
||||
HttpResponse r = v.create(Videos::body({ { "input_reference", png_url(pic) } }));
|
||||
if (r.status == 503) return; /* a build without libx264 refuses it, as it should */
|
||||
if (r.status == 501) return; /* a build without an H.264 encoder refuses it, as it should */
|
||||
REQUIRE_EQ(r.status, 200);
|
||||
const gen::VideoRequest& q = v.gen.last();
|
||||
REQUIRE_EQ(q.image.size(), (size_t)256 * 256 * 3);
|
||||
|
||||
Reference in new issue
Block a user