Archived
Merge main into clef-flash-arch-plugin
This commit is contained in:
commit
d24cf32a13
114 files changed
+26614
-621
No files matched your search
@@ -604,6 +604,19 @@ set_tests_properties(ops_doc PROPERTIES
|
||||
TIMEOUT ${RAD_TEST_TIMEOUT}
|
||||
ENVIRONMENT "ROCR_VISIBLE_DEVICES=99")
|
||||
|
||||
# docs/KERNELS.md is generated by rad-kbench and merged by hand; a partial merge leaves a
|
||||
# library's "rows not reached" header from one run above a table from another (v1.13.0: 239
|
||||
# against 243 rows). The counts must agree with each other and with the headline; cheap.
|
||||
if(EXISTS ${CMAKE_SOURCE_DIR}/docs/KERNELS.md)
|
||||
add_test(NAME kernel_report_check
|
||||
COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/kernel_report_check.sh
|
||||
${CMAKE_SOURCE_DIR}/docs/KERNELS.md)
|
||||
set_tests_properties(kernel_report_check PROPERTIES
|
||||
LABELS "fast;unit"
|
||||
SKIP_RETURN_CODE 77
|
||||
TIMEOUT ${RAD_TEST_TIMEOUT})
|
||||
endif()
|
||||
|
||||
# tools/rad-export. Its standard-library checks always run; the merge arithmetic runs where torch
|
||||
# and safetensors import, and the PEFT comparison where peft and transformers do too.
|
||||
find_program(RAD_PYTHON3 NAMES python3)
|
||||
|
||||
+28
-5
@@ -8226,10 +8226,12 @@ TEST(gemma3_without_fused_junctions_every_linear_quantises_into_what_it_reads) {
|
||||
CHECK(quant >= 2 * (int)m.layers.size());
|
||||
}
|
||||
|
||||
/* Under a lossy --tp-wire the fused all-reduce junctions, which send the exact wire only, still
|
||||
* serve the steps whose message goes out exact anyway: a decode step's few rows fold every
|
||||
* junction's all-reduce in, while a prefill chunk above --tp-wire-min-kb keeps the lossy
|
||||
* all-reduce, unfused. Both families: the MXFP4 trunk's fp8 junction and a w4a8 trunk's int8 one. */
|
||||
/* Under a lossy --tp-wire a decode step's few rows, whose message goes out exact, fold every
|
||||
* junction's all-reduce in. On the MXFP4 trunk a lossy step up to kAr6MaxRows (24) does too,
|
||||
* through the fp8 junction's lossy twin (ar_rmsnorm_post_quant_fp8 at wire 6; TranslateGemma's
|
||||
* 5376-wide row is whole 64-element groups, its last 512-element chunk padded); a taller one, like a
|
||||
* prefill chunk, keeps the lossy all-reduce, unfused. A w4a8 trunk's int8 junction sends the exact
|
||||
* wire only. Both families: the MXFP4 trunk's fp8 junction and a w4a8 trunk's int8 one. */
|
||||
TEST(gemma3_under_a_lossy_wire_small_steps_keep_the_fused_junction) {
|
||||
MetaKV mk = gemma3_meta();
|
||||
const RadEncoding mx = rad_enc_affine(RAD_FP4E2M1, RAD_E8M0, 1, rad::arch::RAD_MX_GROUP);
|
||||
@@ -8244,7 +8246,7 @@ TEST(gemma3_under_a_lossy_wire_small_steps_keep_the_fused_junction) {
|
||||
ctx.tp_wire_min_bytes = 128 * 1024;
|
||||
REQUIRE_EQ(gemma3::declare(&b, mk.meta(), &ctx), RAD_OK);
|
||||
const gemma3::Model& m = gemma3::g_model[rank];
|
||||
if (is_mx) CHECK(m.fuse_mx && m.fuse_mx_ar);
|
||||
if (is_mx) CHECK(m.fuse_mx && m.fuse_mx_ar && m.fuse_mx_ar6);
|
||||
else CHECK(!m.fuse_mx && m.fuse && m.fuse_ar);
|
||||
auto issued = [&](const RadCtx& c, std::initializer_list<const char*> names) {
|
||||
int n = 0;
|
||||
@@ -8263,6 +8265,27 @@ TEST(gemma3_under_a_lossy_wire_small_steps_keep_the_fused_junction) {
|
||||
CHECK_EQ(fused_pre, 0);
|
||||
/* Every junction the decode step fused is an all-reduce the prefill step issues alone. */
|
||||
CHECK_EQ(issued(*v[1], { "all_reduce" }), issued(*v[0], { "all_reduce" }) + fused_dec);
|
||||
/* 24 rows (24 x 5376 x 2 bytes, above the floor): the MXFP4 trunk fuses the same junctions
|
||||
* through the lossy twin, other op instances than the decode step's; the int8 one cannot. */
|
||||
const auto mid = kit(b, {}, { 24 });
|
||||
const auto vm = run_passes(b, gemma3::step, { mid.get() }, rank, 2);
|
||||
CHECK_PASSES(b, vm);
|
||||
const int fused_mid = issued(*vm[0], { "ar_rmsnorm_quant_i8", "ar_rmsnorm_post_quant_fp8" });
|
||||
if (is_mx) {
|
||||
CHECK_EQ(fused_mid, fused_dec);
|
||||
CHECK_EQ(issued(*vm[0], { "all_reduce" }), issued(*v[0], { "all_reduce" }));
|
||||
std::vector<int> dec_ids;
|
||||
for (const RecIssue& i : v[0]->issues)
|
||||
if (const RecOp* o = b.op_of(i.op); o && o->op == "ar_rmsnorm_post_quant_fp8")
|
||||
dec_ids.push_back((int)i.op);
|
||||
int shared = 0;
|
||||
for (const RecIssue& i : vm[0]->issues)
|
||||
if (const RecOp* o = b.op_of(i.op); o && o->op == "ar_rmsnorm_post_quant_fp8")
|
||||
shared += std::find(dec_ids.begin(), dec_ids.end(), (int)i.op) != dec_ids.end();
|
||||
CHECK_EQ(shared, 0);
|
||||
} else {
|
||||
CHECK_EQ(fused_mid, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+211
-54
@@ -7,6 +7,7 @@
|
||||
* back.
|
||||
*/
|
||||
#include "rad_test.h"
|
||||
#include "gguf_writer.h"
|
||||
#include "format/checkpoint.h"
|
||||
#include "format/encoding.h"
|
||||
#include "rad_plugin.h"
|
||||
@@ -2054,60 +2055,9 @@ TEST(a_concat_declared_in_pieces_joins_every_piece_in_order) {
|
||||
* shape everything else uses; the legacy and Q4_K/Q6_K block types decode by their definitions. */
|
||||
namespace {
|
||||
|
||||
struct GKv {
|
||||
std::string key;
|
||||
uint32_t type; /* 4 u32, 6 f32, 8 string, 9 array of strings */
|
||||
double num = 0;
|
||||
std::vector<std::string> strs;
|
||||
};
|
||||
struct GTensor { std::string name; uint32_t type; std::vector<uint64_t> ne; std::vector<uint8_t> bytes; };
|
||||
|
||||
void put_bytes(std::string* b, const void* p, size_t n) { b->append((const char*)p, n); }
|
||||
void put_str(std::string* b, const std::string& s) {
|
||||
const uint64_t n = s.size();
|
||||
put_bytes(b, &n, 8);
|
||||
b->append(s);
|
||||
}
|
||||
|
||||
/* A GGUF v3 file of `kvs` and `ts`, every tensor at a 32-byte aligned offset. */
|
||||
void write_gguf(const std::string& path, const std::vector<GKv>& kvs, const std::vector<GTensor>& ts) {
|
||||
std::string b = "GGUF";
|
||||
const uint32_t ver = 3;
|
||||
const uint64_t nt = ts.size(), nk = kvs.size();
|
||||
put_bytes(&b, &ver, 4);
|
||||
put_bytes(&b, &nt, 8);
|
||||
put_bytes(&b, &nk, 8);
|
||||
for (const GKv& kv : kvs) {
|
||||
put_str(&b, kv.key);
|
||||
put_bytes(&b, &kv.type, 4);
|
||||
if (kv.type == 4) { const uint32_t v = (uint32_t)kv.num; put_bytes(&b, &v, 4); }
|
||||
else if (kv.type == 6) { const float v = (float)kv.num; put_bytes(&b, &v, 4); }
|
||||
else if (kv.type == 8) put_str(&b, kv.strs.at(0));
|
||||
else {
|
||||
const uint32_t et = 8;
|
||||
const uint64_t n = kv.strs.size();
|
||||
put_bytes(&b, &et, 4);
|
||||
put_bytes(&b, &n, 8);
|
||||
for (const std::string& s : kv.strs) put_str(&b, s);
|
||||
}
|
||||
}
|
||||
uint64_t off = 0;
|
||||
for (const GTensor& t : ts) {
|
||||
put_str(&b, t.name);
|
||||
const uint32_t nd = (uint32_t)t.ne.size();
|
||||
put_bytes(&b, &nd, 4);
|
||||
for (uint64_t d : t.ne) put_bytes(&b, &d, 8);
|
||||
put_bytes(&b, &t.type, 4);
|
||||
put_bytes(&b, &off, 8);
|
||||
off += (t.bytes.size() + 31) / 32 * 32;
|
||||
}
|
||||
while (b.size() % 32) b.push_back('\0');
|
||||
for (const GTensor& t : ts) {
|
||||
b.append((const char*)t.bytes.data(), t.bytes.size());
|
||||
while (b.size() % 32) b.push_back('\0');
|
||||
}
|
||||
write_file(path, b);
|
||||
}
|
||||
using ggufw::GKv;
|
||||
using ggufw::GTensor;
|
||||
using ggufw::write_gguf;
|
||||
|
||||
uint16_t h16(float v) { return rad_f32_to_f16(v); }
|
||||
|
||||
@@ -2308,6 +2258,213 @@ TEST(a_gguf_tensor_is_row_major_and_its_legacy_blocks_decode_by_definition) {
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
/* `rows` x `cols` blocks of Q4_K (type 12) or Q6_K (type 14) with arbitrary quants and scales and
|
||||
* finite f16 super-scales: random bits there would make NaNs, which equal nothing. */
|
||||
GTensor k_blocks(const char* name, uint32_t type, int64_t rows, int64_t cols, uint32_t seed) {
|
||||
GTensor t{ name, type, { (uint64_t)cols, (uint64_t)rows }, {} };
|
||||
uint32_t x = seed;
|
||||
auto fill = [&](int n) {
|
||||
for (int i = 0; i < n; ++i) {
|
||||
x = x * 1664525u + 1013904223u;
|
||||
t.bytes.push_back((uint8_t)(x >> 24));
|
||||
}
|
||||
};
|
||||
auto push16 = [&](float v) {
|
||||
const uint16_t h = h16(v);
|
||||
t.bytes.push_back((uint8_t)h);
|
||||
t.bytes.push_back((uint8_t)(h >> 8));
|
||||
};
|
||||
for (int64_t b = 0; b < rows * cols / 256; ++b) {
|
||||
const float d = 0.0625f * (float)(1 + (b + seed) % 7);
|
||||
if (type == 12) {
|
||||
push16(d);
|
||||
push16(d / 2);
|
||||
fill(12 + 128);
|
||||
} else {
|
||||
fill(128 + 64 + 16);
|
||||
push16(d);
|
||||
}
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
/* Every plane of `w` through ckpt_plane_rows, and the weight those planes decode to. */
|
||||
void read_planes(const CkptWeight& w, std::vector<std::vector<uint8_t>>* planes,
|
||||
std::vector<float>* values) {
|
||||
std::string why;
|
||||
planes->assign((size_t)w.enc.n_planes, {});
|
||||
const void* data[RAD_ENC_MAX_PLANES] = { nullptr };
|
||||
for (int k = 0; k < w.enc.n_planes; ++k) {
|
||||
int64_t pr = 0, pc = 0;
|
||||
rad_enc_plane_dims(&w.enc.plane[k], w.rows, w.cols, &pr, &pc);
|
||||
(*planes)[(size_t)k].resize((size_t)(pr * rad_enc_row_bytes(w.enc.plane[k].dtype, pc)));
|
||||
CHECK_EQ(ckpt_plane_rows(w, k, 0, pr, (*planes)[(size_t)k].data(), &why), (int)RAD_OK);
|
||||
data[k] = (*planes)[(size_t)k].data();
|
||||
}
|
||||
EncodedView v;
|
||||
enc_view(w.enc, w.rows, w.cols, data, &v);
|
||||
values->assign((size_t)(w.rows * w.cols), 0.0f);
|
||||
CHECK_EQ(enc_decode_rows(v, 0, w.rows, values->data(), &why), (int)RAD_OK);
|
||||
}
|
||||
|
||||
/* The planes of `w` decode to exactly what the block definition gives (ckpt_rows_f32). */
|
||||
void check_planes_decode_by_definition(const CkptWeight& w) {
|
||||
std::vector<std::vector<uint8_t>> planes;
|
||||
std::vector<float> got, want((size_t)(w.rows * w.cols));
|
||||
std::string why;
|
||||
read_planes(w, &planes, &got);
|
||||
REQUIRE_EQ(ckpt_rows_f32(w, 0, w.rows, want.data(), &why), (int)RAD_OK);
|
||||
int bad = 0, nonzero = 0;
|
||||
for (size_t i = 0; i < want.size(); ++i) {
|
||||
bad += !(got[i] == want[i]);
|
||||
nonzero += want[i] != 0.0f;
|
||||
}
|
||||
if (bad) std::fprintf(stderr, " %d of %zu value(s) differ\n", bad, want.size());
|
||||
CHECK_EQ(bad, 0);
|
||||
CHECK(nonzero > (int)want.size() / 2);
|
||||
}
|
||||
|
||||
} /* namespace */
|
||||
|
||||
TEST(a_gguf_q8_0_q4_k_or_q6_k_tensor_is_imported_as_its_planes) {
|
||||
const std::string path = fresh_dir() + "/m.gguf";
|
||||
std::vector<float> w8;
|
||||
const GTensor q8 = legacy_blocks("t.q8_0", 8, &w8);
|
||||
const GTensor g = k_blocks("g", 12, 2, 512, 1), u = k_blocks("u", 12, 3, 512, 2);
|
||||
const GTensor s = k_blocks("s", 12, 2, 256, 3), k6 = k_blocks("k6", 14, 2, 256, 4);
|
||||
const GTensor q5{ "t.q5_k", 13, { 256, 1 }, std::vector<uint8_t>(176, 0) };
|
||||
write_gguf(path, llama_kvs(15), { q8, g, u, s, k6, q5 });
|
||||
Checkpoint ck;
|
||||
REQUIRE_EQ(ck.open(path), RAD_OK);
|
||||
Program prog;
|
||||
prog.name_map.push_back(map("t.q8_0", RAD_MAP_COPY, { "t.q8_0" }));
|
||||
prog.name_map.push_back(map("gu", RAD_MAP_CONCAT, { "g", "u" }));
|
||||
prog.name_map.push_back(map("s", RAD_MAP_COPY, { "s" }));
|
||||
prog.name_map.push_back(map("k6", RAD_MAP_COPY, { "k6" }));
|
||||
prog.name_map.push_back(map("mix", RAD_MAP_CONCAT, { "s", "k6" }));
|
||||
prog.name_map.push_back(map("across", RAD_MAP_CONCAT, { "g", "s" }, {}, 1));
|
||||
prog.name_map.push_back(map("t.q5_k", RAD_MAP_COPY, { "t.q5_k" }));
|
||||
std::string why;
|
||||
|
||||
/* Q8_0: the codes plane is each block's quants and the scale plane its d, byte for byte. */
|
||||
{
|
||||
CkptWeight w;
|
||||
REQUIRE_EQ(ckpt_resolve(ck, prog, "t.q8_0", false, &w, &why), RAD_OK);
|
||||
CHECK(w.imported && w.ggml_blocks);
|
||||
CHECK(!w.trivial);
|
||||
CHECK(has(w.why, "GGUF"));
|
||||
REQUIRE(rad_enc_valid(&w.enc));
|
||||
REQUIRE_EQ(w.enc.n_planes, 2);
|
||||
std::vector<std::vector<uint8_t>> planes;
|
||||
std::vector<float> f;
|
||||
read_planes(w, &planes, &f);
|
||||
REQUIRE_EQ(planes[0].size(), (size_t)(8 * 32));
|
||||
REQUIRE_EQ(planes[1].size(), (size_t)(8 * 2));
|
||||
int bad = 0;
|
||||
for (int b = 0; b < 8; ++b) {
|
||||
bad += std::memcmp(planes[0].data() + 32 * b, q8.bytes.data() + 34 * b + 2, 32) != 0;
|
||||
bad += std::memcmp(planes[1].data() + 2 * b, q8.bytes.data() + 34 * b, 2) != 0;
|
||||
}
|
||||
CHECK_EQ(bad, 0);
|
||||
int differ = 0;
|
||||
for (size_t i = 0; i < w8.size(); ++i) differ += f[i] != w8[i];
|
||||
CHECK_EQ(differ, 0);
|
||||
}
|
||||
|
||||
/* Q4_K, gate and up joined along rows: the planes decode to the block definition, and a
|
||||
* range that starts in the first piece and ends in the second is the same bytes. */
|
||||
{
|
||||
CkptWeight w;
|
||||
REQUIRE_EQ(ckpt_resolve(ck, prog, "gu", false, &w, &why), RAD_OK);
|
||||
CHECK(w.imported && w.ggml_blocks);
|
||||
CHECK(!w.trivial);
|
||||
CHECK_EQ(w.rows, (int64_t)5);
|
||||
CHECK_EQ(w.cols, (int64_t)512);
|
||||
REQUIRE(rad_enc_valid(&w.enc));
|
||||
REQUIRE_EQ(w.enc.n_planes, 5);
|
||||
check_planes_decode_by_definition(w);
|
||||
std::vector<std::vector<uint8_t>> planes;
|
||||
std::vector<float> f;
|
||||
read_planes(w, &planes, &f);
|
||||
for (int k = 0; k < w.enc.n_planes; ++k) {
|
||||
int64_t pr = 0, pc = 0;
|
||||
rad_enc_plane_dims(&w.enc.plane[k], w.rows, w.cols, &pr, &pc);
|
||||
const int64_t rb = rad_enc_row_bytes(w.enc.plane[k].dtype, pc);
|
||||
std::vector<uint8_t> part((size_t)(3 * rb));
|
||||
REQUIRE_EQ(ckpt_plane_rows(w, k, 1, 3, part.data(), &why), RAD_OK);
|
||||
CHECK_EQ(std::memcmp(part.data(), planes[(size_t)k].data() + rb, part.size()), 0);
|
||||
}
|
||||
}
|
||||
|
||||
/* A row of one block ends its 6-bit planes mid-word. */
|
||||
{
|
||||
CkptWeight w;
|
||||
REQUIRE_EQ(ckpt_resolve(ck, prog, "s", false, &w, &why), RAD_OK);
|
||||
CHECK(w.imported && w.ggml_blocks);
|
||||
check_planes_decode_by_definition(w);
|
||||
}
|
||||
|
||||
/* Q6_K. */
|
||||
{
|
||||
CkptWeight w;
|
||||
REQUIRE_EQ(ckpt_resolve(ck, prog, "k6", false, &w, &why), RAD_OK);
|
||||
CHECK(w.imported && w.ggml_blocks);
|
||||
CHECK(!w.trivial);
|
||||
REQUIRE(rad_enc_valid(&w.enc));
|
||||
REQUIRE_EQ(w.enc.n_planes, 3);
|
||||
check_planes_decode_by_definition(w);
|
||||
}
|
||||
|
||||
/* What it does not import keeps the GGUF reason. */
|
||||
{
|
||||
CkptWeight w;
|
||||
REQUIRE_EQ(ckpt_resolve(ck, prog, "mix", false, &w, &why), RAD_OK);
|
||||
CHECK(!w.imported && !w.ggml_blocks && !w.trivial);
|
||||
CHECK(has(w.why, "different block types"));
|
||||
REQUIRE_EQ(ckpt_resolve(ck, prog, "across", false, &w, &why), RAD_OK);
|
||||
CHECK(!w.imported && !w.ggml_blocks && !w.trivial);
|
||||
CHECK(has(w.why, "joined along a column"));
|
||||
REQUIRE_EQ(ckpt_resolve(ck, prog, "t.q5_k", false, &w, &why), RAD_OK);
|
||||
CHECK(!w.imported && !w.ggml_blocks && !w.trivial);
|
||||
CHECK(has(w.why, "GGUF"));
|
||||
}
|
||||
}
|
||||
|
||||
/* llama.cpp stacks an MoE's experts in one rank-3 tensor of blocks, and an expert's gate|up is two
|
||||
* dim-0 slices joined along rows: their planes are those of the same blocks stored on their own. */
|
||||
TEST(a_slice_of_a_stacked_gguf_block_tensor_is_imported_as_its_planes) {
|
||||
const std::string path = fresh_dir() + "/m.gguf";
|
||||
const int64_t E = 4, N = 3, K = 512;
|
||||
GTensor gate = k_blocks("gate_exps", 12, E * N, K, 5);
|
||||
GTensor up = k_blocks("up_exps", 12, E * N, K, 6);
|
||||
gate.ne = up.ne = { (uint64_t)K, (uint64_t)N, (uint64_t)E };
|
||||
const size_t eb = gate.bytes.size() / E;
|
||||
GTensor own{ "gu2", 12, { (uint64_t)K, (uint64_t)(2 * N) }, {} };
|
||||
own.bytes.assign(gate.bytes.begin() + 2 * eb, gate.bytes.begin() + 3 * eb);
|
||||
own.bytes.insert(own.bytes.end(), up.bytes.begin() + 2 * eb, up.bytes.begin() + 3 * eb);
|
||||
write_gguf(path, llama_kvs(15), { gate, up, own });
|
||||
Checkpoint ck;
|
||||
REQUIRE_EQ(ck.open(path), RAD_OK);
|
||||
Program prog;
|
||||
prog.name_map.push_back(map("gu", RAD_MAP_CONCAT, { "gate_exps", "up_exps" }, { 2, 2 }));
|
||||
prog.name_map.push_back(map("gu2", RAD_MAP_COPY, { "gu2" }));
|
||||
std::string why;
|
||||
CkptWeight w, o;
|
||||
REQUIRE_EQ(ckpt_resolve(ck, prog, "gu", false, &w, &why), RAD_OK);
|
||||
REQUIRE_EQ(ckpt_resolve(ck, prog, "gu2", false, &o, &why), RAD_OK);
|
||||
CHECK(w.imported && w.ggml_blocks);
|
||||
CHECK_EQ(w.rows, 2 * N);
|
||||
CHECK_EQ(w.cols, K);
|
||||
REQUIRE(rad_enc_equal(&w.enc, &o.enc));
|
||||
std::vector<std::vector<uint8_t>> got, want;
|
||||
std::vector<float> fg, fo;
|
||||
read_planes(w, &got, &fg);
|
||||
read_planes(o, &want, &fo);
|
||||
for (int k = 0; k < w.enc.n_planes; ++k) CHECK(got[(size_t)k] == want[(size_t)k]);
|
||||
}
|
||||
|
||||
TEST(hyv3_gguf_metadata_normalizes_architecture_and_config_fields) {
|
||||
const std::string path = fresh_dir() + "/hyv3.gguf";
|
||||
const std::vector<GKv> kvs = {
|
||||
|
||||
@@ -437,6 +437,7 @@ const std::map<std::string, std::vector<std::string>>& legal_values() {
|
||||
{ "--placement", { "all_vram" } }, { "--checkpoint-interval", { "256" } },
|
||||
{ "--prefill-span", { "2" } },
|
||||
{ "--checkpoint-slots", { "4" } }, { "--checkpoint-policy", { "tip-only" } },
|
||||
{ "--prefix-resume", { "nearest" } },
|
||||
{ "--num-speculative-tokens", { "2" } }, { "--draft-window", { "fixed" } }, { "--draft-short-from", { "4" } },
|
||||
{ "--draft-coupling", { "on" } },
|
||||
{ "--host", { "127.0.0.1" } }, { "--port", { "8001" } }, { "--api-key", { "k" } },
|
||||
@@ -466,6 +467,8 @@ const std::map<std::string, std::vector<std::string>>& legal_values() {
|
||||
{ "--video-max-frame-tokens", { "70" } }, { "--image-tokens", { "280" } },
|
||||
{ "--max-source-pixels", { "1000000" } },
|
||||
{ "--expert-stats", { "/s/experts.json" } },
|
||||
{ "--expert-profile", { "/p.json" } }, { "--expert-pin-top", { "0.2" } },
|
||||
{ "--draft-expert-placement", { "host" } },
|
||||
{ "--kld-record", { "/r", "--kld-corpus", "/c.jsonl" } }, { "--kld-ref", { "/r" } },
|
||||
{ "--kld-corpus", { "/c.jsonl", "--kld-record", "/r" } },
|
||||
{ "--kld-out", { "/o.json", "--kld-ref", "/r" } },
|
||||
@@ -863,6 +866,20 @@ TEST(expert_stats_is_off_until_it_names_a_file) {
|
||||
CHECK(parse_fresh({ "--expert-stats" }) < 0);
|
||||
}
|
||||
|
||||
/* A prefix hit resumes on the cold run's chunk grid unless the operator trades that for a shorter
|
||||
* re-prefill; any other word is refused. */
|
||||
TEST(prefix_resume_is_exact_unless_nearest_is_asked_for) {
|
||||
Config d;
|
||||
CHECK_EQ(parse({}, &d), RAD_OK);
|
||||
CHECK(d.prefix_exact);
|
||||
Config c;
|
||||
CHECK_EQ(parse({ "--prefix-resume", "nearest" }, &c), RAD_OK);
|
||||
CHECK(!c.prefix_exact);
|
||||
CHECK_EQ(parse({ "--prefix-resume", "exact" }, &c), RAD_OK);
|
||||
CHECK(c.prefix_exact);
|
||||
CHECK_EQ(parse({ "--prefix-resume", "deepest" }, &c), RAD_E_INVAL);
|
||||
}
|
||||
|
||||
/* --checkpoint-slots is auto by default, resolved by the engine once a snapshot's size is known;
|
||||
* a count is taken as given, 0 included, and the report shows which. */
|
||||
TEST(the_checkpoint_slots_are_auto_or_a_count) {
|
||||
|
||||
@@ -6,11 +6,13 @@
|
||||
* checkpoint holds them, so one conversion writes a quantised and a copied weight of every kind.
|
||||
*/
|
||||
#include "rad_test.h"
|
||||
#include "gguf_writer.h"
|
||||
#include "tiny_model.h"
|
||||
|
||||
#include "format/encoding.h"
|
||||
#include "format/radfile.h"
|
||||
#include "gen_config.h"
|
||||
#include "text/tokenizer.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
@@ -756,6 +758,49 @@ TEST(a_recipe_or_flag_that_cannot_be_honoured_is_refused_before_writing) {
|
||||
}
|
||||
}
|
||||
|
||||
/* A rule that declines a GGUF block tensor stops the run rather than keep the tensor's planes: the
|
||||
* tiny LLaMA as a GGUF with its first attn_norm in Q8_0, under an `rtn` rule, which declines a
|
||||
* rank-1 tensor. */
|
||||
TEST(a_rule_that_declines_a_gguf_block_tensor_is_an_error) {
|
||||
World& w = world();
|
||||
REQUIRE(w.ok);
|
||||
tiny::TempDir d("convert_gguf");
|
||||
const tiny::Llama s;
|
||||
const std::vector<ggufw::GKv> kvs = {
|
||||
{ "general.architecture", 8, 0, { "llama" } },
|
||||
{ "llama.block_count", 4, (double)s.layers, {} },
|
||||
{ "llama.embedding_length", 4, (double)s.hidden, {} },
|
||||
{ "llama.attention.head_count", 4, (double)s.heads, {} },
|
||||
{ "llama.attention.head_count_kv", 4, (double)s.kv_heads, {} },
|
||||
{ "llama.attention.key_length", 4, (double)s.head_dim, {} },
|
||||
{ "llama.feed_forward_length", 4, (double)s.ffn, {} },
|
||||
{ "llama.context_length", 4, (double)s.ctx, {} },
|
||||
{ "llama.vocab_size", 4, (double)s.vocab, {} },
|
||||
};
|
||||
std::vector<ggufw::GTensor> ts;
|
||||
for (const auto& [name, t] : w.src) {
|
||||
ggufw::GTensor g{ name, t.dtype == "F32" ? 0u : 30u, {}, t.bytes };
|
||||
g.ne.assign(t.shape.rbegin(), t.shape.rend());
|
||||
if (name == "model.layers.0.input_layernorm.weight") {
|
||||
g.type = 8;
|
||||
g.bytes.clear();
|
||||
for (uint64_t b = 0; b < g.ne[0] / 32; ++b) {
|
||||
g.bytes.insert(g.bytes.end(), { 0x00, 0x3C }); /* d = 1 in f16 */
|
||||
g.bytes.insert(g.bytes.end(), 32, 1);
|
||||
}
|
||||
}
|
||||
ts.push_back(std::move(g));
|
||||
}
|
||||
REQUIRE(ggufw::write_gguf(d / "llama.gguf", kvs, ts));
|
||||
std::string log;
|
||||
CHECK(convert(d / "llama.gguf",
|
||||
{ "-o", d / "g.rad", "--recipe", w.recipe, "--quant",
|
||||
"blk.0.attn_norm.weight=rtn:codes=i8,group=32,scale=bf16" },
|
||||
&log) != 0);
|
||||
CHECK(has(log, "(rtn) refuses it"));
|
||||
CHECK(!exists(d / "g.rad"));
|
||||
}
|
||||
|
||||
/* ================================================================== an int4 release */
|
||||
|
||||
namespace {
|
||||
@@ -923,4 +968,27 @@ TEST(an_fp8_kv_cache_declares) {
|
||||
CHECK(exists(d / "k.rad"));
|
||||
}
|
||||
|
||||
/* --chat-template bakes a template into the container's vocab section, for a release that ships
|
||||
* none (DeepSeek's). Without the flag the container carries what the checkpoint carried. A missing
|
||||
* file is refused, not silently skipped. */
|
||||
TEST(chat_template_flag_bakes_the_template) {
|
||||
World& w = world();
|
||||
REQUIRE(w.ok);
|
||||
tiny::TempDir d("convert_ct");
|
||||
const std::string tmpl = d / "chat_template.jinja";
|
||||
REQUIRE(tiny::write_text(tmpl, "{%- raw %}{{ messages }}{%- endraw %}\n\n"));
|
||||
std::string log;
|
||||
REQUIRE_EQ(convert(w.ckpt, { "-o", d / "with.rad", "--recipe", w.recipe,
|
||||
"--chat-template", tmpl }, &log), 0);
|
||||
RadFile f;
|
||||
REQUIRE_EQ(f.open((d / "with.rad").c_str()), RAD_OK);
|
||||
VocabBuild vb;
|
||||
REQUIRE_EQ(vocab_deserialize(f.base(), (uint64_t)f.size(), f.vocab().h, vb), RAD_OK);
|
||||
CHECK_EQ(vb.chat_template, std::string("{%- raw %}{{ messages }}{%- endraw %}"));
|
||||
|
||||
std::string bad;
|
||||
CHECK_EQ(convert(w.ckpt, { "-o", d / "bad.rad", "--recipe", w.recipe,
|
||||
"--chat-template", d / "absent.jinja" }, &bad), 1);
|
||||
}
|
||||
|
||||
RAD_TEST_MAIN()
|
||||
@@ -1433,6 +1433,45 @@ TEST(gbnf_a_length_bound_past_two_thousand_is_held_exactly) {
|
||||
}
|
||||
}
|
||||
|
||||
/* Bounded repetitions of one operand share one chain of links, so a schema's many length bounds
|
||||
* cost its longest once rather than their sum. 200 properties at `maxLength: 4000` were 200 chains,
|
||||
* past the compile budget (a tool schema like that is refused in full); shared, they compile, and
|
||||
* every bound, short or long, string or array, is still held exactly. */
|
||||
TEST(gbnf_bounds_over_one_operand_share_their_links) {
|
||||
auto bv = bpe_like(59, 1500);
|
||||
std::string props = R"("a":{"type":"string","maxLength":4000},"b":{"type":"string","maxLength":7},)"
|
||||
R"("c":{"type":"array","items":{"type":"string","maxLength":5},"maxItems":3})";
|
||||
for (int i = 0; i < 200; ++i)
|
||||
props += ",\"f" + std::to_string(i) + "\":{\"type\":\"string\",\"maxLength\":4000}";
|
||||
std::string gbnf, err;
|
||||
CHECK_OK(grammar_from_json_schema("{\"type\":\"object\",\"properties\":{" + props +
|
||||
"},\"required\":[\"a\",\"b\",\"c\"]}",
|
||||
"root", &gbnf, &err));
|
||||
std::unique_ptr<GbnfGrammar> g;
|
||||
CHECK_OK(GbnfGrammar::create(gbnf, "root", &bv->v, false, {}, {}, &g, &err));
|
||||
auto whole = [&](const std::string& text) {
|
||||
std::unique_ptr<GbnfGrammar> h;
|
||||
std::string e;
|
||||
if (GbnfGrammar::create(gbnf, "root", &bv->v, false, {}, {}, &h, &e) < 0) return false;
|
||||
return h->accept_str(text) >= 0 && h->complete();
|
||||
};
|
||||
auto doc = [](size_t a, size_t b, std::vector<size_t> c, size_t f7) {
|
||||
std::string s = "{\"a\":\"" + std::string(a, 'x') + "\",\"b\":\"" + std::string(b, 'y') +
|
||||
"\",\"c\":[";
|
||||
for (size_t i = 0; i < c.size(); ++i) s += (i ? ",\"" : "\"") + std::string(c[i], 'z') + "\"";
|
||||
s += "]";
|
||||
if (f7) s += ",\"f7\":\"" + std::string(f7, 'w') + "\"";
|
||||
return s + "}";
|
||||
};
|
||||
CHECK(whole(doc(4000, 7, { 5, 0, 5 }, 4000)));
|
||||
CHECK(whole(doc(0, 0, {}, 0)));
|
||||
CHECK(!whole(doc(4001, 7, { 5 }, 0)));
|
||||
CHECK(!whole(doc(10, 8, { 5 }, 0)));
|
||||
CHECK(!whole(doc(10, 7, { 6 }, 0)));
|
||||
CHECK(!whole(doc(10, 7, { 1, 1, 1, 1 }, 0)));
|
||||
CHECK(!whole(doc(10, 7, { 1 }, 4001)));
|
||||
}
|
||||
|
||||
/* Identical clauses across tools are one clause to the plan. A tool-calling template writes the
|
||||
* same undeclared-parameter clause, free-text value and closing tags as separate rules per tool;
|
||||
* the plan hash-conses rules by body, so its size and the compile's vocabulary walks do not grow
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/* gguf_writer.h -- GGUF v3 files written by tests: header keys and tensors, the tensors' bytes as
|
||||
* the caller built them. */
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace ggufw {
|
||||
|
||||
struct GKv {
|
||||
std::string key;
|
||||
uint32_t type; /* 4 u32, 6 f32, 8 string, 9 array of strings */
|
||||
double num = 0;
|
||||
std::vector<std::string> strs;
|
||||
};
|
||||
struct GTensor {
|
||||
std::string name;
|
||||
uint32_t type;
|
||||
std::vector<uint64_t> ne; /* fastest dimension first, as GGUF stores it */
|
||||
std::vector<uint8_t> bytes;
|
||||
};
|
||||
|
||||
inline void put_bytes(std::string* b, const void* p, size_t n) { b->append((const char*)p, n); }
|
||||
inline void put_str(std::string* b, const std::string& s) {
|
||||
const uint64_t n = s.size();
|
||||
put_bytes(b, &n, 8);
|
||||
b->append(s);
|
||||
}
|
||||
|
||||
/* A GGUF v3 file of `kvs` and `ts`, every tensor at a 32-byte aligned offset. */
|
||||
inline bool write_gguf(const std::string& path, const std::vector<GKv>& kvs,
|
||||
const std::vector<GTensor>& ts) {
|
||||
std::string b = "GGUF";
|
||||
const uint32_t ver = 3;
|
||||
const uint64_t nt = ts.size(), nk = kvs.size();
|
||||
put_bytes(&b, &ver, 4);
|
||||
put_bytes(&b, &nt, 8);
|
||||
put_bytes(&b, &nk, 8);
|
||||
for (const GKv& kv : kvs) {
|
||||
put_str(&b, kv.key);
|
||||
put_bytes(&b, &kv.type, 4);
|
||||
if (kv.type == 4) { const uint32_t v = (uint32_t)kv.num; put_bytes(&b, &v, 4); }
|
||||
else if (kv.type == 6) { const float v = (float)kv.num; put_bytes(&b, &v, 4); }
|
||||
else if (kv.type == 8) put_str(&b, kv.strs.at(0));
|
||||
else {
|
||||
const uint32_t et = 8;
|
||||
const uint64_t n = kv.strs.size();
|
||||
put_bytes(&b, &et, 4);
|
||||
put_bytes(&b, &n, 8);
|
||||
for (const std::string& s : kv.strs) put_str(&b, s);
|
||||
}
|
||||
}
|
||||
uint64_t off = 0;
|
||||
for (const GTensor& t : ts) {
|
||||
put_str(&b, t.name);
|
||||
const uint32_t nd = (uint32_t)t.ne.size();
|
||||
put_bytes(&b, &nd, 4);
|
||||
for (uint64_t d : t.ne) put_bytes(&b, &d, 8);
|
||||
put_bytes(&b, &t.type, 4);
|
||||
put_bytes(&b, &off, 8);
|
||||
off += (t.bytes.size() + 31) / 32 * 32;
|
||||
}
|
||||
while (b.size() % 32) b.push_back('\0');
|
||||
for (const GTensor& t : ts) {
|
||||
b.append((const char*)t.bytes.data(), t.bytes.size());
|
||||
while (b.size() % 32) b.push_back('\0');
|
||||
}
|
||||
FILE* f = std::fopen(path.c_str(), "wb");
|
||||
if (!f) return false;
|
||||
const bool ok = std::fwrite(b.data(), 1, b.size(), f) == b.size();
|
||||
return std::fclose(f) == 0 && ok;
|
||||
}
|
||||
|
||||
} /* namespace ggufw */
|
||||
Executable
+49
@@ -0,0 +1,49 @@
|
||||
#!/bin/sh
|
||||
# kernel_report_check.sh -- the checked-in kernel report is internally consistent.
|
||||
#
|
||||
# docs/KERNELS.md is generated by `rad-kbench --report` and reviewed by hand. A hand-merged
|
||||
# regeneration can carry a per-library "N row(s) not reached" header from one run and the table
|
||||
# below it from another: at v1.13.0 the libr4d header says 239 while its table lists 243 rows
|
||||
# (the four kv_store_streamed rows landed in 486c9331 without the count moving), so the section
|
||||
# total (378) and the headline "132 of 510 declared row(s) were reached" both read four rows
|
||||
# short of the tables. The generator cannot produce this from one run -- header and table come
|
||||
# from one vector -- so the report is checked here, and a partially regenerated file fails.
|
||||
#
|
||||
# A check that cannot fail is not a check (docs/DEVLOG-decode-floor.md).
|
||||
set -u
|
||||
REPORT=$1
|
||||
test -f "$REPORT" || { echo "kernel_report_check: no report at $REPORT"; exit 1; }
|
||||
# The counting is one python3 pass; a host without it skips, like ops_doc's skip codes.
|
||||
command -v python3 >/dev/null 2>&1 || { echo " SKIP python3 not present"; exit 77; }
|
||||
|
||||
python3 - "$REPORT" <<'PY'
|
||||
import re, sys
|
||||
lines = open(sys.argv[1]).read().split("\n")
|
||||
pat = re.compile(r"`lib\w+`: (\d+) row\(s\) not reached:")
|
||||
heads = [(i, m.group(1)) for i, l in enumerate(lines) if (m := pat.match(l))]
|
||||
bad = 0
|
||||
for j, (a, claimed) in enumerate(heads):
|
||||
# The library's table ends at the next library header or the next section header.
|
||||
b = len(lines)
|
||||
for i in range(a + 1, len(lines)):
|
||||
if pat.match(lines[i]) or lines[i].startswith("## "):
|
||||
b = i
|
||||
break
|
||||
rows = sum(1 for l in lines[a:b] if l.startswith("| `"))
|
||||
name = re.match(r"`(\w+)`", lines[a]).group(1)
|
||||
print(f" {name}: header {claimed}, table {rows}")
|
||||
if int(claimed) != rows:
|
||||
bad += 1
|
||||
text = "\n".join(lines)
|
||||
m = re.search(r"(\d+) of (\d+) declared row\(s\) were reached", text)
|
||||
if m:
|
||||
ran, declared = int(m.group(1)), int(m.group(2))
|
||||
missed = sum(int(x) for x in pat.findall(text))
|
||||
if ran + missed != declared:
|
||||
print(f" headline: {ran} reached + {missed} not reached != {declared} declared")
|
||||
bad += 1
|
||||
if bad:
|
||||
print(f"kernel_report_check: {bad} inconsistent count(s); regenerate the report from one run.")
|
||||
sys.exit(1)
|
||||
print("kernel_report_check: the report's counts agree.")
|
||||
PY
|
||||
+339
-17
@@ -30,6 +30,7 @@
|
||||
#include <cstring>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <numeric>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <unistd.h>
|
||||
@@ -1827,21 +1828,24 @@ TEST(kv_window_snapshot_rows_and_seed) {
|
||||
kv.free_sequence(2);
|
||||
}
|
||||
|
||||
/* A window is snapshotted only where a hit resumes from it: the trunk's window in a model without
|
||||
* linear state. With linear state a hit on a windowed trunk re-prefills, and a drafter's window is
|
||||
* recomputed by draft refill, so a window section there would be copied and never read. */
|
||||
/* A window is snapshotted only where a hit resumes from it: the trunk's window, with or without
|
||||
* linear state beside it. A drafter's window is recomputed by draft refill, so a window section
|
||||
* there would be copied and never read. */
|
||||
TEST(kv_window_snapshot_only_where_a_hit_resumes_from_it) {
|
||||
KVGroupInfo w = paged_group("swa", RAD_KV_WINDOW, 2, 16, { 6 }, 64);
|
||||
const Config cfg = small_config();
|
||||
{ /* beside linear state: the slot holds only the state */
|
||||
{ /* beside linear state: the slot holds the state, then the window. Without the window a
|
||||
* hit could not resume on such a model at all (the scheduler refuses a trunk hole). */
|
||||
std::vector<KVGroupInfo> g = hybrid_groups();
|
||||
g.push_back(w);
|
||||
Pools p;
|
||||
CHECK_OK(configure_pools(p, cfg));
|
||||
KVManager kv;
|
||||
CHECK_OK(kv.configure(g, cfg, p.kv()));
|
||||
CHECK(!kv.has_window_snapshot());
|
||||
CHECK_EQ(kv.checkpoint_bytes(), 16384ll);
|
||||
CHECK(kv.has_window_snapshot());
|
||||
const KVGroupPlan* wp = kv.plan(3);
|
||||
REQUIRE(wp && wp->win_snap);
|
||||
CHECK_EQ(kv.checkpoint_bytes(), 16384ll + wp->window_blocks * wp->bytes_per_block);
|
||||
}
|
||||
{ /* a drafter's own window over a full-attention trunk */
|
||||
std::vector<KVGroupInfo> g = hybrid_groups(/*with_linear=*/false);
|
||||
@@ -2421,6 +2425,222 @@ TEST(checkpoint_interval_must_be_a_block_multiple) {
|
||||
CHECK_EQ(f.pc.configure(f.cfg, &f.kv, f.cfg.checkpoint_interval), RAD_E_INVAL);
|
||||
}
|
||||
|
||||
/* ================================================================== mixed block sizes
|
||||
*
|
||||
* A model can keep KV at different strides: DeepSeek-V4's compressed attention stores one row per
|
||||
* r tokens (a block of r) beside groups at one row a token. The cache indexes every such group at
|
||||
* the lcm of their blocks, an entry holding lcm / B blocks of a B-token group, so a hit ends on a
|
||||
* block of each and adopt() takes every group. Leaving the finer groups out left the trunk a hole
|
||||
* the scheduler refuses every hit for.
|
||||
*/
|
||||
static KVGroupInfo gdn_group(std::vector<int32_t> layers) {
|
||||
KVGroupInfo k;
|
||||
k.name = "gdn";
|
||||
k.decl.kind = RAD_KV_LINEAR;
|
||||
k.decl.dtype = RAD_F32;
|
||||
k.decl.n_head_kv = 4;
|
||||
k.decl.state_dim[0] = 16;
|
||||
k.decl.state_dim[1] = 16;
|
||||
k.layers = std::move(layers);
|
||||
return k;
|
||||
}
|
||||
|
||||
/* Handles: 1 = the coarse group (`a`-token blocks), 2 = the fine one (`b`), 3 = linear state. */
|
||||
static std::vector<KVGroupInfo> mixed_groups(int64_t a, int64_t b, bool with_linear) {
|
||||
std::vector<KVGroupInfo> g;
|
||||
g.push_back(null_group());
|
||||
g.push_back(paged_group("coarse", RAD_KV_FULL, 2, a, { 0, 1 }));
|
||||
g.push_back(paged_group("fine", RAD_KV_FULL, 1, b, { 2 }));
|
||||
if (with_linear) g.push_back(gdn_group({ 3, 4 }));
|
||||
return g;
|
||||
}
|
||||
|
||||
static std::vector<int32_t> head(const std::vector<int32_t>& v, int64_t n) {
|
||||
return std::vector<int32_t>(v.begin(), v.begin() + std::min<int64_t>(n, (int64_t)v.size()));
|
||||
}
|
||||
|
||||
TEST(a_cache_over_mixed_block_sizes_indexes_every_group_at_their_lcm) {
|
||||
for (const auto& ab : { std::pair<int64_t, int64_t>{ 2, 1 }, { 2, 4 }, { 16, 2 } }) {
|
||||
const int64_t a = ab.first, b = ab.second, L = std::lcm(a, b);
|
||||
Fixture f;
|
||||
REQUIRE_EQ(f.build_groups(mixed_groups(a, b, false)), RAD_OK);
|
||||
REQUIRE(f.pc.enabled());
|
||||
CHECK_EQ(f.pc.block_size(), L);
|
||||
CHECK(f.pc.cached_groups() == (std::vector<int32_t>{ 1, 2 }));
|
||||
CHECK_EQ(f.pc.blocks_per_entry(0), L / a);
|
||||
CHECK_EQ(f.pc.blocks_per_entry(1), L / b);
|
||||
std::vector<int32_t> eg;
|
||||
for (int64_t k = 0; k < L / a; ++k) eg.push_back(1);
|
||||
for (int64_t k = 0; k < L / b; ++k) eg.push_back(2);
|
||||
CHECK(f.pc.entry_groups() == eg);
|
||||
/* Named once in the report, and nothing left out. */
|
||||
CHECK(f.pc.report().find("not cached") == std::string::npos);
|
||||
CHECK(f.pc.report().find("blocks an entry") != std::string::npos);
|
||||
const int64_t free1 = f.kv.free_blocks(1), free2 = f.kv.free_blocks(2);
|
||||
|
||||
/* 101 tokens publish their whole entries: 96 or 100 of them. */
|
||||
const auto p = tok_run(300, 101);
|
||||
const int64_t whole = 101 / L * L;
|
||||
publish(f, 1, p, 101);
|
||||
CHECK_EQ(f.pc.size(), whole / L);
|
||||
const std::vector<int32_t> t1 = f.kv.block_table(1, 1), t2 = f.kv.block_table(1, 2);
|
||||
for (int64_t k = 0; k < whole / a; ++k) CHECK_EQ(f.kv.block_refcount(1, t1[(size_t)k]), 2);
|
||||
for (int64_t k = 0; k < whole / b; ++k) CHECK_EQ(f.kv.block_refcount(2, t2[(size_t)k]), 2);
|
||||
/* The partial block past the last entry is the sequence's alone. */
|
||||
if ((int64_t)t2.size() > whole / b) CHECK_EQ(f.kv.block_refcount(2, t2[(size_t)(whole / b)]), 1);
|
||||
|
||||
/* A longer prompt hits every published entry, with each group's own blocks. */
|
||||
auto longer = p;
|
||||
for (int i = 0; i < 40; ++i) longer.push_back(900 + i);
|
||||
std::vector<std::vector<int32_t>> got;
|
||||
CHECK_EQ(f.pc.lookup(longer, {}, &got).n_attn_tokens, (int32_t)whole);
|
||||
REQUIRE_EQ(got.size(), 2u);
|
||||
CHECK(got[0] == head(t1, whole / a));
|
||||
CHECK(got[1] == head(t2, whole / b));
|
||||
/* A full hit backs off one entry, and a divergence ends the hit on the entry below it. */
|
||||
CHECK_EQ(f.pc.lookup(head(p, whole), {}).n_attn_tokens, (int32_t)(whole - L));
|
||||
auto edited = p;
|
||||
edited[37] += 5000;
|
||||
CHECK_EQ(f.pc.lookup(edited, {}).n_attn_tokens, (int32_t)(37 / L * L));
|
||||
|
||||
/* The hit adopts in every group, and the blocks are shared, not copied. */
|
||||
CHECK_OK(f.kv.add_sequence(2));
|
||||
for (size_t i = 0; i < 2; ++i)
|
||||
CHECK_OK(f.kv.adopt(2, f.pc.cached_groups()[i], got[i], whole));
|
||||
CHECK_OK(f.kv.ensure(2, (int64_t)longer.size()));
|
||||
CHECK_EQ(f.kv.block_refcount(2, t2[0]), 3);
|
||||
CHECK(head(f.kv.block_table(2, 2), whole / b) == head(t2, whole / b));
|
||||
f.kv.free_sequence(1);
|
||||
f.kv.free_sequence(2);
|
||||
CHECK_EQ(f.kv.block_refcount(1, t1[0]), 1);
|
||||
CHECK_EQ(f.pc.unshared_tokens(), whole);
|
||||
|
||||
/* Eviction takes the deepest entry: its blocks in both groups go back together. */
|
||||
const int64_t e1 = f.kv.free_blocks(1), e2 = f.kv.free_blocks(2);
|
||||
CHECK_EQ(f.pc.evict_lru(1), 1ll);
|
||||
CHECK_EQ(f.kv.free_blocks(1), e1 + L / a);
|
||||
CHECK_EQ(f.kv.free_blocks(2), e2 + L / b);
|
||||
CHECK_EQ(f.pc.lookup(longer, {}).n_attn_tokens, (int32_t)(whole - L));
|
||||
CHECK_EQ(f.pc.unshared_tokens(), whole - L);
|
||||
/* trim() counts entries too. */
|
||||
CHECK_EQ(f.pc.trim(2), 2ll);
|
||||
CHECK_EQ(f.kv.free_blocks(1), e1 + 3 * (L / a));
|
||||
CHECK_EQ(f.kv.free_blocks(2), e2 + 3 * (L / b));
|
||||
/* A restore's room is in entries: the group shortest of whole entries decides. */
|
||||
const int64_t room = std::min((f.kv.total_blocks(1) - f.kv.held_blocks(1)) / (L / a),
|
||||
(f.kv.total_blocks(2) - f.kv.held_blocks(2)) / (L / b));
|
||||
CHECK_EQ(f.pc.restore_room(), room);
|
||||
f.pc.clear();
|
||||
CHECK_EQ(f.kv.free_blocks(1), free1);
|
||||
CHECK_EQ(f.kv.free_blocks(2), free2);
|
||||
}
|
||||
}
|
||||
|
||||
/* A publish whose tables are short of an entry's blocks in one group is refused whole, and one
|
||||
* that cannot take a reference in a later group gives back what it took in the earlier ones. */
|
||||
TEST(a_mixed_publish_short_of_a_groups_blocks_is_refused_and_takes_nothing) {
|
||||
Fixture f;
|
||||
REQUIRE_EQ(f.build_groups(mixed_groups(2, 1, false)), RAD_OK);
|
||||
const auto p = tok_run(40, 32);
|
||||
CHECK_OK(f.kv.add_sequence(1));
|
||||
CHECK_OK(f.kv.ensure(1, 32));
|
||||
std::vector<std::vector<int32_t>> bt = { f.kv.block_table(1, 1), f.kv.block_table(1, 2) };
|
||||
std::vector<std::vector<int32_t>> shorter = bt;
|
||||
shorter[1].resize(31); /* 16 entries need 32 one-token blocks */
|
||||
CHECK_EQ(f.pc.insert(1, p, {}, shorter, 32), RAD_E_INVAL);
|
||||
CHECK_EQ(f.pc.size(), 0ll);
|
||||
/* A free block in the fine group cannot be retained: the entry is unwound. */
|
||||
std::vector<std::vector<int32_t>> bad = bt;
|
||||
int32_t loose = -1;
|
||||
CHECK_OK(f.kv.reserve_block(2, &loose));
|
||||
f.kv.release_block(2, loose); /* back on the free list */
|
||||
bad[1][1] = loose;
|
||||
CHECK_EQ(f.pc.insert(1, p, {}, bad, 32), RAD_E_STATE);
|
||||
CHECK_EQ(f.kv.block_refcount(1, bt[0][0]), 1);
|
||||
CHECK_EQ(f.kv.block_refcount(2, bt[1][0]), 1);
|
||||
CHECK_OK(f.pc.insert(1, p, {}, bt, 32));
|
||||
CHECK_EQ(f.kv.block_refcount(2, bt[1][0]), 2);
|
||||
}
|
||||
|
||||
/* Checkpoints are keyed on the entry grid: the chain at the lcm of the blocks, as the scheduler's
|
||||
* binding builds it (PCBinding::prefix_hash). A position off the grid has no key. */
|
||||
TEST(a_checkpoint_over_mixed_blocks_sits_on_the_entry_grid) {
|
||||
for (const auto& ab : { std::pair<int64_t, int64_t>{ 2, 1 }, { 2, 4 } }) {
|
||||
const int64_t L = std::lcm(ab.first, ab.second);
|
||||
Fixture f;
|
||||
f.cfg.checkpoint_slots = 4;
|
||||
REQUIRE_EQ(f.build_groups(mixed_groups(ab.first, ab.second, true)), RAD_OK);
|
||||
CHECK_EQ(f.pc.checkpoint_interval(), 64ll);
|
||||
const auto prompt = tok_run(7000, 202);
|
||||
publish(f, 1, prompt, 202);
|
||||
const std::vector<BlockHash> hs = chain_of(prompt, (int)L);
|
||||
const int64_t tail = 198 / L * L;
|
||||
for (int64_t pos : { (int64_t)64, tail }) {
|
||||
int32_t slot = -1;
|
||||
CHECK_OK(f.pc.reserve_checkpoint(1, pos, hs[(size_t)(pos / L - 1)], &slot));
|
||||
f.pc.commit_checkpoint(hs[(size_t)(pos / L - 1)]);
|
||||
}
|
||||
auto longer = prompt;
|
||||
for (int i = 0; i < 30; ++i) longer.push_back(80000 + i);
|
||||
CacheHit h = f.pc.lookup(longer, {});
|
||||
CHECK_EQ(h.n_attn_tokens, (int32_t)(202 / L * L));
|
||||
CHECK_EQ(h.n_linear_tokens, (int32_t)tail);
|
||||
CHECK(h.checkpoint_slot >= 0);
|
||||
/* Diverging below the tail resumes at the interval snapshot. */
|
||||
auto edited = prompt;
|
||||
edited[150] += 9;
|
||||
CHECK_EQ(f.pc.lookup(edited, {}).n_linear_tokens, 64);
|
||||
/* Off the grid: refused. */
|
||||
int32_t slot = -1;
|
||||
CHECK_EQ(f.pc.reserve_checkpoint(1, L + 1, hs[0], &slot), RAD_E_INVAL);
|
||||
|
||||
/* The scheduler's binding keys a snapshot on the same chain. */
|
||||
PCBinding<PrefixCache> bind(&f.pc);
|
||||
Request r;
|
||||
r.id = 5;
|
||||
r.prompt = longer;
|
||||
CHECK_OK(bind.reserve_checkpoint(r, 128, &slot));
|
||||
bind.commit_checkpoint(r, 128);
|
||||
auto at128 = prompt;
|
||||
for (size_t k = 130; k < at128.size(); ++k) at128[k] += 7;
|
||||
CHECK_EQ(f.pc.lookup(at128, {}).n_linear_tokens, 128);
|
||||
}
|
||||
}
|
||||
|
||||
/* The interval must be a multiple of an entry; the chunk quantum, which the engine rounds it to,
|
||||
* is a multiple of every paged group's block and so of the lcm. */
|
||||
TEST(a_mixed_cache_refuses_an_interval_off_its_entry_grid) {
|
||||
Fixture f;
|
||||
f.cfg.checkpoint_interval = 66; /* a multiple of 2, not of lcm(2, 4) */
|
||||
f.cfg.checkpoint_slots = 2;
|
||||
CHECK_OK(configure_pools(f.pools, f.cfg));
|
||||
CHECK_OK(f.kv.configure(mixed_groups(2, 4, true), f.cfg, f.pools.kv()));
|
||||
log_set_level(Log::Error);
|
||||
CHECK_EQ(f.pc.configure(f.cfg, &f.kv, f.cfg.checkpoint_interval), RAD_E_INVAL);
|
||||
log_set_level(Log::Info);
|
||||
CHECK_OK(f.pc.configure(f.cfg, &f.kv, 68));
|
||||
CHECK_EQ(f.pc.block_size(), 4ll);
|
||||
}
|
||||
|
||||
/* A model with linear state beside a trunk window and groups at two strides (DeepSeek-V4.1's
|
||||
* shape): the cache indexes both full groups, and the window rides in the checkpoint slot after
|
||||
* the state, so a hit resumes at a snapshot with nothing left out. */
|
||||
TEST(a_hybrid_with_a_window_and_mixed_blocks_leaves_only_the_window_to_the_slot) {
|
||||
Fixture f;
|
||||
f.cfg.checkpoint_slots = 4;
|
||||
std::vector<KVGroupInfo> g = mixed_groups(2, 1, true);
|
||||
g.push_back(paged_group("swa", RAD_KV_WINDOW, 2, 16, { 5 }, 64)); /* handle 4 */
|
||||
REQUIRE_EQ(f.build_groups(g), RAD_OK);
|
||||
CHECK(f.kv.has_window_snapshot());
|
||||
const KVGroupPlan* w = f.kv.plan(4);
|
||||
REQUIRE(w && w->win_snap);
|
||||
CHECK_EQ(f.kv.checkpoint_bytes(),
|
||||
f.kv.plan(3)->bytes_per_state + w->window_blocks * w->bytes_per_block);
|
||||
CHECK(f.pc.cached_groups() == (std::vector<int32_t>{ 1, 2 }));
|
||||
CHECK_EQ(f.pc.block_size(), 2ll);
|
||||
CHECK(f.pc.report().find("a checkpoint slot carries its window") != std::string::npos);
|
||||
}
|
||||
|
||||
/* ================================================================== retention */
|
||||
|
||||
TEST(geometric_backoff_keeps_the_tip_and_its_ancestors) {
|
||||
@@ -4994,24 +5214,26 @@ static void scribble(Fixture& f) {
|
||||
|
||||
/* The number of entries whose blocks in `now` hold, in every cached group and layer, exactly what
|
||||
* their blocks in `was` held before the move: this rank's own bytes, and for a replicated group
|
||||
* rank 0's, the one copy the slot holds. */
|
||||
* rank 0's, the one copy the slot holds. An entry is blocks_per_entry(gi) blocks of group gi. */
|
||||
static int64_t same_bytes(Fixture& f, int rank, const std::vector<std::vector<int32_t>>& was,
|
||||
const std::vector<std::vector<int32_t>>& now) {
|
||||
const std::vector<int32_t>& cg = f.pc.cached_groups();
|
||||
int64_t good = 0;
|
||||
for (size_t k = 0; k < was[0].size(); ++k) {
|
||||
const int64_t n = (int64_t)was[0].size() / f.pc.blocks_per_entry(0);
|
||||
for (int64_t e = 0; e < n; ++e) {
|
||||
bool ok = true;
|
||||
for (size_t gi = 0; gi < cg.size() && ok; ++gi) {
|
||||
const KVGroupPlan* p = f.kv.plan(cg[gi]);
|
||||
if (p->zero) continue;
|
||||
const int r = p->replicated ? 0 : rank;
|
||||
const int64_t frag = p->layer_bytes_per_block();
|
||||
for (int64_t l = 0; l < p->n_layers && ok; ++l) {
|
||||
const unsigned char* row =
|
||||
(const unsigned char*)p->base + l * p->layer_stride() + now[gi][k] * frag;
|
||||
for (int64_t i = 0; i < frag && ok; ++i)
|
||||
ok = row[i] == pat(r, cg[gi] * 16 + l, was[gi][k], i);
|
||||
}
|
||||
const int64_t frag = p->layer_bytes_per_block(), per = f.pc.blocks_per_entry(gi);
|
||||
for (int64_t k = e * per; k < (e + 1) * per && ok; ++k)
|
||||
for (int64_t l = 0; l < p->n_layers && ok; ++l) {
|
||||
const unsigned char* row = (const unsigned char*)p->base +
|
||||
l * p->layer_stride() + now[gi][(size_t)k] * frag;
|
||||
for (int64_t i = 0; i < frag && ok; ++i)
|
||||
ok = row[i] == pat(r, cg[gi] * 16 + l, was[gi][(size_t)k], i);
|
||||
}
|
||||
}
|
||||
good += ok;
|
||||
}
|
||||
@@ -5059,6 +5281,9 @@ struct TransferCase {
|
||||
bool replicated = false;
|
||||
bool alike = false;
|
||||
bool verify = false;
|
||||
/* The key cache at 8-token blocks: an entry is one attention block and two key blocks, and
|
||||
* the slot, the staging entry and the jobs all go by the entry's blocks. */
|
||||
bool mixed = false;
|
||||
};
|
||||
static void run_transfer(const TransferCase& tc) {
|
||||
const int world = tc.world;
|
||||
@@ -5085,11 +5310,14 @@ static void run_transfer(const TransferCase& tc) {
|
||||
* replicated attention group, which leaves that rank's own window empty. */
|
||||
if (zero_last && r == world - 1) groups[tc.replicated ? 2 : 1].zero = true;
|
||||
if (tc.replicated) groups[1].replicated = true;
|
||||
if (tc.mixed) groups[2].block_size = 8;
|
||||
REQUIRE_EQ(fx.back()->build_groups(groups), RAD_OK);
|
||||
}
|
||||
Fixture& f = *fx[0];
|
||||
const std::vector<int32_t>& cg = f.pc.cached_groups();
|
||||
REQUIRE_EQ(cg.size(), 2u);
|
||||
REQUIRE_EQ(f.pc.cached_groups().size(), 2u);
|
||||
/* One group per block an entry holds (PrefixCache::entry_groups), as bringup passes them. */
|
||||
const std::vector<int32_t>& cg = f.pc.entry_groups();
|
||||
REQUIRE_EQ(cg.size(), tc.mixed ? 3u : 2u);
|
||||
/* The slot as bringup lays it out: a replicated group once at the front, then each rank's own
|
||||
* window following the previous ones. Checked against the plain sums here. */
|
||||
std::vector<const KVManager*> kvs;
|
||||
@@ -5146,6 +5374,7 @@ static void run_transfer(const TransferCase& tc) {
|
||||
REQUIRE_EQ(f.pc.lookup(prompt, {}, &hit).n_attn_tokens, 320);
|
||||
const std::vector<std::vector<int32_t>> was = hit;
|
||||
CHECK(was[0][0] != was[1][0]);
|
||||
CHECK_EQ((int64_t)was[1].size(), tc.mixed ? 40ll : 20ll);
|
||||
for (int r = 0; r < world; ++r) fill(*fx[(size_t)r], r, tc.alike);
|
||||
|
||||
/* ---- out ---- */
|
||||
@@ -5233,6 +5462,24 @@ TEST(each_rank_restores_its_own_window_of_a_shared_slot) {
|
||||
run_transfer({ 2, /*fragment=*/false });
|
||||
run_transfer({ 2, /*fragment=*/true });
|
||||
}
|
||||
/* An entry over groups at different block sizes moves as its blocks: one attention block and two
|
||||
* key-cache blocks a slot, each through its own staging window, and every byte comes back. With a
|
||||
* replicated attention group beside a zero rank the windows still stay apart. */
|
||||
TEST(an_entry_over_mixed_block_sizes_moves_through_the_tiers_block_by_block) {
|
||||
TransferCase tc;
|
||||
tc.mixed = true;
|
||||
for (int world : { 1, 2 })
|
||||
for (bool fragment : { false, true }) {
|
||||
tc.world = world;
|
||||
tc.fragment = fragment;
|
||||
run_transfer(tc);
|
||||
}
|
||||
tc.world = 3;
|
||||
tc.fragment = false;
|
||||
tc.zero_last = true;
|
||||
tc.replicated = true;
|
||||
run_transfer(tc);
|
||||
}
|
||||
TEST(a_rank_with_a_zero_group_moves_only_its_own_groups) {
|
||||
run_transfer({ 3, /*fragment=*/false, /*zero_last=*/true });
|
||||
run_transfer({ 3, /*fragment=*/true, /*zero_last=*/true });
|
||||
@@ -6413,6 +6660,81 @@ TEST(a_checkpoint_carries_the_window_page_by_page_and_skips_the_padding) {
|
||||
rad_stream_destroy(st);
|
||||
}
|
||||
|
||||
/* Linear state, a conv window and a trunk window in one slot, as on DeepSeek-V4.1: the state
|
||||
* section first in plan order, then the window pages, and a restore puts each back where it
|
||||
* belongs -- the state into the resumed sequence's slots, the pages into its seeded blocks. */
|
||||
TEST(a_checkpoint_carries_linear_state_and_the_window_together) {
|
||||
if (!host_backend_or_skip("the hybrid checkpoint round trip")) return;
|
||||
Fixture f;
|
||||
f.cfg.checkpoint_slots = 4;
|
||||
std::vector<KVGroupInfo> g = hybrid_conv_groups();
|
||||
g.push_back(paged_group("swa", RAD_KV_WINDOW, 2, 16, { 7, 8 }, 64)); /* handle 4 */
|
||||
REQUIRE_EQ(f.build_groups(g), RAD_OK);
|
||||
const KVGroupPlan* w = f.kv.plan(4);
|
||||
REQUIRE(w && w->win_snap && f.kv.has_window_snapshot());
|
||||
const int64_t state = f.kv.plan(G_GDN)->bytes_per_state + f.kv.plan(G_CV)->bytes_per_state;
|
||||
const int64_t page = w->bytes_per_block, lb = w->layer_bytes_per_block();
|
||||
REQUIRE_EQ(f.kv.checkpoint_bytes(), state + w->window_blocks * page);
|
||||
auto block = [&](int64_t l, int32_t b) {
|
||||
return (unsigned char*)w->base + l * w->layer_stride() + b * lb;
|
||||
};
|
||||
for (int64_t l = 0; l < w->n_layers; ++l)
|
||||
for (int32_t b = 0; b < (int32_t)w->n_blocks; ++b)
|
||||
for (int64_t i = 0; i < lb; ++i) block(l, b)[i] = pat(7, l, b, i);
|
||||
|
||||
CHECK_OK(f.kv.add_sequence(1));
|
||||
CHECK_OK(f.kv.ensure(1, 400));
|
||||
const std::vector<int32_t> a = slots_of(f.kv, 1);
|
||||
fill_states(f.kv, 0);
|
||||
std::vector<int32_t> rows;
|
||||
REQUIRE(f.kv.window_rows(1, 400, &rows));
|
||||
int32_t ck = -1;
|
||||
REQUIRE_EQ(f.kv.alloc_checkpoint(&ck), RAD_OK);
|
||||
unsigned char* blob = (unsigned char*)f.kv.checkpoint_ptr(ck);
|
||||
std::memset(blob, 0x5A, (size_t)f.kv.checkpoint_bytes());
|
||||
RadStream st = nullptr;
|
||||
REQUIRE_EQ(rad_stream_create(&st, 0), RAD_OK);
|
||||
CHECK_OK(f.kv.checkpoint_save(a.data(), (int)a.size(), ck, st, &rows));
|
||||
CHECK_OK(rad_stream_sync(st));
|
||||
int64_t off = 0, wrong = 0;
|
||||
for (int32_t gi : { (int32_t)G_GDN, (int32_t)G_CV }) {
|
||||
const KVGroupPlan* p = f.kv.plan(gi);
|
||||
const int64_t sl = p->bytes_per_state / p->n_layers;
|
||||
for (int64_t l = 0; l < p->n_layers; ++l, off += sl)
|
||||
for (int64_t i = 0; i < sl; ++i) wrong += blob[off + i] != pat(0, gi * 16 + l, a[(size_t)gi], i);
|
||||
}
|
||||
CHECK_EQ(off, state);
|
||||
for (int64_t j = 0; j < w->window_blocks; ++j)
|
||||
for (int64_t l = 0; l < w->n_layers; ++l)
|
||||
for (int64_t i = 0; i < lb; ++i) {
|
||||
const unsigned char want = rows[(size_t)j] >= 0 ? pat(7, l, rows[(size_t)j], i) : 0x5A;
|
||||
wrong += blob[state + j * page + l * lb + i] != want;
|
||||
}
|
||||
CHECK_EQ(wrong, 0ll);
|
||||
|
||||
/* Back into a fresh sequence: its state slots take A's copy 0, its seeded window the pages. */
|
||||
CHECK_OK(f.kv.add_sequence(2));
|
||||
CHECK_OK(f.kv.seed_window(2, 400));
|
||||
CHECK_OK(f.kv.ensure(2, 432, 400)); /* the chunk after the hit, as admit_one */
|
||||
const std::vector<int32_t> b = slots_of(f.kv, 2);
|
||||
REQUIRE(b[(size_t)G_GDN] >= 0 && b[(size_t)G_CV] >= 0);
|
||||
std::vector<int32_t> rows2;
|
||||
REQUIRE(f.kv.window_rows(2, 400, &rows2));
|
||||
for (int64_t l = 0; l < w->n_layers; ++l)
|
||||
for (int32_t r : rows2) if (r >= 0) std::memset(block(l, r), 0xEE, (size_t)lb);
|
||||
CHECK_OK(f.kv.checkpoint_restore(b.data(), (int)b.size(), ck, st, &rows2));
|
||||
CHECK_OK(rad_stream_sync(st));
|
||||
CHECK_EQ(states_wrong(f.kv, 0, b, a), 0ll);
|
||||
wrong = 0;
|
||||
for (size_t j = 0; j < rows2.size(); ++j) {
|
||||
if (rows2[j] < 0) continue;
|
||||
for (int64_t l = 0; l < w->n_layers; ++l)
|
||||
for (int64_t i = 0; i < lb; ++i) wrong += block(l, rows2[j])[i] != pat(7, l, rows[j], i);
|
||||
}
|
||||
CHECK_EQ(wrong, 0ll);
|
||||
rad_stream_destroy(st);
|
||||
}
|
||||
|
||||
/* ================================================================== multimodal prefix keys
|
||||
*
|
||||
* Placeholder token ids are the same for every picture, so the content key of each media span
|
||||
|
||||
@@ -55,9 +55,11 @@ for d in "$S"/arch/*/ "$S"/plugin/*/; do
|
||||
[ -f "$d/CMakeLists.txt" ] && dirs="$dirs $(basename "$(dirname "$d")")/$(basename "$d")"
|
||||
done
|
||||
# The device libraries: built out of tree only with the tree's HIP compiler, and left out of every
|
||||
# comparison below without it.
|
||||
# comparison below without it. Each declares the family it serves, so a tree built for one family
|
||||
# produces one of them: libr3d returns without a target when RAD_GPU_TARGETS holds no gfx11, and the
|
||||
# checks below compare the two builds of the same list, not a fixed list.
|
||||
devlibs=""
|
||||
for d in libr4d; do
|
||||
for d in libr4d libr3d; do
|
||||
[ -f "$S/$d/CMakeLists.txt" ] && [ -f "$B/radiance_home/kernels/$d.so" ] && devlibs="$devlibs $d"
|
||||
done
|
||||
[ -n "$HIPC" ] && dirs="$dirs $devlibs"
|
||||
|
||||
@@ -3908,4 +3908,224 @@ TEST(a_mover_gives_back_every_event_and_device_byte) {
|
||||
CHECK(vram1 - vram0 <= 2 * MiB + 4096);
|
||||
}
|
||||
|
||||
/* ================================================================== the two placement flags
|
||||
*
|
||||
* --draft-expert-placement host pins a draft head's routed experts in the host pool before any
|
||||
* strategy runs, so they fit beside a trunk that already fills the card. --expert-pin-top keeps
|
||||
* the hottest fraction of the routed experts resident, so heat never demotes them. */
|
||||
|
||||
/* A trunk of `trunk` routed layers and a draft head of `head` layers past it, `n` experts each. */
|
||||
void build_drafted(Fixture& f, int trunk, int head, int n, int64_t each) {
|
||||
f.prog.meta.n_layers = (uint32_t)trunk;
|
||||
f.prog.drafter.kind = RAD_DRAFT_BLOCK;
|
||||
f.prog.drafter.depth = 5;
|
||||
build_moe_layers(f, trunk + head, n, each, 0);
|
||||
}
|
||||
|
||||
TEST(draft_experts_pin_to_the_host_pool) {
|
||||
Fixture f;
|
||||
build_drafted(f, 2, 1, 4, 1 * MiB);
|
||||
|
||||
Config c = base_config();
|
||||
c.placement = "expert_tiered";
|
||||
c.vram_weights_mib = 1024;
|
||||
c.host_pool_mib = 64;
|
||||
c.draft_expert_placement = "host";
|
||||
c.draft_expert_placement_given = true;
|
||||
|
||||
PlannerInput in{&f.prog, &c, 0, 1, nullptr, 0};
|
||||
Plan p;
|
||||
CHECK_OK(Planner(in).plan(&p));
|
||||
|
||||
int pinned = 0, trunk_vram = 0;
|
||||
for (const MoveUnit& mu : p.units) {
|
||||
if (mu.expert < 0) continue;
|
||||
if (mu.layer >= 2) {
|
||||
CHECK(mu.host_forced);
|
||||
CHECK(mu.tier == Tier::HostPinned);
|
||||
CHECK(mu.site == Site::DeviceZeroCopy);
|
||||
CHECK(!mu.movable);
|
||||
++pinned;
|
||||
} else if (mu.tier == Tier::VRAM) {
|
||||
++trunk_vram;
|
||||
}
|
||||
}
|
||||
/* The head's four experts, and only those, are forced into the pool. */
|
||||
CHECK_EQ(pinned, 4);
|
||||
CHECK(trunk_vram > 0);
|
||||
CHECK(p.draft_host_bytes >= 4 * MiB);
|
||||
CHECK(p.report(f.prog).find("drafter") != std::string::npos);
|
||||
|
||||
/* The footprint agrees: the head is the part of the plane the flag takes out. */
|
||||
WeightFootprint wf;
|
||||
weight_footprint(f.prog, &wf, TablePlacement::Vram, TablePlacement::Disk, false, false);
|
||||
CHECK(wf.draft_experts >= 4 * MiB);
|
||||
CHECK(wf.draft_experts < wf.experts);
|
||||
}
|
||||
|
||||
TEST(draft_placement_auto_leaves_the_head_to_the_strategy) {
|
||||
Fixture f;
|
||||
build_drafted(f, 2, 1, 4, 1 * MiB);
|
||||
|
||||
Config c = base_config();
|
||||
c.placement = "all_vram";
|
||||
c.vram_weights_mib = 1024;
|
||||
|
||||
PlannerInput in{&f.prog, &c, 0, 1, nullptr, 0};
|
||||
Plan p;
|
||||
CHECK_OK(Planner(in).plan(&p));
|
||||
for (const MoveUnit& mu : p.units)
|
||||
if (mu.expert >= 0 && mu.layer >= 2) CHECK(!mu.host_forced);
|
||||
CHECK_EQ(p.draft_host_bytes, (int64_t)0);
|
||||
}
|
||||
|
||||
TEST(draft_placement_host_refuses_a_model_with_no_drafter) {
|
||||
Fixture f;
|
||||
build_moe_layers(f, 2, 4, 1 * MiB, 0);
|
||||
|
||||
Config c = base_config();
|
||||
c.placement = "all_vram";
|
||||
c.vram_weights_mib = 1024;
|
||||
c.host_pool_mib = 64;
|
||||
c.draft_expert_placement = "host";
|
||||
c.draft_expert_placement_given = true;
|
||||
|
||||
PlannerInput in{&f.prog, &c, 0, 1, nullptr, 0};
|
||||
Plan p;
|
||||
CHECK_EQ(Planner(in).plan(&p), RAD_E_INVAL);
|
||||
}
|
||||
|
||||
TEST(draft_placement_host_refuses_when_the_pool_is_short) {
|
||||
Fixture f;
|
||||
build_drafted(f, 1, 1, 8, 4 * MiB);
|
||||
|
||||
Config c = base_config();
|
||||
c.placement = "expert_tiered";
|
||||
c.vram_weights_mib = 1024;
|
||||
c.host_pool_mib = 1;
|
||||
c.draft_expert_placement = "host";
|
||||
|
||||
PlannerInput in{&f.prog, &c, 0, 1, nullptr, 0};
|
||||
Plan p;
|
||||
CHECK_EQ(Planner(in).plan(&p), RAD_E_NOMEM);
|
||||
CHECK(p.report(f.prog).find("DID NOT FIT") != std::string::npos);
|
||||
}
|
||||
|
||||
TEST(expert_pin_top_keeps_the_hottest_resident) {
|
||||
Fixture f;
|
||||
build_moe_layers(f, 2, 8, 1 * MiB, 0);
|
||||
|
||||
/* Expert e of each layer takes share e + 1, so the hottest are the high indices. */
|
||||
std::vector<RadFileProfile> prof;
|
||||
for (int l = 0; l < 2; ++l)
|
||||
for (int e = 0; e < 8; ++e) {
|
||||
RadFileProfile r{};
|
||||
r.layer = l;
|
||||
r.expert = e;
|
||||
r.share = (float)(e + 1);
|
||||
prof.push_back(r);
|
||||
}
|
||||
|
||||
Config c = base_config();
|
||||
c.placement = "expert_tiered";
|
||||
c.vram_weights_mib = 1024;
|
||||
c.host_pool_mib = 1024;
|
||||
c.expert_pin_top = 0.25f;
|
||||
|
||||
PlannerInput in{&f.prog, &c, 0, 1, prof.data(), (int64_t)prof.size()};
|
||||
Plan p;
|
||||
CHECK_OK(Planner(in).plan(&p));
|
||||
|
||||
int pinned = 0, hot_pinned = 0;
|
||||
for (const MoveUnit& mu : p.units) {
|
||||
if (mu.expert < 0) continue;
|
||||
if (mu.pinned) {
|
||||
CHECK(mu.tier == Tier::VRAM);
|
||||
CHECK(!mu.movable);
|
||||
++pinned;
|
||||
if (mu.expert >= 6) ++hot_pinned;
|
||||
}
|
||||
}
|
||||
/* The top quarter of 16 experts: the two hottest of each layer. */
|
||||
CHECK_EQ(pinned, 4);
|
||||
CHECK_EQ(hot_pinned, 4);
|
||||
CHECK(p.report(f.prog).find("pinned hot") != std::string::npos);
|
||||
}
|
||||
|
||||
TEST(expert_pin_top_zero_pins_nothing) {
|
||||
Fixture f;
|
||||
build_moe_layers(f, 1, 4, 1 * MiB, 0);
|
||||
|
||||
Config c = base_config();
|
||||
c.placement = "all_vram";
|
||||
c.vram_weights_mib = 1024;
|
||||
c.expert_pin_top = 0.0f;
|
||||
|
||||
PlannerInput in{&f.prog, &c, 0, 1, nullptr, 0};
|
||||
Plan p;
|
||||
CHECK_OK(Planner(in).plan(&p));
|
||||
for (const MoveUnit& mu : p.units) CHECK(!mu.pinned);
|
||||
CHECK_EQ(p.pinned_units, (int64_t)0);
|
||||
}
|
||||
|
||||
TEST(a_pinned_resident_is_never_demoted) {
|
||||
Fixture f;
|
||||
build_moe_layers(f, 1, 4, 1 * MiB, 0);
|
||||
|
||||
std::vector<RadFileProfile> prof;
|
||||
for (int e = 0; e < 4; ++e) {
|
||||
RadFileProfile r{};
|
||||
r.layer = 0;
|
||||
r.expert = e;
|
||||
r.share = (float)(e + 1);
|
||||
prof.push_back(r);
|
||||
}
|
||||
Config c = base_config();
|
||||
c.placement = "expert_tiered";
|
||||
c.vram_weights_mib = 1024;
|
||||
c.host_pool_mib = 1024;
|
||||
c.expert_pin_top = 0.5f;
|
||||
|
||||
PlannerInput in{&f.prog, &c, 0, 1, prof.data(), (int64_t)prof.size()};
|
||||
Plan p;
|
||||
CHECK_OK(Planner(in).plan(&p));
|
||||
|
||||
/* Force one pinned unit and one cold unit onto the host, so the engine has a swap to make,
|
||||
* and heat the cold one far above the pinned one. */
|
||||
int32_t pinned_u = -1, cold_u = -1;
|
||||
for (size_t u = 0; u < p.units.size(); ++u) {
|
||||
if (p.units[u].pinned && pinned_u < 0) pinned_u = (int32_t)u;
|
||||
if (p.units[u].expert == 0) cold_u = (int32_t)u;
|
||||
}
|
||||
CHECK(pinned_u >= 0 && cold_u >= 0);
|
||||
p.units[(size_t)cold_u].tier = Tier::HostPinned;
|
||||
p.units[(size_t)cold_u].movable = true;
|
||||
|
||||
HeatEngine h;
|
||||
HeatParams hp;
|
||||
hp.warmup_dispatches = 0;
|
||||
CHECK_OK(h.init(p, hp));
|
||||
const int32_t ids[] = {0};
|
||||
const int32_t counts[] = {1000};
|
||||
for (int i = 0; i < 8; ++i) h.observe_ids(0, ids, counts, 1);
|
||||
Swap sw{};
|
||||
if (h.pick(&sw)) CHECK(sw.demote != pinned_u);
|
||||
}
|
||||
|
||||
TEST(the_draft_floor_charges_only_the_trunk) {
|
||||
WeightFootprint wf;
|
||||
wf.experts = 100;
|
||||
wf.draft_experts = 30;
|
||||
wf.expert_unit_max = 5;
|
||||
wf.expert_spare = 10;
|
||||
/* With the drafter hosted, the pool's room serves the trunk alone. */
|
||||
const int64_t hosted = expert_vram_floor_draft_hosted(wf, 80);
|
||||
const int64_t plain = expert_vram_floor(wf, 80);
|
||||
CHECK(hosted < plain);
|
||||
CHECK(hosted <= wf.experts - wf.draft_experts + wf.expert_spare);
|
||||
/* No drafter: the two floors agree. */
|
||||
wf.draft_experts = 0;
|
||||
CHECK_EQ(expert_vram_floor_draft_hosted(wf, 80), expert_vram_floor(wf, 80));
|
||||
}
|
||||
|
||||
RAD_TEST_MAIN()
|
||||
@@ -1126,6 +1126,28 @@ TEST(libr4d_resolves_every_band_of_glm_mla_split_by_rows) {
|
||||
}
|
||||
}
|
||||
|
||||
/* The dense integer gemm_nt_q kernels compile their group in, so their rows take no other: at
|
||||
* group 64 each dtype is a miss, at 128 it resolves. At M = 1 every skinny, tiled and prefill row
|
||||
* of these dtypes is a candidate. */
|
||||
TEST(libr4d_resolves_a_dense_integer_gemm_only_at_its_group) {
|
||||
const std::string so = libr4d();
|
||||
if (so.empty()) return;
|
||||
Registry r;
|
||||
CHECK(r.load_plugin(so, 0) >= 0);
|
||||
for (const char* dtype : { "w4a16", "w5a16", "w4a16_asym", "w4a8i8_asym", "w5a8i8", "w2a8",
|
||||
"w8a16", "w4a8", "w4a8_asym", "w8a8" }) {
|
||||
Geometry g;
|
||||
g.set_i("M", 1);
|
||||
g.set_i("N", 256);
|
||||
g.set_i("K", 256);
|
||||
g.set_s("dtype", dtype);
|
||||
g.set_i("group", 64);
|
||||
CHECK_EQ(picked(r.select("gemm_nt_q", g, RAD_DOMAIN_DEVICE)), "<none>");
|
||||
g.set_i("group", 128);
|
||||
CHECK(r.select("gemm_nt_q", g, RAD_DOMAIN_DEVICE) != nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================== constraints that are not intervals */
|
||||
namespace {
|
||||
std::string extra_dir() { return home() + "/testkernels/extra"; }
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
* The error bounds carry margin and catch a wrong plane layout, which decodes to noise.
|
||||
*/
|
||||
#include "quant_fixture.h"
|
||||
#include "format/ggml_planes.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
@@ -134,6 +135,24 @@ TEST(ggml_writes_each_type_as_its_affine_planes) {
|
||||
}
|
||||
}
|
||||
|
||||
/* The core cannot call libquant, so a GGUF is read through its own copy of the encodings
|
||||
* (core/format/ggml_planes.h); this holds every type of the copy to the quantiser's. */
|
||||
TEST(the_reader_names_the_planes_the_quantiser_writes) {
|
||||
NEED_LIBQUANT();
|
||||
const RadQuantizerInfo* q = quantizer("ggml");
|
||||
REQUIRE(q != nullptr);
|
||||
for (const ggml_planes::Type& t : ggml_planes::kTypes) {
|
||||
Opts o;
|
||||
o.s("type", gguf_dtype(t.ggml)->name);
|
||||
const RadQuantWeight qw = weight_of("w", 4, 512, nullptr);
|
||||
RadEncoding written, read;
|
||||
REQUIRE_EQ(q->encoding(o.data(), o.n(), &qw, &written), RAD_OK);
|
||||
REQUIRE(ggml_plane_encoding(t.ggml, &read));
|
||||
CHECK_EQ(enc_name(read), enc_name(written));
|
||||
CHECK(rad_enc_equal(&read, &written));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(every_type_decodes_within_its_bound) {
|
||||
NEED_LIBQUANT();
|
||||
const int64_t C = 1024;
|
||||
|
||||
@@ -883,6 +883,52 @@ TEST(a_kernel_refuses_an_encoding_it_does_not_read) {
|
||||
}
|
||||
}
|
||||
|
||||
/* The dense integer kernels compile their group in and read no `group` argument, so a hook that
|
||||
* accepted another one would hand the kernel planes it reads at 128. */
|
||||
TEST(a_dense_int_kernel_refuses_a_group_it_does_not_compute) {
|
||||
NEED_LIBQUANT();
|
||||
const int64_t N = 64, K = 256;
|
||||
const std::vector<float> w = draw(N * K, 28);
|
||||
auto rtn = [&](const char* codes, const char* zero, bool clamp, int64_t group) {
|
||||
Opts g;
|
||||
g.s("codes", codes).i("group", group).s("scale", "f16");
|
||||
if (zero) g.s("zero", zero);
|
||||
if (clamp) g.s("clamp", "sym");
|
||||
Quantised q = quantise(quantizer("rtn"), g, "x", N, K, w);
|
||||
CHECK_EQ(q.status, RAD_OK);
|
||||
return q;
|
||||
};
|
||||
auto lay = [&](RadLayoutFn f, const char* dtype, int64_t group, const Quantised& q) {
|
||||
Opts kp;
|
||||
kp.i("N", N).i("K", K).i("group", group).s("dtype", dtype);
|
||||
Selection s = select(q, N, K, { "codes" });
|
||||
RadLayout L{};
|
||||
return f(kp.data(), kp.n(), B, &q.enc, s.sel.data(), s.t.data(), (int)s.t.size(), &L);
|
||||
};
|
||||
const Quantised i4 = rtn("i4", nullptr, false, 64), u5 = rtn("u5", "u8", false, 64);
|
||||
const Quantised i8 = rtn("i8", nullptr, true, 64), u2 = rtn("u2", "u8", false, 64);
|
||||
CHECK_EQ(lay(r4d_rad_layout_w4, "w4a8", 64, i4), RAD_E_DTYPE);
|
||||
CHECK_EQ(lay(r4d_rad_layout_w5, "w5a16", 64, u5), RAD_E_DTYPE);
|
||||
CHECK_EQ(lay(r4d_rad_layout_w8a16, "w8a16", 64, i8), RAD_E_DTYPE);
|
||||
CHECK_EQ(lay(r4d_rad_layout_w2a8, "w2a8", 64, u2), RAD_E_DTYPE);
|
||||
|
||||
/* llama.cpp's Q8_0 is this encoding, an f16 scale per 32 i8 codes; the w8 kernels would read
|
||||
* it at 128. */
|
||||
const RadQuantizerInfo* ggml = quantizer("ggml");
|
||||
REQUIRE(ggml != nullptr);
|
||||
Opts o;
|
||||
o.s("type", "q8_0");
|
||||
const Quantised q8 = quantise(ggml, o, "x", N, K, w);
|
||||
REQUIRE_EQ(q8.status, RAD_OK);
|
||||
CHECK_EQ(lay(r4d_rad_layout_w8a16, "w8a16", 32, q8), RAD_E_DTYPE);
|
||||
|
||||
const Quantised i4_128 = rtn("i4", nullptr, false, 128), i8_128 = rtn("i8", nullptr, true, 128);
|
||||
const Quantised u2_128 = rtn("u2", "u8", false, 128);
|
||||
CHECK_EQ(lay(r4d_rad_layout_w4, "w4a8", 128, i4_128), RAD_OK);
|
||||
CHECK_EQ(lay(r4d_rad_layout_w8a16, "w8a16", 128, i8_128), RAD_OK);
|
||||
CHECK_EQ(lay(r4d_rad_layout_w2a8, "w2a8", 128, u2_128), RAD_OK);
|
||||
}
|
||||
|
||||
/* ParoQuant's rotation pairs are stored as they are, and refused at load when a stage is not a
|
||||
* pairing within its own group's 128 columns, which the rotate kernels would index out of bounds. */
|
||||
TEST(givens_pairs_are_stored_as_they_are_and_checked) {
|
||||
|
||||
@@ -166,6 +166,10 @@ struct Fixture {
|
||||
cfg.max_ctx = max_ctx;
|
||||
cfg.checkpoint_interval = 256;
|
||||
cfg.prefix_cache = true;
|
||||
/* The tests below were written for the nearest resume rule (a tail snapshot at the last
|
||||
* quantum boundary, a hit at any snapshot or block); the exact rule's own tests set
|
||||
* prefix_exact (--prefix-resume exact, the default). */
|
||||
cfg.prefix_exact = false;
|
||||
/* Config::n_spec defaults to -1 (`auto`), which engine_bringup resolves; this fixture
|
||||
* skips that, and DraftController::configure refuses a negative depth. Speculation tests
|
||||
* set their own depth. */
|
||||
@@ -795,6 +799,248 @@ TEST(a_span_needs_an_interval_grid) {
|
||||
CHECK_EQ((int64_t)f.sch.plan().e.size(), 2ll);
|
||||
}
|
||||
|
||||
/* ================================================================== exact resume */
|
||||
/* --prefix-resume exact (the default): a hit resumes only where an idle server's cold prefill of
|
||||
* the same prompt starts a chunk, and a prompt's tail snapshot is where its last chunk starts. A
|
||||
* kernel may round a row differently at another chunk length (spec §17: the split-K count is
|
||||
* chosen from M), so a hit is bit-identical to a cold run only when it recomputes the cold run's
|
||||
* own chunks. */
|
||||
|
||||
/* The chunk ends and checkpoints an idle server plans for an `L`-token prompt from `from`. */
|
||||
struct Cut { std::vector<int64_t> ends, ckpts; };
|
||||
static Cut cut_from(const Scheduler& s, int64_t from, int64_t L, int64_t budget) {
|
||||
Cut c;
|
||||
for (int64_t pos = from; pos < L;) {
|
||||
int64_t ck = -1;
|
||||
const int64_t n = s.plan_chunk(pos, L, budget, &ck);
|
||||
if (n <= 0) break;
|
||||
pos += n;
|
||||
c.ends.push_back(pos);
|
||||
if (ck > 0) c.ckpts.push_back(ck);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
static std::vector<int64_t> ends_after(const Cut& c, int64_t from) {
|
||||
std::vector<int64_t> v;
|
||||
for (int64_t e : c.ends) if (e > from) v.push_back(e);
|
||||
return v;
|
||||
}
|
||||
|
||||
/* Which geometry: 0 the GDN hybrid at interval 256 / budget 512 (chunks split at the interval);
|
||||
* 1 interval 1024 past a 512 budget; 2 a span of 2; 3 a sliding-window model with periodic
|
||||
* snapshots; 4 the same, tip-only (no interval split); 5 full attention alone (no snapshots). */
|
||||
static void exact_fixture(Fixture& f, int kind) {
|
||||
const bool window = kind == 3 || kind == 4, attn_only = kind == 5;
|
||||
f.build(4096, 64, 512, 8192, window, !attn_only);
|
||||
if (window) {
|
||||
/* As the window tests above: drop the GDN hybrid's linear and conv groups and its scan. */
|
||||
f.prog.kv_groups.erase(f.prog.kv_groups.begin() + 1, f.prog.kv_groups.begin() + 3);
|
||||
f.prog.ops.resize(1);
|
||||
f.prog.buffers.resize(1);
|
||||
f.kv.setup(f.prog.kv_groups, f.cfg.max_ctx, 4096, 64);
|
||||
f.pc.groups = { 0 };
|
||||
if (kind == 4) f.cfg.checkpoint_policy = "tip-only";
|
||||
}
|
||||
if (kind == 1) f.cfg.checkpoint_interval = 1024;
|
||||
if (kind == 2) f.cfg.prefill_span = 2;
|
||||
f.cfg.prefix_exact = true;
|
||||
}
|
||||
|
||||
TEST(exact_resume_grid_is_the_chunk_an_idle_prefill_cuts) {
|
||||
struct Want { int kind; int64_t interval, grid, origin; };
|
||||
for (const Want w : { Want{ 0, 256, 256, 0 }, Want{ 1, 1024, 512, 0 }, Want{ 2, 256, 512, 256 },
|
||||
Want{ 3, 256, 256, 0 }, Want{ 4, 256, 512, 0 }, Want{ 5, 0, 512, 0 } }) {
|
||||
Fixture f;
|
||||
exact_fixture(f, w.kind);
|
||||
REQUIRE_EQ(f.start(), RAD_OK);
|
||||
const ChunkGeometry& g = f.sch.geometry();
|
||||
CHECK(g.exact);
|
||||
CHECK_EQ(g.checkpoint_interval, w.interval);
|
||||
CHECK_EQ(g.grid, w.grid);
|
||||
CHECK_EQ(g.grid_origin, w.origin);
|
||||
}
|
||||
/* Nearest, or no prefix cache: no grid, every position its own floor. */
|
||||
for (int off = 0; off < 2; ++off) {
|
||||
Fixture f;
|
||||
exact_fixture(f, 0);
|
||||
if (off) f.cfg.prefix_cache = false; else f.cfg.prefix_exact = false;
|
||||
REQUIRE_EQ(f.start(), RAD_OK);
|
||||
CHECK(!f.sch.geometry().exact);
|
||||
CHECK_EQ(f.sch.geometry().grid_floor(300), 300);
|
||||
}
|
||||
Fixture f;
|
||||
exact_fixture(f, 2);
|
||||
REQUIRE_EQ(f.start(), RAD_OK);
|
||||
const ChunkGeometry& g = f.sch.geometry(); /* 0, 256, 768, 1280, ... */
|
||||
CHECK_EQ(g.grid_floor(255), 0);
|
||||
CHECK_EQ(g.grid_floor(256), 256);
|
||||
CHECK_EQ(g.grid_floor(767), 256);
|
||||
CHECK_EQ(g.grid_floor(1000), 768);
|
||||
CHECK(!g.on_grid(512));
|
||||
}
|
||||
|
||||
/* An interval past the budget that is not a multiple of the budget's chunk would put the chunk
|
||||
* after every checkpoint off the cold run's grid: exact rounds it up, with a warning that names
|
||||
* both ways out; nearest keeps it. */
|
||||
TEST(exact_rounds_an_interval_off_the_chunk_up_to_a_multiple_of_it) {
|
||||
for (int exact = 0; exact < 2; ++exact) {
|
||||
Fixture f;
|
||||
f.build(); /* quantum 64 */
|
||||
f.cfg.checkpoint_interval = 768; /* past the 512 budget, not a multiple of it */
|
||||
f.cfg.prefix_exact = exact != 0;
|
||||
log_set_level(Log::Error);
|
||||
REQUIRE_EQ(f.start(), RAD_OK);
|
||||
CHECK_EQ(f.sch.geometry().checkpoint_interval, exact ? 1024 : 768);
|
||||
if (exact) CHECK_EQ(f.sch.geometry().grid, 512);
|
||||
}
|
||||
/* A budget off the quantum chunks at the quantum below it: 500 -> 448, and the interval goes
|
||||
* to the next multiple of 448. */
|
||||
Fixture f;
|
||||
f.build(4096, 64, /*max_tok=*/500);
|
||||
f.cfg.checkpoint_interval = 1024;
|
||||
f.cfg.prefix_exact = true;
|
||||
log_set_level(Log::Error);
|
||||
REQUIRE_EQ(f.start(), RAD_OK);
|
||||
CHECK_EQ(f.sch.geometry().checkpoint_interval, 1344);
|
||||
CHECK_EQ(f.sch.geometry().grid, 448);
|
||||
int64_t ck = -1;
|
||||
CHECK_EQ(f.sch.plan_chunk(0, 5000, 500, &ck), 448);
|
||||
CHECK_EQ(f.sch.plan_chunk(896, 5000, 500, &ck), 448);
|
||||
CHECK_EQ(ck, 1344);
|
||||
}
|
||||
|
||||
/* The tail snapshot is where the prompt's last chunk starts, a boundary an idle chunk already
|
||||
* ends on: no extra step, and an exact repeat re-prefills that last chunk whole. */
|
||||
TEST(an_exact_tail_snapshot_is_where_the_last_chunk_starts) {
|
||||
Fixture f;
|
||||
exact_fixture(f, 1); /* interval 1024, chunks of 512 */
|
||||
REQUIRE_EQ(f.start(), RAD_OK);
|
||||
Cut c = cut_from(f.sch, 0, 1800, 512);
|
||||
CHECK((c.ends == std::vector<int64_t>{ 512, 1024, 1536, 1800 }));
|
||||
CHECK((c.ckpts == std::vector<int64_t>{ 1024, 1536 }));
|
||||
/* Its last chunk starting on the interval: that checkpoint is the tail's. */
|
||||
c = cut_from(f.sch, 0, 1100, 512);
|
||||
CHECK((c.ends == std::vector<int64_t>{ 512, 1024, 1100 }));
|
||||
CHECK((c.ckpts == std::vector<int64_t>{ 1024 }));
|
||||
/* One ending on the grid: the last chunk is [1536, 2048), and its end is an interval. */
|
||||
c = cut_from(f.sch, 0, 2048, 512);
|
||||
CHECK((c.ckpts == std::vector<int64_t>{ 1024, 1536, 2048 }));
|
||||
/* Inside the first interval nothing (as before, cheap to prefill again). */
|
||||
c = cut_from(f.sch, 0, 900, 512);
|
||||
CHECK(c.ckpts.empty());
|
||||
/* A step sharing its budget may straddle the tail: split there, the snapshot written. */
|
||||
int64_t ck = -1;
|
||||
CHECK_EQ(f.sch.plan_chunk(1400, 1800, 512, &ck), 136);
|
||||
CHECK_EQ(ck, 1536);
|
||||
/* A budget short of a quantum boundary past it leaves it for the next chunk. */
|
||||
CHECK_EQ(f.sch.plan_chunk(1024, 1800, 100, &ck), 64);
|
||||
CHECK_EQ(ck, -1);
|
||||
|
||||
/* Nearest cuts the same prompt's last chunk at its last quantum boundary instead. */
|
||||
Fixture n;
|
||||
n.build();
|
||||
n.cfg.checkpoint_interval = 1024;
|
||||
REQUIRE_EQ(n.start(), RAD_OK);
|
||||
c = cut_from(n.sch, 0, 1800, 512);
|
||||
CHECK((c.ends == std::vector<int64_t>{ 512, 1024, 1536, 1792, 1800 }));
|
||||
CHECK((c.ckpts == std::vector<int64_t>{ 1024, 1792 }));
|
||||
}
|
||||
|
||||
/* The property itself, over every geometry and many prompt lengths: every checkpoint is on the
|
||||
* grid and is a chunk start of the cold run of the prompt that wrote it and of any longer prompt
|
||||
* it prefixes (an agent's next turn), and from it the hit cuts exactly the cold run's chunks. */
|
||||
TEST(an_exact_hit_from_any_checkpoint_recomputes_the_cold_runs_own_chunks) {
|
||||
for (int kind = 0; kind < 6; ++kind) {
|
||||
Fixture f;
|
||||
exact_fixture(f, kind);
|
||||
REQUIRE_EQ(f.start(), RAD_OK);
|
||||
const ChunkGeometry& g = f.sch.geometry();
|
||||
int checked = 0;
|
||||
for (int64_t L = 100; L <= 3000; L += 37) {
|
||||
const Cut cold = cut_from(f.sch, 0, L, 512);
|
||||
for (int64_t c : cold.ckpts) {
|
||||
CHECK(g.on_grid(c));
|
||||
if (c >= L) continue;
|
||||
CHECK(std::find(cold.ends.begin(), cold.ends.end(), c) != cold.ends.end());
|
||||
CHECK(cut_from(f.sch, c, L, 512).ends == ends_after(cold, c));
|
||||
for (int64_t L2 : { L + 1, L + 300, L + 1500 }) {
|
||||
const Cut cold2 = cut_from(f.sch, 0, L2, 512);
|
||||
CHECK(std::find(cold2.ends.begin(), cold2.ends.end(), c) != cold2.ends.end());
|
||||
CHECK(cut_from(f.sch, c, L2, 512).ends == ends_after(cold2, c));
|
||||
}
|
||||
++checked;
|
||||
}
|
||||
}
|
||||
CHECK(kind == 5 ? checked == 0 : checked > 20);
|
||||
}
|
||||
/* What nearest gives up: its tail snapshot at a 1000-token prompt's last quantum boundary
|
||||
* (960) is no chunk start of the 1500-token turn after it, which a cold run cuts at 768 and
|
||||
* 1024, so a hit there recomputes [960, 1024) as a chunk of its own. */
|
||||
Fixture n;
|
||||
n.build();
|
||||
REQUIRE_EQ(n.start(), RAD_OK);
|
||||
const Cut c1000 = cut_from(n.sch, 0, 1000, 512);
|
||||
CHECK(std::find(c1000.ckpts.begin(), c1000.ckpts.end(), 960) != c1000.ckpts.end());
|
||||
const Cut c1500 = cut_from(n.sch, 0, 1500, 512);
|
||||
CHECK(std::find(c1500.ends.begin(), c1500.ends.end(), 960) == c1500.ends.end());
|
||||
CHECK(std::find(c1500.ends.begin(), c1500.ends.end(), 768) != c1500.ends.end());
|
||||
CHECK_EQ(cut_from(n.sch, 960, 1500, 512).ends.front(), 1024);
|
||||
}
|
||||
|
||||
/* At admission: a hit at a snapshot resumes there (plan_chunk put it on the grid); a hit with no
|
||||
* snapshot to resume from (full attention alone) steps back to the grid, the blocks above it
|
||||
* left to the cache and recomputed in the cold run's chunk. */
|
||||
TEST(an_exact_hit_steps_back_to_the_grid_and_prefills_the_cold_chunks) {
|
||||
for (int exact = 0; exact < 2; ++exact) {
|
||||
Fixture f;
|
||||
exact_fixture(f, 5); /* chunks of 512, no snapshots */
|
||||
f.cfg.prefix_exact = exact != 0;
|
||||
REQUIRE_EQ(f.start(), RAD_OK);
|
||||
f.pc.seed(784); /* 49 blocks */
|
||||
const uint64_t a = f.submit(1300, 8);
|
||||
const RadBatch* b = f.sch.step();
|
||||
REQUIRE(b != nullptr);
|
||||
CHECK_EQ(f.sch.find(a)->n_computed, exact ? 512 : 784);
|
||||
CHECK_EQ(b->ctx_lens[0], exact ? 512 : 784);
|
||||
CHECK_EQ(b->n_tok, 512); /* [512, 1024) as the cold run, or [784, 1296) */
|
||||
CHECK_EQ((int)f.kv.block_table(a, 0).size(), exact ? 64 : 81);
|
||||
CHECK_EQ(f.sch.metrics().hit_cut_tokens, exact ? 272 : 0);
|
||||
}
|
||||
/* With snapshots the hit is at one: kept as is, restored from its slot. */
|
||||
Fixture f;
|
||||
exact_fixture(f, 1);
|
||||
REQUIRE_EQ(f.start(), RAD_OK);
|
||||
f.pc.seed(1600);
|
||||
f.pc.lin = 1536; /* a tail snapshot, on the 512 grid */
|
||||
f.pc.src = 3;
|
||||
const uint64_t a = f.submit(1800, 8);
|
||||
const RadBatch* b = f.sch.step();
|
||||
REQUIRE(b != nullptr);
|
||||
CHECK_EQ(f.sch.find(a)->n_computed, 1536);
|
||||
CHECK_EQ(b->n_tok, 264); /* the cold run's last chunk, whole */
|
||||
CHECK_EQ(f.sch.plan().e[0].ckpt_restore, 3);
|
||||
}
|
||||
|
||||
/* A cold prompt at the scheduler: the last chunk is not split at the end, and an exact repeat's
|
||||
* hit at the tail snapshot is that chunk. */
|
||||
TEST(an_exact_cold_prefill_keeps_its_last_chunk_whole) {
|
||||
Fixture f;
|
||||
exact_fixture(f, 0); /* interval 256, chunks of 256 */
|
||||
REQUIRE_EQ(f.start(), RAD_OK);
|
||||
f.submit(1000, 1);
|
||||
std::vector<int64_t> toks, ckpts;
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
const RadBatch* b = f.sch.step();
|
||||
if (!b) break;
|
||||
toks.push_back(b->n_tok);
|
||||
for (int k = 0; k < b->n_checkpoints; ++k)
|
||||
ckpts.push_back(b->ctx_lens[0] + b->checkpoint_tok[k] + 1);
|
||||
f.commit_plain();
|
||||
}
|
||||
CHECK((toks == std::vector<int64_t>{ 256, 256, 256, 232 }));
|
||||
CHECK((ckpts == std::vector<int64_t>{ 256, 512, 768 }));
|
||||
}
|
||||
|
||||
TEST(a_chunk_ending_on_a_checkpoint_carries_it_into_the_batch) {
|
||||
Fixture f;
|
||||
f.build();
|
||||
@@ -1117,6 +1363,123 @@ TEST(a_hit_on_a_model_with_a_windowed_group_reuses_nothing) {
|
||||
CHECK_EQ(m.linear_cached_tokens, 0);
|
||||
}
|
||||
|
||||
/* The same model with the trunk's window in the checkpoint slot (KVGroupPlan::win_snap beside
|
||||
* linear state, as DeepSeek-V4.1's sliding layers beside its compressor state): the hit resumes at
|
||||
* the snapshot, which restores the linear state and the window together, and the cached group's
|
||||
* blocks are adopted. Before, a model with linear state never put its window in the slot, so this
|
||||
* clamp refused every hit on it. */
|
||||
TEST(a_hit_on_a_hybrid_whose_slot_carries_the_window_resumes_at_the_snapshot) {
|
||||
Fixture f;
|
||||
f.build(4096, 64, 512, 4096, /*windowed=*/true);
|
||||
const int32_t swa = 3;
|
||||
f.kv.snap = { swa };
|
||||
f.pc.groups = { 0 };
|
||||
CHECK_OK(f.start());
|
||||
f.pc.seed(304);
|
||||
f.pc.lin = 256;
|
||||
f.pc.src = 3;
|
||||
|
||||
const uint64_t a = f.submit(300, 8);
|
||||
const RadBatch* b = f.sch.step();
|
||||
REQUIRE(b != nullptr);
|
||||
CHECK_EQ(f.sch.find(a)->n_computed, 256);
|
||||
CHECK_EQ(b->ctx_lens[0], 256);
|
||||
CHECK_EQ(f.sch.plan().e[0].ckpt_restore, 3);
|
||||
CHECK_EQ(f.kv.block_table(a, 0)[0], f.pc.seeded[0][0]);
|
||||
const SchedMetrics m = f.sch.metrics();
|
||||
CHECK_EQ(m.linear_cached_tokens, 256);
|
||||
CHECK_EQ(m.hit_cut_window, 0);
|
||||
|
||||
/* A hit with no snapshot under it still reuses nothing: the window has nowhere to come from. */
|
||||
Fixture g;
|
||||
g.build(4096, 64, 512, 4096, /*windowed=*/true);
|
||||
g.kv.snap = { swa };
|
||||
g.pc.groups = { 0 };
|
||||
CHECK_OK(g.start());
|
||||
g.pc.seed(304);
|
||||
g.pc.lin = 0;
|
||||
g.pc.src = -1;
|
||||
const uint64_t c = g.submit(300, 8);
|
||||
REQUIRE(g.sch.step() != nullptr);
|
||||
CHECK_EQ(g.sch.find(c)->n_computed, 0);
|
||||
}
|
||||
|
||||
/* A trunk group the cache does not index and no slot carries is a hole no snapshot fills: a full
|
||||
* group left out (as a group at another block size was before the cache took every block size)
|
||||
* refuses the hit even where the window is in the slot. */
|
||||
TEST(a_trunk_group_neither_cached_nor_in_the_slot_refuses_the_hit) {
|
||||
Fixture f;
|
||||
f.build(4096, 64, 512, 4096, /*windowed=*/true);
|
||||
KVGroupInfo k;
|
||||
k.name = "fine";
|
||||
k.decl.kind = RAD_KV_FULL;
|
||||
k.block_size = 16;
|
||||
k.layers = { 3 };
|
||||
f.prog.kv_groups.push_back(k);
|
||||
f.kv.setup(f.prog.kv_groups, f.cfg.max_ctx, 4096, 64);
|
||||
f.kv.snap = { 3 };
|
||||
f.pc.groups = { 0 };
|
||||
CHECK_OK(f.start());
|
||||
f.pc.seed(304);
|
||||
f.pc.lin = 256;
|
||||
f.pc.src = 3;
|
||||
const uint64_t a = f.submit(300, 8);
|
||||
REQUIRE(f.sch.step() != nullptr);
|
||||
CHECK_EQ(f.sch.find(a)->n_computed, 0);
|
||||
CHECK_EQ(f.sch.metrics().hit_cut_window, 1);
|
||||
}
|
||||
|
||||
/* Groups at two block sizes: a hit adopts each group's own blocks (the 8-token group twice as
|
||||
* many), and the cache's reserve is asked for in entries, from the group furthest short. */
|
||||
TEST(a_hit_over_mixed_block_sizes_adopts_each_groups_own_blocks) {
|
||||
Fixture f;
|
||||
f.build(4096, 64);
|
||||
KVGroupInfo k;
|
||||
k.name = "fine";
|
||||
k.decl.kind = RAD_KV_FULL;
|
||||
k.block_size = 8;
|
||||
f.prog.kv_groups.push_back(k);
|
||||
const int32_t fine = 3;
|
||||
f.kv.setup(f.prog.kv_groups, f.cfg.max_ctx, 4096, 64);
|
||||
f.pc.groups = { 0, fine };
|
||||
CHECK_OK(f.start());
|
||||
CHECK_EQ(f.sch.geometry().quantum % 16, 0ll);
|
||||
f.pc.seed(304); /* 19 blocks of 16, 38 of 8 */
|
||||
f.pc.lin = 256;
|
||||
f.pc.src = 3;
|
||||
const uint64_t a = f.submit(1000, 8);
|
||||
REQUIRE(f.sch.step() != nullptr);
|
||||
CHECK_EQ(f.sch.find(a)->n_computed, 256);
|
||||
const std::vector<int32_t> t0 = f.kv.block_table(a, 0), t1 = f.kv.block_table(a, fine);
|
||||
CHECK_EQ((int)t0.size(), 32); /* 16 adopted + 16 for the 256-token chunk */
|
||||
CHECK_EQ((int)t1.size(), 64); /* 32 adopted + 32 */
|
||||
for (int i = 0; i < 16; ++i) CHECK_EQ(t0[(size_t)i], f.pc.seeded[0][(size_t)i]);
|
||||
for (int i = 0; i < 32; ++i) CHECK_EQ(t1[(size_t)i], f.pc.seeded[1][(size_t)i]);
|
||||
}
|
||||
|
||||
TEST(the_cache_trim_over_mixed_block_sizes_asks_for_entries) {
|
||||
Fixture f;
|
||||
f.build(/*blocks=*/64, /*states=*/64);
|
||||
KVGroupInfo k;
|
||||
k.name = "fine";
|
||||
k.decl.kind = RAD_KV_FULL;
|
||||
k.block_size = 8;
|
||||
f.prog.kv_groups.push_back(k);
|
||||
f.kv.setup(f.prog.kv_groups, f.cfg.max_ctx, 64, 64);
|
||||
f.pc.groups = { 0, 3 };
|
||||
CHECK_OK(f.start());
|
||||
f.pc.evict_grant = 1 << 20;
|
||||
f.submit(160, /*max_tokens=*/1); /* 10 + 20 blocks, finishes on the first commit */
|
||||
f.submit(176, /*max_tokens=*/64); /* 11 + 22 each, still running after it */
|
||||
f.submit(176, /*max_tokens=*/64);
|
||||
REQUIRE(f.sch.step() != nullptr);
|
||||
CHECK_EQ(f.kv.held_blocks(0), 32ll); /* 32 free against a reserve of 16 */
|
||||
CHECK_EQ(f.kv.held_blocks(3), 64ll); /* none free against 16: 8 entries of 2 */
|
||||
f.commit_plain();
|
||||
REQUIRE(f.pc.trims.size() == 1u);
|
||||
CHECK_EQ(f.pc.trims[0], 8ll);
|
||||
}
|
||||
|
||||
/* A request whose media is not encoded yet waits, and only it does: it is not admitted without
|
||||
* its rows, and the request behind it is asked and runs. Once its items are encoded it is
|
||||
* admitted where it stood. */
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
*/
|
||||
#include "rad_test.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include "text/gguf.h"
|
||||
#include "text/tokenizer.h"
|
||||
#include "text/tokenizer_nfc.h"
|
||||
@@ -2240,4 +2242,29 @@ TEST(the_normal_forms_agree_with_an_independent_implementation) {
|
||||
CHECK(rows > 2500);
|
||||
}
|
||||
|
||||
/* A release that ships no chat template (DeepSeek's) is why --chat-template exists: the file is
|
||||
* read, trailing newlines stripped exactly as the checkpoint's own file is, and an unreadable or
|
||||
* empty file is refused rather than skipped. */
|
||||
TEST(read_chat_template_path_strips_newlines_and_refuses_empty) {
|
||||
VocabBuild vb;
|
||||
const std::string p = radtest::tmp_path("chat_template.jinja");
|
||||
{
|
||||
std::ofstream f(p);
|
||||
f << "{%- raw %}{{ messages }}{%- endraw %}\n\n";
|
||||
}
|
||||
CHECK_OK(read_chat_template_path(p.c_str(), vb));
|
||||
CHECK_EQ(vb.chat_template, std::string("{%- raw %}{{ messages }}{%- endraw %}"));
|
||||
|
||||
vb.chat_template.clear();
|
||||
{
|
||||
std::ofstream f(p);
|
||||
f << "\n\r\n";
|
||||
}
|
||||
CHECK_EQ(read_chat_template_path(p.c_str(), vb), (int)RAD_E_IO);
|
||||
CHECK(vb.chat_template.empty());
|
||||
|
||||
CHECK_EQ(read_chat_template_path(radtest::tmp_path("absent.jinja").c_str(), vb), (int)RAD_E_IO);
|
||||
std::remove(p.c_str());
|
||||
}
|
||||
|
||||
RAD_TEST_MAIN()
|
||||
@@ -1080,8 +1080,7 @@ TEST(a_keyframe_pair_is_encoded_and_pins_both_ends) {
|
||||
CHECK(stepped);
|
||||
}
|
||||
|
||||
/* References ride a latent upscale, laid out again at the small size for the steps before it; a
|
||||
* keyframe, pinned on the video's own grid, does not. */
|
||||
/* References ride a latent upscale, laid out again at the small size for the steps before it. */
|
||||
TEST(references_are_laid_out_again_at_an_upscales_small_size) {
|
||||
VideoFixture f;
|
||||
f.build();
|
||||
@@ -1120,6 +1119,53 @@ TEST(references_are_laid_out_again_at_an_upscales_small_size) {
|
||||
CHECK_OK(f.drv.done());
|
||||
}
|
||||
CHECK_EQ(kinds, std::string("ECSSUSAD"));
|
||||
}
|
||||
|
||||
/* A keyframe rides a latent upscale pinned on the grid the steps run on: encoded at the small size
|
||||
* before the prompt, and again at the full size, into the same slot, between the upscale and the
|
||||
* first full-size step. Without its small picture the request is refused. */
|
||||
TEST(a_keyframe_is_encoded_again_at_the_full_size_after_an_upscale) {
|
||||
VideoFixture f;
|
||||
f.build();
|
||||
f.prog.video_gen.upscale_max = 4.0;
|
||||
f.prog.video_gen.upscale_refine = 1;
|
||||
with_tower(f, 16);
|
||||
CHECK_OK(f.start_refs());
|
||||
std::string why;
|
||||
auto r = f.req(1, 4);
|
||||
r->width = 64;
|
||||
r->height = 64;
|
||||
r->upscale = 2.0;
|
||||
gen::VideoRefMedia kf = picture(gen::VideoRefMedia::FIRST_FRAME, "first_frame", 1, 64, 64);
|
||||
kf.small_w = 32;
|
||||
kf.small_h = 32;
|
||||
kf.small_pixels.assign((size_t)32 * 32 * 3, 2.0f);
|
||||
r->refs.push_back(kf);
|
||||
const int64_t T = (int64_t)r->tokens.size();
|
||||
CHECK_OK(f.drv.submit(std::move(r), &why));
|
||||
|
||||
/* The prompt, a keyframe's 2 rows and 60 soundtrack rows, then a video of 2 rows small, 8 full. */
|
||||
std::string kinds;
|
||||
int steps = 0, encodes = 0;
|
||||
for (int i = 0; i < 20; ++i) {
|
||||
const RadBatch* b = f.drv.next(i);
|
||||
if (!b) break;
|
||||
const RadVideoGenBatch* V = b->vgen_b;
|
||||
kinds += b->gen == RAD_GEN_PASS_VENCODE ? 'E' : kind_of(b->gen);
|
||||
if (b->gen == RAD_GEN_PASS_VENCODE) {
|
||||
const int32_t side = encodes++ == 0 ? 32 : 64;
|
||||
CHECK_EQ(V->enc_kind, (int32_t)RAD_ENC_KEYFRAME);
|
||||
CHECK_EQ(V->enc_slot, 1);
|
||||
CHECK_EQ(V->enc_height, side);
|
||||
CHECK_EQ(V->enc_width, side);
|
||||
} else if (b->gen == RAD_GEN_PASS_VSTEP) {
|
||||
CHECK_EQ(b->n_tok, T + 2 + 60 + (steps++ < 2 ? 2 : 8));
|
||||
CHECK_EQ(V->ref_tab[1], 1);
|
||||
}
|
||||
f.answer(10 * i);
|
||||
CHECK_OK(f.drv.done());
|
||||
}
|
||||
CHECK_EQ(kinds, std::string("ECSSUESAD"));
|
||||
|
||||
VideoFixture g;
|
||||
g.build();
|
||||
@@ -1132,7 +1178,7 @@ TEST(references_are_laid_out_again_at_an_upscales_small_size) {
|
||||
r->upscale = 2.0;
|
||||
r->refs.push_back(picture(gen::VideoRefMedia::FIRST_FRAME, "first_frame", 1, 64, 64));
|
||||
CHECK_EQ(g.drv.submit(std::move(r), &why), (int)RAD_E_INVAL);
|
||||
CHECK(has(why, "latent_upscale"));
|
||||
CHECK(has(why, "small size"));
|
||||
}
|
||||
|
||||
/* A reference video with its soundtrack and a standalone soundtrack: one encode pass each, the
|
||||
|
||||
@@ -680,6 +680,49 @@ TEST(fl2va_keyframes_feed_the_tower_and_pin_the_output_ends) {
|
||||
CHECK(g.tokens == want);
|
||||
}
|
||||
|
||||
/* With a latent upscale each keyframe is prepared twice, the same way: at the canvas and at the
|
||||
* small size the first steps pin it at. The tower still sees the canvas frame only. */
|
||||
TEST(fl2va_keyframes_are_prepared_at_an_upscales_small_size_too) {
|
||||
FakeMultimodal mm;
|
||||
mm.expand = { 900, 901 };
|
||||
mm.enc_frames = 5; mm.enc_side = 16; mm.enc_n = 850;
|
||||
FakeVideoGen gen;
|
||||
std::unique_ptr<Fixture> f(new Fixture(Fixture::Tweak{ [&](ServerOptions& o, Deps& d) {
|
||||
d.videos = &gen;
|
||||
d.mm = &mm;
|
||||
o.video_model = true;
|
||||
gen.inf.enc_ratio = 16;
|
||||
gen.inf.max_enc_side = 512;
|
||||
gen.inf.upscale_max = 4.0;
|
||||
} }));
|
||||
HttpRequest q;
|
||||
q.method = "POST";
|
||||
q.path = "/v1/videos";
|
||||
q.form = { FormPart{ "prompt", "", "", "fox" },
|
||||
FormPart{ "size", "", "", "512x256" },
|
||||
FormPart{ "task", "", "", "fl2va" },
|
||||
FormPart{ "latent_upscale", "", "", "2" },
|
||||
FormPart{ "first_frame", "f.png", "image/png", "PF" },
|
||||
FormPart{ "last_frame", "l.png", "image/png", "PL" } };
|
||||
HttpResponse r = f->srv->router().dispatch(q);
|
||||
REQUIRE_EQ(r.status, 200);
|
||||
CHECK_EQ(mm.n_pframe, 2);
|
||||
REQUIRE_EQ(mm.cenc_covers.size(), (size_t)4);
|
||||
CHECK(!mm.cenc_covers[0]); /* first frame: stretched at both sizes */
|
||||
CHECK(!mm.cenc_covers[1]);
|
||||
CHECK(mm.cenc_covers[2]); /* last frame: centre-cropped at both sizes */
|
||||
CHECK(mm.cenc_covers[3]);
|
||||
const gen::VideoRequest& g = gen.last();
|
||||
REQUIRE_EQ(g.refs.size(), (size_t)2);
|
||||
for (const gen::VideoRefMedia& m : g.refs) {
|
||||
CHECK_EQ(m.enc_w, 512);
|
||||
CHECK_EQ(m.enc_h, 256);
|
||||
CHECK_EQ(m.small_w, 256);
|
||||
CHECK_EQ(m.small_h, 128);
|
||||
CHECK_EQ(m.small_pixels.size(), (size_t)256 * 128 * 3);
|
||||
}
|
||||
}
|
||||
|
||||
/* A last frame alone is <Picture 1>: the number counts the pictures present, as ComfyUI's does.
|
||||
* fl2va (both ends) keeps first = 1, last = 2. */
|
||||
TEST(l2va_presents_its_sole_frame_as_picture_1) {
|
||||
|
||||
Reference in new issue
Block a user