Archived
radiance 1.0.10
- Four-rank Qwen3.8-Flash-Next (PRs 14 and 16 by keptn42): the all-reduce runs fused with the hyper-connection's write, and with the MoE gather in front of it, on decode and verify steps on the exact wire. The routed experts are split in four classes, so every rank computes the same share; moe_gemm_q_mod4 is the new grouped GEMM. The oracle now checks moe_gemm_q on w4nl and w5nl containers. - --embedding-placement and --ngram-placement, each auto | vram | ram | disk. The token embedding can live in the pinned host pool, read in place over the link (from PR 17 by mechkbfan). An n-gram table can be copied into locked RAM at load instead of read from the container (from PR 15 by keptn42). auto takes the fastest tier with room once every other weight is placed, and startup prints what it chose and why. A tier that cannot be honoured stops the start with the reason; the embedding on disk and the n-gram table in VRAM are refused, since nothing can serve them. - The expert_tiered placement no longer spends the pinned host pool twice when it falls back to layer offload, and a lossy-wire request for a four-rank fused write is a selection miss rather than a startup abort.
This commit is contained in:
1 parent
2f56e3c477
commit
e466fa07e2
56 files changed
+1804
-761
No files matched your search
@@ -158,8 +158,7 @@ endif()
|
||||
# runs embed_lookup_q over a file-backed table with two ranks and the read-ahead racing: the path a
|
||||
# model's host gather takes and that no geometry reaches. It writes its table beside itself, where
|
||||
# the filesystem reports its direct-I/O alignment, and again in TMPDIR, where a tmpfs reports none
|
||||
# and the gather aligns its reads by the block size, as it does on btrfs. And once with `resident`,
|
||||
# from the table's copy in RAM where the process may lock it.
|
||||
# and the gather aligns its reads by the block size, as it does on btrfs.
|
||||
if(TARGET libavx AND TARGET rad-avx-check)
|
||||
add_test(NAME avx_check
|
||||
COMMAND rad-avx-check --ref ${RAD_PLUGIN_OUT}/kernels/libref.so
|
||||
|
||||
+89
-50
@@ -1849,18 +1849,18 @@ TEST(a_sizing_declare_leaves_the_step_state_alone_and_shrinks_only_rows) {
|
||||
* cannot cut evenly, so the split is UNEVEN BY CLASS and it is the width that divides, not the
|
||||
* expert set: every rank routes every one of the 512 experts and computes [lo, hi) of each, the
|
||||
* rank taking the odd block going round with the expert's number mod 4 -- five blocks of every
|
||||
* four experts on every rank -- and with its parity in a layer whose quantised experts do not
|
||||
* come in fours. Sharding the experts instead
|
||||
* was tried and is wrong here -- protection is per-rank, so a rank can end up owning one plain
|
||||
* bf16 expert, leaving an odd count of quantised ones, and the grouped GEMM takes its experts as
|
||||
* two EQUAL tables by parity. The recipe protects experts in pairs for exactly that reason.
|
||||
* four experts on every rank, whatever count of quantised experts (four or more) a layer
|
||||
* keeps. Sharding the experts instead was tried and is wrong here -- protection is per-rank,
|
||||
* so a rank can end up owning one plain bf16 expert, leaving an odd count of quantised ones,
|
||||
* and the grouped GEMM takes its experts as two EQUAL tables by parity. The recipe protects
|
||||
* experts in pairs for exactly that reason.
|
||||
* - the FUSED all-reduces are world-2 kernels (`ar_wire_is_exact` and `ar_fused_ok` both return
|
||||
* false off two), with one exception: the gated residual's write. `ar_hc_write` and
|
||||
* `ar_gather_hc_write` also exist at four, on the exact wire only (no `wire` key, never the
|
||||
* rotated form). Every block still declares its standalone `all_reduce`, and every MoE block
|
||||
* its `moe_gather`, which serve the steps the fused write declines. The contrast with world 2
|
||||
* in the same test is the contract -- it fails loudly if a fused declare is ever gated on the
|
||||
* wrong condition.
|
||||
* `ar_gather_hc_write` also exist at four, on the exact wire only (`wire` 0, never the rotated
|
||||
* form) and over the rows of a decode or verify step, max_seqs * (1 + max_spec). Every block
|
||||
* still declares its standalone `all_reduce`, and every MoE block its `moe_gather`, which
|
||||
* serve the steps the fused write declines. The contrast with world 2 in the same test is the
|
||||
* contract -- it fails loudly if a fused declare is ever gated on the wrong condition.
|
||||
*
|
||||
* Every expected number is derived from the meta this file builds (n_head 24, n_head_kv 2, head_dim
|
||||
* 256, num_experts 512), so the fixture and the assertions cannot drift apart. Where a number is
|
||||
@@ -2002,7 +2002,9 @@ TEST(flashnext_tp4_replicates_kv_heads_and_splits_expert_widths) {
|
||||
|
||||
/* (4) A standalone collective per reduction, the exact four-rank ar_hc_write and
|
||||
* ar_gather_hc_write beside it -- the gather form on every MoE connection, so one a layer
|
||||
* plus the MTP head's if there is one -- and not the fused norm. */
|
||||
* plus the MTP head's if there is one -- and not the fused norm. Both fused forms state
|
||||
* the exact wire and are declared over a decode or verify step's rows, 8 * (1 + 3): the
|
||||
* architecture's own bound, not a message size a kernel library chose. */
|
||||
CHECK(count_op(b[r], "all_reduce") > 0);
|
||||
CHECK_EQ(pint(find_op(b[r], "all_reduce"), "world_size"), world);
|
||||
CHECK(count_op(b[r], "ar_hc_write") > 0);
|
||||
@@ -2012,7 +2014,11 @@ TEST(flashnext_tp4_replicates_kv_heads_and_splits_expert_widths) {
|
||||
for (const RecOp& o : b[r].ops) {
|
||||
if (o.op != "ar_hc_write" && o.op != "ar_gather_hc_write") continue;
|
||||
CHECK_EQ(pint(&o, "world_size"), world);
|
||||
CHECK(param(&o, "wire") == nullptr); /* exact only */
|
||||
CHECK_EQ(pint(&o, "wire"), 0); /* exact only, and stated */
|
||||
const RecParam* m = param(&o, "M");
|
||||
REQUIRE(m != nullptr);
|
||||
CHECK_EQ(m->kind, (int)RAD_P_RANGE);
|
||||
CHECK_EQ(m->ihi, c[r].max_seqs * (1 + c[r].max_spec));
|
||||
}
|
||||
CHECK_EQ(count_op(b[r], "ar_rmsnorm_quant_fp8"), 0);
|
||||
}
|
||||
@@ -2048,9 +2054,9 @@ TEST(flashnext_tp4_replicates_kv_heads_and_splits_expert_widths) {
|
||||
}
|
||||
|
||||
/* THE SHARED ARM IS SPLIT BY WHOLE BLOCKS AND IS UNEVEN AT FOUR: 640 is five blocks of 128, and
|
||||
* the rank taking the extra block is rank 2, the first rank the routed split gives no extra
|
||||
* block (qwen4exp_fp8.cpp's narrow_place) -- ranks 2, 3, 0, 1 cut [0,256) [256,384) [384,512)
|
||||
* [512,640) in the model's column numbering. At two ranks rank 0 still takes three of five.
|
||||
* the rank taking the extra block is rank 2, the first rank after the plain experts' extra
|
||||
* tiles on ranks 0 and 1 (qwen4exp_fp8.cpp's shared_place) -- ranks 2, 3, 0, 1 cut [0,256)
|
||||
* [256,384) [384,512) [512,640) in the model's column numbering. At two ranks rank 0 still takes three of five.
|
||||
* This is the one world-4 span that is NOT a KV head. */
|
||||
const int64_t sh_lo[] = { 384, 512, 0, 256 };
|
||||
const int64_t sh_hi[] = { 512, 640, 256, 384 };
|
||||
@@ -2095,6 +2101,14 @@ TEST(flashnext_tp4_replicates_kv_heads_and_splits_expert_widths) {
|
||||
CHECK_EQ(pint(find_op(h[r], "moe_scatter"), "expert_base"), 0);
|
||||
CHECK(count_op(h[r], "ar_hc_write") > 0);
|
||||
CHECK(count_op(h[r], "ar_gather_hc_write") > 0);
|
||||
/* Two ranks keep the exact write over every step, prefill chunks included. */
|
||||
for (const RecOp& o : h[r].ops) {
|
||||
if (o.op != "ar_hc_write") continue;
|
||||
CHECK_EQ(pint(&o, "wire"), 0);
|
||||
const RecParam* m = param(&o, "M");
|
||||
REQUIRE(m != nullptr);
|
||||
CHECK_EQ(m->ihi, c2.max_tok);
|
||||
}
|
||||
/* Not ar_rmsnorm_quant_fp8: qwen4exp hands every block's norm `kArNone`, because here
|
||||
* the reduction rides in the gated residual's WRITE rather than in the norm that
|
||||
* follows it (qwen4exp_fp8.cpp's block declares). So this one is absent at BOTH world
|
||||
@@ -2103,24 +2117,54 @@ TEST(flashnext_tp4_replicates_kv_heads_and_splits_expert_widths) {
|
||||
}
|
||||
}
|
||||
|
||||
/* THE FOUR-RANK FUSED WRITE'S STEPS: exactly those the standalone collective would have served
|
||||
* as the exact one-shot -- under 1 MiB, and on the lossy wire also under its floor (or off its
|
||||
* 128-element tile). The block in front and the write ask the same predicate. At two ranks it
|
||||
* is ar_wire_is_exact unchanged, and ar_wire_is_exact itself stays false at four. */
|
||||
/* THE FOUR-RANK FUSED WRITE'S STEPS: the decode and verify steps -- max_seqs * (1 + max_spec)
|
||||
* rows, never more than max_tok -- whose message goes out exact, which on the lossy wire means
|
||||
* under its floor or off its 128-element tile. The bound is the architecture's own and not a
|
||||
* message size: 64 sequences at depth 3 are 256 rows, 1.25 MiB, and still take it, while a
|
||||
* prefill chunk keeps the pair at any size. The block in front and the write ask the same
|
||||
* predicate. At two ranks it is ar_wire_is_exact unchanged, and ar_wire_is_exact itself stays
|
||||
* false at four. */
|
||||
{
|
||||
rad::arch::Geom g4{};
|
||||
g4.world = 4; g4.n_embd = 2560; g4.wire_exact = 1; g4.wire_min_bytes = 128 * 1024;
|
||||
CHECK(rad::arch::ar_exact_write_takes(g4, 8)); /* a decode step, 40 KiB */
|
||||
CHECK(rad::arch::ar_exact_write_takes(g4, 204)); /* 1020 KiB */
|
||||
CHECK(!rad::arch::ar_exact_write_takes(g4, 205)); /* 1025 KiB: the two-shot's */
|
||||
g4.max_tok = 2048; g4.max_seqs = 8; g4.max_spec = 3;
|
||||
CHECK_EQ(rad::arch::ar_wide_write_rows(g4), (int64_t)32);
|
||||
CHECK_EQ(rad::arch::ar_exact_write_rows(g4), (int64_t)32);
|
||||
CHECK(!rad::arch::ar_exact_write_takes(g4, 0));
|
||||
CHECK(rad::arch::ar_exact_write_takes(g4, 1));
|
||||
CHECK(rad::arch::ar_exact_write_takes(g4, 8)); /* a decode step */
|
||||
CHECK(rad::arch::ar_exact_write_takes(g4, 32)); /* every sequence verifying 1 + 3 */
|
||||
CHECK(!rad::arch::ar_exact_write_takes(g4, 33)); /* more: a prefill chunk's */
|
||||
CHECK(!rad::arch::ar_exact_write_takes(g4, 2048));
|
||||
CHECK(!rad::arch::ar_wire_is_exact(g4, 8));
|
||||
g4.wire_exact = 0;
|
||||
CHECK(rad::arch::ar_exact_write_takes(g4, 25)); /* 125 KiB, under the floor */
|
||||
CHECK(!rad::arch::ar_exact_write_takes(g4, 26)); /* 130 KiB, the ti8 wire's */
|
||||
CHECK(!rad::arch::ar_exact_write_takes(g4, 32));
|
||||
g4.wire_exact = 1;
|
||||
g4.max_spec = 0; /* one row a sequence */
|
||||
CHECK_EQ(rad::arch::ar_wide_write_rows(g4), (int64_t)8);
|
||||
CHECK(rad::arch::ar_exact_write_takes(g4, 8));
|
||||
CHECK(!rad::arch::ar_exact_write_takes(g4, 9));
|
||||
g4.max_seqs = 64; g4.max_spec = 3;
|
||||
CHECK(rad::arch::ar_exact_write_takes(g4, 256)); /* 1.25 MiB */
|
||||
CHECK(!rad::arch::ar_exact_write_takes(g4, 257));
|
||||
g4.max_tok = 128; /* a step holds no more than this */
|
||||
CHECK_EQ(rad::arch::ar_wide_write_rows(g4), (int64_t)128);
|
||||
CHECK(rad::arch::ar_exact_write_takes(g4, 128));
|
||||
CHECK(!rad::arch::ar_exact_write_takes(g4, 129));
|
||||
rad::arch::Geom g8 = g4;
|
||||
g8.world = 8;
|
||||
CHECK_EQ(rad::arch::ar_exact_write_rows(g8), (int64_t)0);
|
||||
CHECK(!rad::arch::ar_exact_write_takes(g8, 8));
|
||||
rad::arch::Geom g2 = g4;
|
||||
g2.world = 2;
|
||||
for (int64_t T : { 1, 8, 25, 26, 205, 4096 })
|
||||
CHECK(rad::arch::ar_exact_write_takes(g2, T) == rad::arch::ar_wire_is_exact(g2, T));
|
||||
g2.world = 2; g2.max_tok = 4096; g2.max_seqs = 8;
|
||||
CHECK_EQ(rad::arch::ar_exact_write_rows(g2), g2.max_tok);
|
||||
for (int exact : { 0, 1 }) {
|
||||
g2.wire_exact = exact;
|
||||
for (int64_t T : { 1, 8, 25, 26, 33, 205, 4096 })
|
||||
CHECK(rad::arch::ar_exact_write_takes(g2, T) == rad::arch::ar_wire_is_exact(g2, T));
|
||||
}
|
||||
}
|
||||
/* THE FOUR-RANK GATHER'S STEPS: the fused write's, and within one MoE pass. The exact bound
|
||||
* is the only one at four (the rotated form is never declared there, so `rows6` is 0), and a
|
||||
@@ -2129,14 +2173,15 @@ TEST(flashnext_tp4_replicates_kv_heads_and_splits_expert_widths) {
|
||||
{
|
||||
rad::arch::Geom g4{};
|
||||
g4.world = 4; g4.n_embd = 2560; g4.wire_exact = 1; g4.wire_min_bytes = 128 * 1024;
|
||||
CHECK(rad::arch::gather_taken(g4, 8, 2048, 0)); /* a decode step */
|
||||
CHECK(rad::arch::gather_taken(g4, 204, 2048, 0)); /* 1020 KiB, one pass */
|
||||
CHECK(!rad::arch::gather_taken(g4, 205, 2048, 0)); /* the two-shot's */
|
||||
g4.max_tok = 2048; g4.max_seqs = 8; g4.max_spec = 3;
|
||||
CHECK(rad::arch::gather_taken(g4, 8, 32, 0)); /* a decode step */
|
||||
CHECK(rad::arch::gather_taken(g4, 32, 32, 0)); /* a verify step, one pass */
|
||||
CHECK(!rad::arch::gather_taken(g4, 33, 2048, 0)); /* the write declines it */
|
||||
CHECK(!rad::arch::gather_taken(g4, 8, 0, 0)); /* not declared */
|
||||
CHECK(!rad::arch::gather_taken(g4, 100, 64, 0)); /* two passes */
|
||||
CHECK(!rad::arch::gather_taken(g4, 20, 16, 0)); /* two passes */
|
||||
g4.wire_exact = 0;
|
||||
CHECK(rad::arch::gather_taken(g4, 25, 2048, 0)); /* under the floor */
|
||||
CHECK(!rad::arch::gather_taken(g4, 26, 2048, 0)); /* the ti8 wire's */
|
||||
CHECK(rad::arch::gather_taken(g4, 25, 32, 0)); /* under the floor */
|
||||
CHECK(!rad::arch::gather_taken(g4, 26, 32, 0)); /* the ti8 wire's */
|
||||
rad::arch::Geom g2 = g4;
|
||||
g2.world = 2;
|
||||
for (int64_t T : { 1, 8, 25, 26, 205, 4096 })
|
||||
@@ -2146,7 +2191,7 @@ TEST(flashnext_tp4_replicates_kv_heads_and_splits_expert_widths) {
|
||||
}
|
||||
}
|
||||
/* ...and the lossy wire at four declares no rotated write and no rotated gather form: the
|
||||
* exact ones only, for the steps under the floor. */
|
||||
* exact ones only, stating `wire` 0, for the decode and verify steps under the floor. */
|
||||
{
|
||||
RadBuilder b4;
|
||||
RadBuildCtx c4 = build_ctx(0, world);
|
||||
@@ -2158,7 +2203,10 @@ TEST(flashnext_tp4_replicates_kv_heads_and_splits_expert_widths) {
|
||||
CHECK(count_op(b4, "ar_gather_hc_write") > 0);
|
||||
for (const RecOp& o : b4.ops) {
|
||||
if (o.op != "ar_hc_write" && o.op != "ar_gather_hc_write") continue;
|
||||
CHECK(param(&o, "wire") == nullptr);
|
||||
CHECK_EQ(pint(&o, "wire"), 0);
|
||||
const RecParam* m = param(&o, "M");
|
||||
REQUIRE(m != nullptr);
|
||||
CHECK_EQ(m->ihi, c4.max_seqs * (1 + c4.max_spec));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2181,9 +2229,7 @@ TEST(flashnext_tp4_replicates_kv_heads_and_splits_expert_widths) {
|
||||
const RadEncoding w4p = [] { RadEncoding e = rad_enc_affine(RAD_I4, RAD_BF16, 1, 128);
|
||||
rad_enc_copy_str(e.transform, "fwht128"); return e; }();
|
||||
const RadEncoding plain = rad_enc_plain(RAD_BF16);
|
||||
/* The parity slices, [lo, hi) by place parity, and the four-class ones by place mod 4. */
|
||||
const int64_t par_lo[4][2] = { { 0, 512 }, { 256, 0 }, { 384, 256 }, { 512, 384 } };
|
||||
const int64_t par_hi[4][2] = { { 256, 640 }, { 384, 256 }, { 512, 384 }, { 640, 512 } };
|
||||
/* The four-class slices, [lo, hi) by rank and place mod 4. */
|
||||
const int64_t c4_lo[4][4] = { { 0, 512, 384, 256 }, { 256, 0, 512, 384 },
|
||||
{ 384, 256, 0, 512 }, { 512, 384, 256, 0 } };
|
||||
const int64_t c4_hi[4][4] = { { 256, 640, 512, 384 }, { 384, 256, 640, 512 },
|
||||
@@ -2204,7 +2250,6 @@ TEST(flashnext_tp4_replicates_kv_heads_and_splits_expert_widths) {
|
||||
RadBuildCtx cp = build_ctx(r, world);
|
||||
cp.max_tok = 2048; cp.max_seqs = 8; cp.max_spec = 3; cp.max_ctx = 200000;
|
||||
REQUIRE_EQ(qwen4exp_fp8::declare(&bp, &meta, &cp), RAD_OK);
|
||||
const int ncls = 4;
|
||||
const int64_t n_reg = ne_all - nprot;
|
||||
/* layer 1's quantised GEMMs, and nobody else's */
|
||||
int l1_ops = 0, other_ops = 0;
|
||||
@@ -2215,7 +2260,7 @@ TEST(flashnext_tp4_replicates_kv_heads_and_splits_expert_widths) {
|
||||
l1 = l1 || bp.weights[wh - 1].name.rfind("blk.1.", 0) == 0;
|
||||
if (!l1) { CHECK_EQ(o.op, std::string("moe_gemm_q_mod4")); ++other_ops; continue; }
|
||||
++l1_ops;
|
||||
CHECK_EQ(o.op, std::string(ncls == 4 ? "moe_gemm_q_mod4" : "moe_gemm_q"));
|
||||
CHECK_EQ(o.op, std::string("moe_gemm_q_mod4"));
|
||||
CHECK_EQ(pint(&o, "n_expert"), n_reg);
|
||||
CHECK_EQ(o.w.size(), (size_t)(2 * n_reg));
|
||||
/* the four runs, read off the declaration: codes then scales, class by class,
|
||||
@@ -2247,18 +2292,12 @@ TEST(flashnext_tp4_replicates_kv_heads_and_splits_expert_widths) {
|
||||
int place = e;
|
||||
for (int x : pe) place -= x < e ? 1 : 0;
|
||||
CHECK(w.span_set);
|
||||
if (ncls == 4) {
|
||||
CHECK_EQ(w.span_lo, c4_lo[r][place % 4]);
|
||||
CHECK_EQ(w.span_hi, c4_hi[r][place % 4]);
|
||||
} else {
|
||||
CHECK_EQ(w.span_lo, par_lo[r][place % 2]);
|
||||
CHECK_EQ(w.span_hi, par_hi[r][place % 2]);
|
||||
}
|
||||
CHECK_EQ(w.span_lo, c4_lo[r][place % 4]);
|
||||
CHECK_EQ(w.span_hi, c4_hi[r][place % 4]);
|
||||
++seen;
|
||||
}
|
||||
CHECK_EQ(seen, (int)n_reg);
|
||||
/* the plain experts' tiles: by narrow_place at two classes, by rank at four */
|
||||
const int64_t p2_lo[4] = { 384, 512, 0, 192 }, p2_hi[4] = { 512, 640, 192, 384 };
|
||||
/* the plain experts' tiles, by rank: 3, 3, 2, 2 */
|
||||
const int64_t p4_lo[4] = { 0, 192, 384, 512 }, p4_hi[4] = { 192, 384, 512, 640 };
|
||||
int pseen = 0;
|
||||
for (const RecWeight& w : bp.weights) {
|
||||
@@ -2266,8 +2305,8 @@ TEST(flashnext_tp4_replicates_kv_heads_and_splits_expert_widths) {
|
||||
if (w.name.find("_exps.") == std::string::npos) continue;
|
||||
if (w.name.compare(w.name.size() - 7, 7, ".weight") != 0) continue;
|
||||
CHECK(w.span_set);
|
||||
CHECK_EQ(w.span_lo, ncls == 4 ? p4_lo[r] : p2_lo[r]);
|
||||
CHECK_EQ(w.span_hi, ncls == 4 ? p4_hi[r] : p2_hi[r]);
|
||||
CHECK_EQ(w.span_lo, p4_lo[r]);
|
||||
CHECK_EQ(w.span_hi, p4_hi[r]);
|
||||
++pseen;
|
||||
}
|
||||
CHECK_EQ(pseen, 2 * nprot);
|
||||
@@ -2289,7 +2328,7 @@ TEST(flashnext_tp4_replicates_kv_heads_and_splits_expert_widths) {
|
||||
* Ten tiles over four ranks is 3, 3, 2, 2: an UNEVEN share, still whole tiles, every tile owned
|
||||
* once. Ranks 0 and 1 compute 192 columns of every protected expert and ranks 2 and 3 compute
|
||||
* 128: the routed experts are split in four classes, so every rank holds the same routed
|
||||
* width, and rank 2 holds the shared expert's extra block (narrow_place). Two protected
|
||||
* width, and rank 2 holds the shared expert's extra block (shared_place). Two protected
|
||||
* experts, as the production recipe's pairs have it. */
|
||||
{
|
||||
const RadEncoding w4p = [] { RadEncoding e = rad_enc_affine(RAD_I4, RAD_BF16, 1, 128);
|
||||
|
||||
@@ -486,6 +486,87 @@ TEST(no_schema_names_the_near_miss) {
|
||||
CHECK(has(b.errors().back(), "did you mean"));
|
||||
}
|
||||
|
||||
/* ================================================================== a weight list over its tables
|
||||
* A table operand consumes a RUN of the declared weights, and the declaration decides which run:
|
||||
* the fixed weight positions take one each, and the rest is divided over the table positions in
|
||||
* declaration order, the first positions taking one more where it does not divide. That map
|
||||
* (OpInfo::weight_opd) is what the layout pass, the converter and the issue path all read, so it
|
||||
* is asserted whole. t_moe is one fixed weight (operand 1) and eight tables -- class pairs at
|
||||
* operands 2/3, 5/6, 7/8 and 9/10 -- the way a four-class grouped GEMM lays its classes out. */
|
||||
namespace {
|
||||
|
||||
/* `n` weights declared in a row under `tag`, and t_moe over them. */
|
||||
rad_op decl_moe(Builder& b, const char* tag, int n, std::vector<rad_weight>* w) {
|
||||
w->clear();
|
||||
for (int i = 0; i < n; ++i)
|
||||
w->push_back(decl_w(b, (std::string(tag) + ".e" + std::to_string(i)).c_str(), 64, 64));
|
||||
const RadParam p[] = { RAD_INT("M", 8), RAD_INT("n", 64) };
|
||||
return b.decl_op("t_moe", p, 2, w->data(), (int)w->size());
|
||||
}
|
||||
|
||||
/* The operand each declared weight went to, as runs: "1x1 2x3" is one weight at operand 1, then
|
||||
* three at operand 2. */
|
||||
std::string runs(const OpInfo* o) {
|
||||
std::string s;
|
||||
for (size_t i = 0; i < o->weight_opd.size();) {
|
||||
size_t j = i;
|
||||
while (j < o->weight_opd.size() && o->weight_opd[j] == o->weight_opd[i]) ++j;
|
||||
s += (s.empty() ? "" : " ") + std::to_string(o->weight_opd[i]) + "x" +
|
||||
std::to_string(j - i);
|
||||
i = j;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
} /* namespace */
|
||||
|
||||
TEST(a_weight_list_divides_over_its_tables_the_first_taking_the_remainder) {
|
||||
NEED_PLUGIN(reg)
|
||||
Builder b(reg, make_meta(), make_ctx());
|
||||
std::vector<rad_weight> w;
|
||||
|
||||
/* Ten experts' codes and scales behind the fixed weight: twenty entries over eight tables is
|
||||
* two each and four left, so the first four positions -- classes 0 and 1, codes and scales --
|
||||
* hold three and the last four two. A four-class grouped GEMM over ten experts, whose first
|
||||
* two classes are one expert longer. */
|
||||
rad_op h = decl_moe(b, "ten", 21, &w);
|
||||
REQUIRE(h != RAD_NULL_HANDLE);
|
||||
const OpInfo* o = b.program().op(h);
|
||||
REQUIRE(o != nullptr);
|
||||
CHECK_EQ(runs(o), std::string("1x1 2x3 3x3 5x3 6x3 7x2 8x2 9x2 10x2"));
|
||||
/* The list is cut into runs in the order it was declared, not dealt out. */
|
||||
CHECK(o->weights == w);
|
||||
|
||||
/* A list that divides is the plain equal division: sixteen entries, two a table. */
|
||||
h = decl_moe(b, "eight", 17, &w);
|
||||
REQUIRE(h != RAD_NULL_HANDLE);
|
||||
CHECK_EQ(runs(b.program().op(h)), std::string("1x1 2x2 3x2 5x2 6x2 7x2 8x2 9x2 10x2"));
|
||||
|
||||
/* One entry a table is the least a declaration can give. */
|
||||
h = decl_moe(b, "four", 9, &w);
|
||||
REQUIRE(h != RAD_NULL_HANDLE);
|
||||
CHECK_EQ(runs(b.program().op(h)), std::string("1x1 2x1 3x1 5x1 6x1 7x1 8x1 9x1 10x1"));
|
||||
CHECK_EQ((int)b.errors().size(), 0);
|
||||
}
|
||||
|
||||
TEST(a_weight_list_shorter_than_its_tables_is_refused_by_name) {
|
||||
NEED_PLUGIN(reg)
|
||||
Builder b(reg, make_meta(), make_ctx());
|
||||
std::vector<rad_weight> w;
|
||||
const size_t ops = b.program().ops.size();
|
||||
|
||||
/* Seven entries for eight tables leaves one empty, which no division can fill: refused at
|
||||
* declare, with the counts that say so. */
|
||||
CHECK_EQ(decl_moe(b, "short", 8, &w), RAD_NULL_HANDLE);
|
||||
CHECK_EQ(b.status(), RAD_E_SCHEMA);
|
||||
REQUIRE(!b.errors().empty());
|
||||
CHECK(has(b.errors().back(), "op 't_moe': 8 weight operands declared"));
|
||||
CHECK(has(b.errors().back(), "1 fixed weight operands and 8 weight TABLE operands"));
|
||||
CHECK(has(b.errors().back(), "so 7 leaves a table empty"));
|
||||
/* Nothing is recorded for the run phase to reach. */
|
||||
CHECK_EQ(b.program().ops.size(), ops);
|
||||
}
|
||||
|
||||
/* ================================================================== misses, reported whole */
|
||||
TEST(a_hole_in_the_range_is_reported_as_that_band) {
|
||||
NEED_PLUGIN(reg)
|
||||
|
||||
+20
-13
@@ -324,21 +324,27 @@ TEST(the_kv_cache_dtype_is_one_of_two_names) {
|
||||
CHECK_EQ(d.kv_cache_dtype, std::string("bf16"));
|
||||
}
|
||||
|
||||
TEST(the_ngram_table_is_on_disk_or_in_ram) {
|
||||
/* THE TWO TABLE PLACEMENTS take the same four names and nothing else, default to auto, and leave
|
||||
* the resolved values to Engine::plan: a parse never decides a tier. Where each table may go is
|
||||
* the engine's to refuse, with the model in hand -- not the parser's. */
|
||||
TEST(the_table_placements_are_auto_vram_ram_or_disk) {
|
||||
Config d;
|
||||
CHECK_EQ(parse({}, &d), RAD_OK);
|
||||
CHECK(!d.ngram_table_ram);
|
||||
CHECK(d.embedding_placement == TablePlacement::Auto);
|
||||
CHECK(d.ngram_placement == TablePlacement::Auto);
|
||||
Config c;
|
||||
CHECK_EQ(parse({ "--ngram-table", "ram" }, &c), RAD_OK);
|
||||
CHECK(c.ngram_table_ram);
|
||||
CHECK_EQ(parse({ "--ngram-table", "disk" }, &c), RAD_OK);
|
||||
CHECK(!c.ngram_table_ram);
|
||||
/* 47.7 GiB of locked memory is the operator's to give, so a name this build does not know
|
||||
* stops the server rather than picking either side. */
|
||||
CHECK_EQ(parse({ "--ngram-table", "memory" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--ngram-table", "RAM" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--ngram-table", "" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--ngram-table" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--embedding-placement", "ram", "--ngram-placement", "disk" }, &c), RAD_OK);
|
||||
CHECK(c.embedding_placement == TablePlacement::Ram);
|
||||
CHECK(c.ngram_placement == TablePlacement::Disk);
|
||||
CHECK_EQ(parse({ "--embedding-placement", "vram", "--ngram-placement", "auto" }, &c), RAD_OK);
|
||||
CHECK(c.embedding_placement == TablePlacement::Vram);
|
||||
CHECK(c.ngram_placement == TablePlacement::Auto);
|
||||
CHECK(c.embedding_resolved == TablePlacement::Vram); /* untouched until plan */
|
||||
for (const char* bad : { "RAM", "memory", "host", "" }) {
|
||||
CHECK_EQ(parse({ "--embedding-placement", bad }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--ngram-placement", bad }, &c), RAD_E_INVAL);
|
||||
}
|
||||
CHECK_EQ(parse({ "--ngram-placement" }, &c), RAD_E_INVAL);
|
||||
}
|
||||
|
||||
/* THE FLAG THAT DECIDES WHETHER MULTI-TURN WORKS. It is the WEIGHTS share, strictly inside
|
||||
@@ -814,7 +820,8 @@ TEST(usage_names_every_flag_it_documents) {
|
||||
CHECK(text.find("--checkpoint-policy") != std::string::npos);
|
||||
CHECK(text.find("--prefix-cache-host-mib") != std::string::npos);
|
||||
CHECK(text.find("--tp-wire") != std::string::npos);
|
||||
CHECK(text.find("--ngram-table") != std::string::npos);
|
||||
CHECK(text.find("--embedding-placement") != std::string::npos);
|
||||
CHECK(text.find("--ngram-placement") != std::string::npos);
|
||||
CHECK(text.find("--kld-record") != std::string::npos);
|
||||
CHECK(text.find("--kld-ref") != std::string::npos);
|
||||
for (const char* f : { "--default-max-tokens", "--max-tokens-cap", "--presence-penalty",
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
#include "rad_test.h"
|
||||
#include "format/radfile.h"
|
||||
#include "format/table_copy.h"
|
||||
#include "format/tunecache.h"
|
||||
#include "format/imatrix.h"
|
||||
#include "format/safetensors.h"
|
||||
@@ -426,6 +427,59 @@ TEST(fixed_stride_expert_addressing) {
|
||||
::unlink(b.path.c_str());
|
||||
}
|
||||
|
||||
/* --ngram-placement ram: A TABLE COPIED OUT OF THE CONTAINER INTO LOCKED MEMORY is the mapping's
|
||||
* bytes, every one of them, at an address no file backs; and a copy read from the wrong file offset
|
||||
* is refused by the check against the mapping rather than handed out. Small enough to lock under a
|
||||
* default RLIMIT_MEMLOCK, and an odd size so the copy's 2 MiB rounding is exercised. */
|
||||
TEST(a_table_copied_into_locked_memory_is_the_mapping_byte_for_byte) {
|
||||
const std::string p = tmp_path("tcopy");
|
||||
RadWriter w;
|
||||
REQUIRE(w.begin(p.c_str()) >= 0);
|
||||
w.set_arch("radtest");
|
||||
const RadWriter::Weight x = mkw("ngram.weight", plain_bf16(), 1500, 999, -1, -1, 0);
|
||||
const Planes want = planes_of(x, 5);
|
||||
REQUIRE(w.add_weight(x, want.ptr.data()) >= 0);
|
||||
/* A weight after it, so a read shifted past the table's end is still inside the file. */
|
||||
const RadWriter::Weight y = mkw("tail.weight", plain_bf16(), 64, 64, -1, -1, 0);
|
||||
const Planes ywant = planes_of(y, 6);
|
||||
REQUIRE(w.add_weight(y, ywant.ptr.data()) >= 0);
|
||||
REQUIRE(w.finish() >= 0);
|
||||
|
||||
RadFile f;
|
||||
REQUIRE(f.open(p.c_str()) >= 0);
|
||||
const RadFileEntry* e = f.find("ngram.weight");
|
||||
REQUIRE(e != nullptr);
|
||||
const RadFilePlane& pl = f.plane(*e, 0);
|
||||
const uint8_t* src = f.data(pl);
|
||||
const int64_t n = (int64_t)pl.bytes;
|
||||
CHECK_EQ(n, (int64_t)1500 * 999 * 2);
|
||||
|
||||
TableCopy c;
|
||||
std::string why;
|
||||
const int rc = table_copy_make(f, src, n, (int64_t)pl.offset, &c, &why);
|
||||
if (rc == RAD_E_NOMEM && why.find("mlock2") != std::string::npos) {
|
||||
std::fprintf(stderr, " SKIP %s: %s\n", ::radtest::current(), why.c_str());
|
||||
} else {
|
||||
CHECK_OK(rc);
|
||||
CHECK(c.base != nullptr && c.base != (const void*)src);
|
||||
CHECK_EQ(c.bytes % ((size_t)2 << 20), (size_t)0);
|
||||
CHECK(c.bytes >= (size_t)n);
|
||||
if (c.base) CHECK(std::memcmp(c.base, src, (size_t)n) == 0);
|
||||
table_copy_free(&c);
|
||||
CHECK(c.base == nullptr);
|
||||
|
||||
/* A sixteen-byte shift in the file offset reads real bytes from the wrong place. */
|
||||
TableCopy bad;
|
||||
std::string bwhy;
|
||||
CHECK_EQ(table_copy_make(f, src, n, (int64_t)pl.offset + 16, &bad, &bwhy), (int)RAD_E_IO);
|
||||
CHECK(bad.base == nullptr);
|
||||
CHECK(bwhy.find("does not match") != std::string::npos);
|
||||
}
|
||||
table_copy_free(&c); /* a copy never made, or freed already: a no-op */
|
||||
f.close();
|
||||
::unlink(p.c_str());
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ reserving and writing */
|
||||
TEST(a_weight_is_written_in_pieces_in_any_order) {
|
||||
const std::string p = tmp_path("pieces");
|
||||
|
||||
+130
-33
@@ -2237,7 +2237,7 @@ TEST(the_weight_footprint_splits_statics_from_the_elastic_expert_plane) {
|
||||
build_moe(f, /*n=*/4, /*each=*/2 * MiB, &experts);
|
||||
|
||||
WeightFootprint fp;
|
||||
weight_footprint(f.prog, &fp);
|
||||
weight_footprint(f.prog, &fp, TablePlacement::Vram);
|
||||
|
||||
/* One model-level weight and four experts: five units. */
|
||||
CHECK_EQ(fp.n_units, 5ll);
|
||||
@@ -2267,7 +2267,7 @@ TEST(weights_in_one_layer_are_one_unit_and_are_aligned_once_each) {
|
||||
}
|
||||
|
||||
WeightFootprint fp;
|
||||
weight_footprint(f.prog, &fp);
|
||||
weight_footprint(f.prog, &fp, TablePlacement::Vram);
|
||||
CHECK_EQ(fp.n_units, 2ll); /* the declared group is the unit, not the weight */
|
||||
|
||||
/* ONE align_up A UNIT AND ONE INSIDE IT, which is how Mover::init spends the slab. A budget
|
||||
@@ -2300,16 +2300,16 @@ TEST(a_weight_with_no_device_band_takes_its_whole_unit_to_the_mapped_tier) {
|
||||
f.prog.ops.push_back(host_only);
|
||||
|
||||
WeightFootprint fp;
|
||||
weight_footprint(f.prog, &fp);
|
||||
weight_footprint(f.prog, &fp, TablePlacement::Vram);
|
||||
CHECK_EQ(fp.n_units, 1ll);
|
||||
CHECK_EQ(fp.statics, 0ll);
|
||||
CHECK_EQ(fp.mapped, 6 * MiB); /* both weights: the unit is what moves */
|
||||
}
|
||||
|
||||
/* --host-weights. The fixture's embedding is read by an `embed_lookup`, as every arch declares it:
|
||||
* that is the only reader the flag accepts. */
|
||||
void build_dense_lookup(Fixture& f, int layers, int64_t per_layer) {
|
||||
const rad_weight m = f.weight("token_embd.weight", 1 * MiB, RAD_ACCESS_VOCAB, -1, -1);
|
||||
/* --embedding-placement. The fixture's embedding is read by an `embed_lookup`, as every arch
|
||||
* declares it, and its head by a GEMM: the first is the table the flag moves, the second never. */
|
||||
void build_dense_lookup(Fixture& f, int layers, int64_t per_layer, int64_t emb = 1 * MiB) {
|
||||
const rad_weight m = f.weight("token_embd.weight", emb, RAD_ACCESS_VOCAB, -1, -1);
|
||||
f.op("embed_lookup", {m}, false);
|
||||
for (int l = 0; l < layers; ++l) {
|
||||
const rad_weight w = f.weight("blk." + std::to_string(l) + ".ffn_down.weight", per_layer,
|
||||
@@ -2320,39 +2320,72 @@ void build_dense_lookup(Fixture& f, int layers, int64_t per_layer) {
|
||||
f.op("logits_gemm", {o}, false);
|
||||
}
|
||||
|
||||
/* A HOSTED WEIGHT IS IN THE HOST POOL, NOT ON THE CARD, and the footprint has to say so: the
|
||||
* resolver sizes a derived weight budget from `statics`, so a hosted weight counted there would
|
||||
* reserve VRAM the planner never spends. */
|
||||
TEST(host_weights_leave_the_statics_for_the_hosted_bucket) {
|
||||
/* An n-gram table: model-level, read only by `embed_lookup_q`, which only a host kernel serves. */
|
||||
rad_weight add_ngram_table(Fixture& f, int64_t bytes) {
|
||||
const rad_weight t = f.weight("ngram.weight", bytes, RAD_ACCESS_VOCAB, -1, -1);
|
||||
OpInfo o;
|
||||
o.op = "embed_lookup_q";
|
||||
o.index = (int32_t)f.prog.ops.size();
|
||||
o.weights = { t };
|
||||
Band hb;
|
||||
hb.hi = 1 << 20;
|
||||
hb.dom[RAD_DOMAIN_HOST].row = &g_host_row;
|
||||
hb.miss[RAD_DOMAIN_DEVICE] = "no device kernel";
|
||||
o.bands.push_back(hb);
|
||||
f.prog.ops.push_back(o);
|
||||
return t;
|
||||
}
|
||||
|
||||
/* THE TABLES ARE FOUND BY WHAT READS THEM. A model-level weight only embed_lookup reads is the
|
||||
* embedding; one only embed_lookup_q reads is an n-gram table; a head a GEMM reads is neither, and
|
||||
* neither is a table a GEMM reads beside the lookup -- a tied head would stream whole over the
|
||||
* link every step. Placed in RAM the embedding leaves the statics for the hosted bucket, because
|
||||
* the resolver sizes a derived weight budget from the statics. */
|
||||
TEST(the_placement_flags_find_their_tables_by_what_reads_them) {
|
||||
Fixture f;
|
||||
build_dense_lookup(f, /*layers=*/2, /*per_layer=*/4 * MiB);
|
||||
add_ngram_table(f, 8 * MiB);
|
||||
|
||||
WeightFootprint fp;
|
||||
weight_footprint(f.prog, &fp, {"token_embd.weight"});
|
||||
weight_footprint(f.prog, &fp, TablePlacement::Vram);
|
||||
CHECK_EQ(fp.embedding, 1 * MiB);
|
||||
CHECK_EQ(fp.ngram, 8 * MiB);
|
||||
CHECK(!fp.ngram_device);
|
||||
CHECK_EQ(fp.hosted, 0ll);
|
||||
CHECK_EQ(fp.statics, 2 * 4 * MiB + 2 * MiB);
|
||||
CHECK_EQ(fp.mapped, 8 * MiB);
|
||||
|
||||
weight_footprint(f.prog, &fp, TablePlacement::Ram);
|
||||
CHECK_EQ(fp.embedding, 1 * MiB);
|
||||
CHECK_EQ(fp.hosted, 1 * MiB);
|
||||
CHECK_EQ(fp.statics, 2 * 4 * MiB + 1 * MiB);
|
||||
|
||||
weight_footprint(f.prog, &fp, {"token_*"}); /* a trailing '*' is a prefix */
|
||||
CHECK_EQ(fp.hosted, 1 * MiB);
|
||||
CHECK(is_embedding_table(f.prog, 1));
|
||||
CHECK(!is_embedding_table(f.prog, 2)); /* a layer's GEMM operand */
|
||||
CHECK(!is_embedding_table(f.prog, 4)); /* the head */
|
||||
CHECK(is_ngram_table(f.prog, 5));
|
||||
CHECK(!is_ngram_table(f.prog, 1));
|
||||
|
||||
/* NEITHER A LAYER WEIGHT NOR A GEMM'S: layers belong to the offload strategies, and a GEMM
|
||||
operand would stream every step. */
|
||||
weight_footprint(f.prog, &fp, {"blk.*", "output.weight"});
|
||||
/* A head tied to the table: the same weight read by the lookup and the logits GEMM. */
|
||||
Fixture t;
|
||||
const rad_weight m = t.weight("token_embd.weight", 1 * MiB, RAD_ACCESS_VOCAB, -1, -1);
|
||||
t.op("embed_lookup", {m}, false);
|
||||
t.op("logits_gemm", {m}, false);
|
||||
CHECK(!is_embedding_table(t.prog, m));
|
||||
weight_footprint(t.prog, &fp, TablePlacement::Ram);
|
||||
CHECK_EQ(fp.embedding, 0ll);
|
||||
CHECK_EQ(fp.hosted, 0ll);
|
||||
|
||||
weight_footprint(f.prog, &fp); /* and none named is none hosted */
|
||||
CHECK_EQ(fp.hosted, 0ll);
|
||||
CHECK_EQ(fp.statics, 2 * 4 * MiB + 2 * MiB);
|
||||
}
|
||||
|
||||
TEST(host_weights_go_to_the_pinned_pool_read_in_place_and_cost_no_vram) {
|
||||
TEST(embedding_ram_goes_to_the_pinned_pool_read_in_place_and_costs_no_vram) {
|
||||
Fixture f;
|
||||
build_dense_lookup(f, /*layers=*/2, /*per_layer=*/4 * MiB);
|
||||
Config cfg = base_config();
|
||||
cfg.placement = "all_vram";
|
||||
cfg.vram_weights_mib = 9; /* layers and the head exactly: not the embedding */
|
||||
cfg.host_pool_mib = 2;
|
||||
cfg.host_weights = {"token_embd.weight"};
|
||||
cfg.embedding_placement = TablePlacement::Ram;
|
||||
cfg.embedding_resolved = TablePlacement::Ram;
|
||||
Plan plan;
|
||||
PlannerInput in{&f.prog, &cfg, 0, 1, nullptr, 0};
|
||||
CHECK_OK(Planner(in).plan(&plan));
|
||||
@@ -2361,31 +2394,69 @@ TEST(host_weights_go_to_the_pinned_pool_read_in_place_and_cost_no_vram) {
|
||||
CHECK(plan.weight[emb].tier == Tier::HostPinned);
|
||||
CHECK(plan.weight[emb].site == Site::DeviceZeroCopy);
|
||||
CHECK(!plan.units[(size_t)plan.weight[emb].unit].movable);
|
||||
CHECK_EQ(plan.host_weights_bytes, 1 * MiB);
|
||||
CHECK_EQ(plan.embedding_host_bytes, 1 * MiB);
|
||||
for (rad_weight w = 2; (size_t)w < f.prog.weights.size(); ++w)
|
||||
CHECK(plan.weight[w].tier == Tier::VRAM);
|
||||
|
||||
/* Vram, the default, leaves it with the other weights. */
|
||||
cfg.embedding_resolved = TablePlacement::Vram;
|
||||
cfg.vram_weights_mib = 10;
|
||||
Plan plan2;
|
||||
CHECK_OK(Planner(in).plan(&plan2));
|
||||
CHECK(plan2.weight[emb].tier == Tier::VRAM);
|
||||
CHECK_EQ(plan2.embedding_host_bytes, 0ll);
|
||||
}
|
||||
|
||||
TEST(host_weights_that_a_gemm_reads_are_refused) {
|
||||
/* A TABLE THAT IS NOT A WHOLE NUMBER OF PAGES still leaves the report's pinned total at what the
|
||||
* pooled units use: the pool slot is charged rounded up and the tier total counts weight bytes, so
|
||||
* the report subtracts the same weight bytes it added. */
|
||||
TEST(the_report_counts_a_hosted_embedding_once_in_one_unit) {
|
||||
Fixture f;
|
||||
build_dense_lookup(f, /*layers=*/1, /*per_layer=*/4 * MiB);
|
||||
build_dense_lookup(f, /*layers=*/1, /*per_layer=*/4 * MiB, /*emb=*/3 * MiB + 100);
|
||||
Config cfg = base_config();
|
||||
cfg.placement = "all_vram";
|
||||
cfg.host_pool_mib = 8;
|
||||
cfg.embedding_resolved = TablePlacement::Ram;
|
||||
Plan plan;
|
||||
PlannerInput in{&f.prog, &cfg, 0, 1, nullptr, 0};
|
||||
CHECK_OK(Planner(in).plan(&plan));
|
||||
CHECK_EQ(plan.embedding_host_used, 3 * MiB + 100);
|
||||
CHECK(plan.embedding_host_bytes >= plan.embedding_host_used);
|
||||
const std::string r = plan.report(f.prog);
|
||||
const size_t at = r.find("host pinned");
|
||||
CHECK(at != std::string::npos);
|
||||
if (at != std::string::npos) {
|
||||
const std::string line = r.substr(at, r.find('\n', at) - at);
|
||||
CHECK(line.find('-') == std::string::npos); /* no negative total */
|
||||
}
|
||||
CHECK(r.find("--embedding-placement ram") != std::string::npos);
|
||||
}
|
||||
|
||||
/* A plan resolved to Ram for a program with no table only embed_lookup reads is a budget split
|
||||
* for a different program; it refuses rather than leave the table on a card split without it. */
|
||||
TEST(embedding_ram_with_no_table_to_place_is_refused) {
|
||||
Fixture t;
|
||||
const rad_weight m = t.weight("token_embd.weight", 1 * MiB, RAD_ACCESS_VOCAB, -1, -1);
|
||||
t.op("embed_lookup", {m}, false);
|
||||
t.op("logits_gemm", {m}, false);
|
||||
Config cfg = base_config();
|
||||
cfg.placement = "all_vram";
|
||||
cfg.host_pool_mib = 4;
|
||||
cfg.host_weights = {"output.weight"};
|
||||
cfg.embedding_resolved = TablePlacement::Ram;
|
||||
Plan plan;
|
||||
PlannerInput in{&f.prog, &cfg, 0, 1, nullptr, 0};
|
||||
CHECK_EQ(Planner(in).plan(&plan), RAD_E_INVAL);
|
||||
PlannerInput in{&t.prog, &cfg, 0, 1, nullptr, 0};
|
||||
CHECK_EQ(Planner(in).plan(&plan), RAD_E_STATE);
|
||||
CHECK(!plan.notes.empty());
|
||||
CHECK(plan.weight[m].tier == Tier::VRAM);
|
||||
}
|
||||
|
||||
TEST(host_weights_that_do_not_fit_the_host_pool_are_refused_with_the_plan_filled_in) {
|
||||
TEST(embedding_ram_that_does_not_fit_the_host_pool_is_refused_with_the_plan_filled_in) {
|
||||
Fixture f;
|
||||
build_dense_lookup(f, /*layers=*/1, /*per_layer=*/4 * MiB);
|
||||
Config cfg = base_config();
|
||||
cfg.placement = "all_vram";
|
||||
cfg.host_pool_mib = 0; /* nowhere to put it */
|
||||
cfg.host_weights = {"token_embd.weight"};
|
||||
cfg.embedding_resolved = TablePlacement::Ram;
|
||||
Plan plan;
|
||||
PlannerInput in{&f.prog, &cfg, 0, 1, nullptr, 0};
|
||||
CHECK_EQ(Planner(in).plan(&plan), RAD_E_NOMEM);
|
||||
@@ -2393,16 +2464,42 @@ TEST(host_weights_that_do_not_fit_the_host_pool_are_refused_with_the_plan_filled
|
||||
CHECK(!plan.notes.empty());
|
||||
}
|
||||
|
||||
/* --ngram-placement ram leaves the table on the mapped tier, which no pool counts, and names the
|
||||
* copy the load phase makes: its reason says where the rows will come from, and the report what
|
||||
* the copy costs in RAM. */
|
||||
TEST(ngram_ram_stays_mapped_and_reports_the_copy) {
|
||||
Fixture f;
|
||||
build_dense_lookup(f, /*layers=*/1, /*per_layer=*/4 * MiB);
|
||||
const rad_weight t = add_ngram_table(f, 8 * MiB);
|
||||
Config cfg = base_config();
|
||||
cfg.placement = "all_vram";
|
||||
cfg.ngram_resolved = TablePlacement::Ram;
|
||||
Plan plan;
|
||||
PlannerInput in{&f.prog, &cfg, 0, 1, nullptr, 0};
|
||||
CHECK_OK(Planner(in).plan(&plan));
|
||||
CHECK(plan.weight[t].tier == Tier::Mapped);
|
||||
CHECK(plan.weight[t].site == Site::Host);
|
||||
CHECK_EQ(plan.ngram_copy_bytes, 8 * MiB);
|
||||
CHECK(std::string(plan.weight[t].reason).find("--ngram-placement ram") != std::string::npos);
|
||||
CHECK(plan.report(f.prog).find("n-gram copy") != std::string::npos);
|
||||
|
||||
cfg.ngram_resolved = TablePlacement::Disk;
|
||||
Plan plan2;
|
||||
CHECK_OK(Planner(in).plan(&plan2));
|
||||
CHECK_EQ(plan2.ngram_copy_bytes, 0ll);
|
||||
CHECK(plan2.report(f.prog).find("n-gram copy") == std::string::npos);
|
||||
}
|
||||
|
||||
TEST(an_empty_program_has_an_empty_footprint) {
|
||||
Fixture f;
|
||||
WeightFootprint fp;
|
||||
fp.statics = 1; /* and the out parameter is reset, not accumulated */
|
||||
weight_footprint(f.prog, &fp);
|
||||
weight_footprint(f.prog, &fp, TablePlacement::Vram);
|
||||
CHECK_EQ(fp.statics, 0ll);
|
||||
CHECK_EQ(fp.experts, 0ll);
|
||||
CHECK_EQ(fp.mapped, 0ll);
|
||||
CHECK_EQ(fp.n_units, 0ll);
|
||||
weight_footprint(f.prog, nullptr); /* and a null one is not a crash */
|
||||
weight_footprint(f.prog, nullptr, TablePlacement::Vram); /* and a null one is not a crash */
|
||||
}
|
||||
|
||||
RAD_TEST_MAIN()
|
||||
+58
-3
@@ -119,8 +119,8 @@ TEST(loading_reads_identity_and_calls_open) {
|
||||
if (!base) return;
|
||||
CHECK_EQ((int)base->kind, RAD_PLUGIN_KERNEL);
|
||||
CHECK_EQ(base->version, "0.1");
|
||||
CHECK_EQ(base->n_kernels, 16);
|
||||
CHECK_EQ(base->n_schemas, 9);
|
||||
CHECK_EQ(base->n_kernels, 17);
|
||||
CHECK_EQ(base->n_schemas, 10);
|
||||
|
||||
/* The optional open hook runs once, after load and before any selection. */
|
||||
auto open_calls = reinterpret_cast<int (*)(void)>(dlsym(base->handle, "radtest_open_calls"));
|
||||
@@ -286,7 +286,7 @@ TEST(every_row_s_op_has_a_schema) {
|
||||
CHECK_OK(load(r));
|
||||
CHECK_OK(r.check_complete());
|
||||
const auto ops = r.op_names();
|
||||
CHECK_EQ(ops.size(), (size_t)9);
|
||||
CHECK_EQ(ops.size(), (size_t)10);
|
||||
CHECK_EQ(ops[0], "t_attn");
|
||||
}
|
||||
|
||||
@@ -881,4 +881,59 @@ TEST(libr4d_resolves_the_all_reduce_by_message_size) {
|
||||
}
|
||||
}
|
||||
|
||||
/* THE FOUR-RANK FUSED WRITES SERVE THE EXACT WIRE ONLY, AND SAY SO IN SELECTION. A caller states
|
||||
* `wire` 0 for the exact form and gets the four-rank rows; a request for the rotated wire at four
|
||||
* ranks is a miss that names `wire`, so the caller keeps its unfused pair -- not a row that
|
||||
* matches and then refuses its instance, which would stop declare. At two ranks both wires keep
|
||||
* their row. Geometry is Qwen3.8-Flash-Next's: 2560 wide, four streams, top-k 10, declared over a
|
||||
* decode or verify step of 8 sequences at depth 3. */
|
||||
TEST(libr4d_resolves_the_four_rank_fused_writes_on_the_exact_wire_only) {
|
||||
const std::string so = home() + "/kernels/libr4d.so";
|
||||
if (access(so.c_str(), R_OK) != 0) {
|
||||
fprintf(stderr, " SKIP %s: no %s (a build without HIP)\n", ::radtest::current(),
|
||||
so.c_str());
|
||||
return;
|
||||
}
|
||||
Registry r;
|
||||
CHECK(r.load_plugin(so, 0) >= 0);
|
||||
r.set_device_fact(RAD_FACT_P2P, 1);
|
||||
|
||||
const int64_t rows = 8 * (1 + 3);
|
||||
auto bands = [&](const std::string& op, int world, int wire) {
|
||||
Geometry g;
|
||||
g.set_i("n", 2560);
|
||||
g.set_i("hc", 4);
|
||||
g.set_i("world_size", world);
|
||||
g.set_s("dtype", "bf16");
|
||||
g.set_i("wire", wire);
|
||||
if (op == "ar_gather_hc_write") {
|
||||
g.set_i("top_k", 10);
|
||||
g.set_s("act", "sigmoid");
|
||||
}
|
||||
return r.build_bands(op, "M", 1, rows, g);
|
||||
};
|
||||
auto names = [](const std::vector<Band>& b) {
|
||||
std::string s;
|
||||
for (const Band& x : b)
|
||||
s += fmt("%lld:%s ", (long long)x.hi, picked(x.dom[RAD_DOMAIN_DEVICE].row).c_str());
|
||||
return s;
|
||||
};
|
||||
|
||||
CHECK_EQ(names(bands("ar_hc_write", 4, 0)), "32:ar_hc_write_4rank ");
|
||||
CHECK_EQ(names(bands("ar_gather_hc_write", 4, 0)), "32:ar_gather_hc_write_4rank ");
|
||||
for (int wire : { 0, 6 }) {
|
||||
CHECK_EQ(names(bands("ar_hc_write", 2, wire)), "32:ar_hc_write ");
|
||||
CHECK_EQ(names(bands("ar_gather_hc_write", 2, wire)), "32:ar_gather_hc_write ");
|
||||
}
|
||||
|
||||
for (const char* op : { "ar_hc_write", "ar_gather_hc_write" }) {
|
||||
const std::vector<Band> none = bands(op, 4, 6);
|
||||
CHECK(!none.empty());
|
||||
for (const Band& b : none) {
|
||||
CHECK(!b.dom[RAD_DOMAIN_DEVICE]);
|
||||
CHECK(has(b.miss[RAD_DOMAIN_DEVICE], "wire"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RAD_TEST_MAIN()
|
||||
@@ -2072,6 +2072,28 @@ TEST(op_moe_gemm_q_scale_grid_by_dtype) {
|
||||
CHECK_EQ(y.at(0), 160.0f); /* 0.5 * (64*1*2 + 64*1*3) */
|
||||
CHECK_EQ(y.at(1), 320.0f); /* 0.5 * (64*2*2 + 64*2*3) */
|
||||
}
|
||||
|
||||
/* A dtype that names none of those grids -- a format of another op, or no dtype at all -- is
|
||||
* declined for every operand, the scale planes and the rest: a plane sized on a guessed grid
|
||||
* is a tensor of the wrong extent. */
|
||||
for (const char* op : { "moe_gemm_q", "moe_gemm_q_mod4" }) {
|
||||
const RadKernelInfo* k = kern(op);
|
||||
REQUIRE(k != nullptr && k->opd_shape != nullptr);
|
||||
for (const char* dt : { "w8a8", "mxfp4a8", "" }) {
|
||||
A a;
|
||||
a.i("M", 2).i("N", 256).i("K", 512).i("n_expert", 8).i("top_k", 2).i("group", 128)
|
||||
.s("a_order", "token");
|
||||
if (*dt) a.s("dtype", dt);
|
||||
const RadArgs* r = a.get();
|
||||
for (int opd : { 0, 2, 3 }) {
|
||||
RadOpdDesc d{};
|
||||
if (k->opd_shape(r->p, r->n_p, opd, &d) != RAD_E_UNSUPPORTED)
|
||||
std::fprintf(stderr, " %s at dtype '%s': operand %d described\n", op, dt,
|
||||
opd);
|
||||
CHECK_EQ(k->opd_shape(r->p, r->n_p, opd, &d), RAD_E_UNSUPPORTED);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(op_moe_chain) {
|
||||
|
||||
@@ -667,6 +667,72 @@ TEST(a_weight_table_resolves_only_the_entries_that_moved) {
|
||||
CHECK_EQ(res.lookups, before + 4);
|
||||
}
|
||||
|
||||
/* A TABLE'S RUN IS THE DECLARATION'S. The weights declared at a table position (OpInfo::
|
||||
* weight_opd) are bound as one table before the first step. A declared run with a gap in it is
|
||||
* refused there -- the kernel is handed one base and strides through it, so a gap is a wrong
|
||||
* expert read -- and an issue naming any other run than the bound one is refused at issue, by
|
||||
* name, rather than handed a table of other experts. */
|
||||
TEST(a_weight_table_issued_against_its_declaration_is_refused) {
|
||||
static const RadOperandSpec opds[] = {
|
||||
{ "a", RAD_OPD_IN, 0 }, { "b", RAD_OPD_WTAB, 0 }, { "y", RAD_OPD_OUT, 0 },
|
||||
};
|
||||
static const RadOpSchema schema = {
|
||||
"moe_gemm", g_gemm_params, 4, opds, 3, "A[M,K] x B[e][N,K]^T -> Y[M,N]"
|
||||
};
|
||||
static uint16_t expert_bytes[4][32];
|
||||
auto experts = [](Fixture& f) {
|
||||
std::vector<rad_weight> w;
|
||||
for (int e = 0; e < 4; ++e)
|
||||
w.push_back(f.add_weight(("blk.0.e" + std::to_string(e)).c_str(), RAD_BF16, 8, 4,
|
||||
expert_bytes[e]));
|
||||
return w;
|
||||
};
|
||||
|
||||
{
|
||||
/* Experts 0, 1 and 3 at the table, 2 missing from the run: refused when the tables are
|
||||
* bound, so the Ctx never runs a step. */
|
||||
Fixture f;
|
||||
const std::vector<rad_weight> w = experts(f);
|
||||
f.add_buffer("x", RAD_BF16, 64, 4, 0);
|
||||
f.add_buffer("y", RAD_BF16, 64, 8, 1024);
|
||||
rad_op op = f.add_op("moe_gemm", "M", { 8192 }, { k_pre }, { "prefill" }, &schema,
|
||||
{ w[0], w[1], w[3] });
|
||||
f.P.ops[op].weight_opd = { 1, 1, 1 };
|
||||
CHECK_EQ(f.start(), RAD_E_INVAL);
|
||||
}
|
||||
|
||||
Fixture f;
|
||||
const std::vector<rad_weight> w = experts(f);
|
||||
rad_buf x = f.add_buffer("x", RAD_BF16, 64, 4, 0);
|
||||
rad_buf y = f.add_buffer("y", RAD_BF16, 64, 8, 1024);
|
||||
rad_op op = f.add_op("moe_gemm", "M", { 8192 }, { k_pre }, { "prefill" }, &schema, w);
|
||||
f.P.ops[op].weight_opd = { 1, 1, 1, 1 };
|
||||
CHECK_OK(f.start());
|
||||
|
||||
/* The declared run is served. */
|
||||
g_rec.clear();
|
||||
CHECK_OK(f.step(4, 0, [&](Ctx& c) {
|
||||
RadOperand opd[3] = { RAD_B(x), RAD_WTAB(w[0], 4), RAD_B(y) };
|
||||
CHECK_OK(c.issue(op, opd, 3, RAD_N_BATCH));
|
||||
}));
|
||||
CHECK_EQ(g_rec.size(), (size_t)1);
|
||||
|
||||
/* One entry short, and the same length one expert along: both name experts the declaration
|
||||
* did not put at this table, and neither reaches the kernel. */
|
||||
int step_no = 1;
|
||||
for (const RadOperand tab : { RAD_WTAB(w[0], 3), RAD_WTAB(w[1], 3) }) {
|
||||
g_rec.clear();
|
||||
const int s = f.step(4, step_no++, [&](Ctx& c) {
|
||||
RadOperand opd[3] = { RAD_B(x), tab, RAD_B(y) };
|
||||
c.issue(op, opd, 3, RAD_N_BATCH);
|
||||
});
|
||||
CHECK_EQ(s, RAD_E_INVAL);
|
||||
CHECK_EQ(g_rec.size(), (size_t)0);
|
||||
CHECK(std::strstr(f.ctx.step_error(), "A table's run is fixed by the declaration") !=
|
||||
nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
/* Routing never blocks the compute stream: the histogram is copied back asynchronously and the
|
||||
* heat engine DRAINS it on a later step (spec §5.5). */
|
||||
TEST(route_report_is_asynchronous_and_drains_oldest_first) {
|
||||
|
||||
Reference in new issue
Block a user