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
@@ -595,9 +595,6 @@ struct Geom {
|
||||
* message anyway. Straight through to `all_reduce`'s `min_bytes`; 0 leaves the choice to
|
||||
* the kernel plugin, which has the measured default. */
|
||||
int64_t wire_min_bytes = 0;
|
||||
/* 1 = keep a file-backed table a host gather reads in RAM (--ngram-table ram). Straight
|
||||
* through to `embed_lookup_q`'s `resident`; RadBuildCtx says what it costs and buys. */
|
||||
int ngram_ram = 0;
|
||||
float eps = 1e-6f;
|
||||
/* GemmaRMSNorm's `1 +`. Qwen3.5, Qwen3-Next and Gemma normalise with `x_hat * (1 + w)` and
|
||||
* store `w` around 0.1, not around 1.0 -- so reading the gain as a plain RMSNorm gain shrinks
|
||||
@@ -735,7 +732,6 @@ inline int geom_from(Geom& g, const RadModelMeta* m, const RadBuildCtx* c,
|
||||
g.world = c->world_size ? c->world_size : 1;
|
||||
g.wire_exact= c->tp_wire_lossy ? 0 : 1;
|
||||
g.wire_min_bytes = c->tp_wire_min_bytes;
|
||||
g.ngram_ram = c->ngram_table_ram ? 1 : 0;
|
||||
g.eps = m->rms_eps;
|
||||
g.theta = m->rope_theta;
|
||||
g.rope_scale= m->rope_scale ? m->rope_scale : 1.0f;
|
||||
|
||||
+20
-10
@@ -295,15 +295,21 @@ inline int HyperConn::declare(RadBuilder* b, Names& nm, const Geom& geom, const
|
||||
if (!op_write) return RAD_E_INVAL;
|
||||
/* A handle that did not resolve is 0 and not an error: a backend without the fused kernel
|
||||
* keeps the pair, and takes_ar() then answers no on every step. At four ranks only the
|
||||
* exact form exists, and it takes a step only where ar_wide_write_exact says the
|
||||
* standalone collective would have been the exact one-shot. */
|
||||
if (c.reduce && (g.world == 2 || g.world == 4))
|
||||
* exact form exists, declared over the decode and verify steps' rows and taken where
|
||||
* ar_wide_write_exact says so. The exact form states `wire` 0 rather than leaving it out:
|
||||
* a row that serves one wire only says so with a constraint on `wire`, and a constraint on
|
||||
* an absent key does not hold. */
|
||||
const int64_t ar_rows = ar_exact_write_rows(g);
|
||||
if (c.reduce && ar_rows >= 1)
|
||||
op_ar_write = rw(b, RAD_OP(b, "ar_hc_write",
|
||||
RAD_PARAMS(RAD_RANGE("M", 1, g.max_tok), RAD_INT("n", g.n_embd),
|
||||
RAD_PARAMS(RAD_RANGE("M", 1, ar_rows), RAD_INT("n", g.n_embd),
|
||||
RAD_INT("hc", c.hc), RAD_INT("world_size", g.world),
|
||||
RAD_STR("dtype", g.dtype)),
|
||||
RAD_STR("dtype", g.dtype), RAD_INT("wire", 0)),
|
||||
RAD_NOWEIGHTS),
|
||||
{w.x.x, w.inj, w.h}, {w.x.x, w.h});
|
||||
/* The rotated form at two ranks only: the op has no four-rank form on that wire
|
||||
* (docs/OPS.md), and an op declared that nothing resolves is reported at startup as a
|
||||
* band a request cannot run in. */
|
||||
if (op_ar_write && !g.wire_exact && g.world == 2)
|
||||
op_ar_write6 = rw(b, RAD_OP(b, "ar_hc_write",
|
||||
RAD_PARAMS(RAD_RANGE("M", 1, g.max_tok), RAD_INT("n", g.n_embd),
|
||||
@@ -323,11 +329,14 @@ inline int HyperConn::declare_gather(RadBuilder* b, const GatherSrc& src) {
|
||||
if (g.world != 2 && g.world != 4) return RAD_OK;
|
||||
const bool shared = src.sh && src.sg;
|
||||
gsrc = src;
|
||||
/* EVERY ROW COUNT ONE PASS CARRIES, prefill chunks included: the kernel reads its slots from
|
||||
* an LDS table at a decode step and from an inverse table at a chunk, where the gather's reads
|
||||
* then run beside the reduction's push instead of in a launch of their own. */
|
||||
/* EVERY ROW COUNT ONE PASS CARRIES, up to the rows the write itself was declared for
|
||||
* (ar_exact_write_rows): prefill chunks included at two ranks, the decode and verify steps at
|
||||
* four. The kernel reads its slots from an LDS table at a decode step and from an inverse
|
||||
* table at a chunk, where the gather's reads then run beside the reduction's push instead of
|
||||
* in a launch of their own. */
|
||||
int64_t rows = src.rows;
|
||||
if (rows > g.max_tok) rows = g.max_tok;
|
||||
const int64_t ar_rows = ar_exact_write_rows(g);
|
||||
if (rows > ar_rows) rows = ar_rows;
|
||||
if (rows < 1) return RAD_OK;
|
||||
const rad_buf rd[8] = { src.ye, src.ew, src.sorted, w.x.x, w.inj, w.h, src.sh, src.sg };
|
||||
const rad_buf wr[2] = { w.x.x, w.h };
|
||||
@@ -339,7 +348,8 @@ inline int HyperConn::declare_gather(RadBuilder* b, const GatherSrc& src) {
|
||||
RAD_INT("hc", c.hc), RAD_INT("top_k", src.top_k),
|
||||
RAD_INT("world_size", g.world),
|
||||
RAD_STR("dtype", g.dtype),
|
||||
RAD_STR("act", shared ? "sigmoid" : "none")),
|
||||
RAD_STR("act", shared ? "sigmoid" : "none"),
|
||||
RAD_INT("wire", 0)),
|
||||
RAD_NOWEIGHTS);
|
||||
if (op_ar_gather_write) {
|
||||
RAD_ARCH_TRY(rad_op_reads (b, op_ar_gather_write, rd, shared ? 8 : 6));
|
||||
|
||||
@@ -198,12 +198,6 @@ struct MoeFP8 {
|
||||
* The arm's stages run behind the routed ones on the same queue (see pass()): a routed
|
||||
* GEMM's tail leaves compute units idle, and the arm fills them. */
|
||||
int64_t shared_lo = 0, shared_hi = 0;
|
||||
/* THIS RANK'S PLACE WHERE THE PLAIN EXPERTS' 64-WIDE TILES DO NOT DIVIDE over the ranks:
|
||||
* the first places take one tile more. -1 is the rank's own index. A permutation of the
|
||||
* ranks, the same on every rank, so every tile still has exactly one owner; the
|
||||
* architecture sets it above two ranks to keep the extra tiles off the ranks that already
|
||||
* take the routed experts' extra blocks. */
|
||||
int64_t extra_place = -1;
|
||||
int norm_topk = 1; /* renormalise the kept routing weights to sum to one */
|
||||
/* THE EXPERT WEIGHT AT FOUR BITS rather than E4M3, which for Qwen3.8-Flash-Next is the
|
||||
* difference between a model that fits two cards and one that does not (the registry row
|
||||
@@ -1144,12 +1138,12 @@ inline int MoeFP8::declare(RadBuilder* b, Names& nm, const Geom& geom, int l,
|
||||
/* ONE SLICE A RANK, and it does not have to be the same size on every rank: an uneven
|
||||
* share of the 64-wide tiles is still whole tiles, and an uneven share is the only
|
||||
* kind available when the width does not divide -- this family's 640 columns are ten
|
||||
* tiles, which four ranks take as 2, 2, 3, 3 (Config::extra_place puts ranks 2 and 3
|
||||
* first, the ranks without a routed extra block). Every tile has exactly one owner,
|
||||
* each rank writes its own columns of gate/up and reads its own of down, and the
|
||||
* block's all-reduce sums the partials exactly as it does for the quantised experts
|
||||
* and for the shared arm. The even case keeps the even-split declaration verbatim --
|
||||
* no span at all -- so a rank count that divides declares exactly as it did before. */
|
||||
* tiles, which four ranks take as 3, 3, 2, 2, the first ranks by index taking the
|
||||
* extra ones. Every tile has exactly one owner, each rank writes its own columns of
|
||||
* gate/up and reads its own of down, and the block's all-reduce sums the partials
|
||||
* exactly as it does for the quantised experts and for the shared arm. The even case
|
||||
* keeps the even-split declaration verbatim -- no span at all -- so a rank count that
|
||||
* divides declares exactly as it did before. */
|
||||
psh_row = RAD_SHARD_ROW;
|
||||
psh_col = RAD_SHARD_COL;
|
||||
pparts = 2;
|
||||
@@ -1161,16 +1155,8 @@ inline int MoeFP8::declare(RadBuilder* b, Names& nm, const Geom& geom, int l,
|
||||
return RAD_E_INVAL;
|
||||
} else {
|
||||
const int64_t nt = full / 64, base = nt / g.world, extra = nt % g.world;
|
||||
/* Cut by the rank's place (Config::extra_place), not necessarily its index --
|
||||
* except in a layer served at four classes. The place exists to keep these tiles
|
||||
* off the ranks holding the routed extra blocks, and at four classes every rank
|
||||
* holds one; the shared expert's extra block is cut by the same place, so the
|
||||
* rank's own index keeps the two remainders apart instead. */
|
||||
const int64_t pr = (c.extra_place >= 0 && ncls != 4) ? c.extra_place
|
||||
: (int64_t)g.rank;
|
||||
if (pr >= g.world) return RAD_E_INVAL;
|
||||
const int64_t t0 = pr * base + std::min<int64_t>(pr, extra);
|
||||
const int64_t t1 = t0 + base + (pr < extra ? 1 : 0);
|
||||
const int64_t t0 = (int64_t)g.rank * base + std::min<int64_t>(g.rank, extra);
|
||||
const int64_t t1 = t0 + base + ((int64_t)g.rank < extra ? 1 : 0);
|
||||
plo = t0 * 64;
|
||||
phi = t1 * 64;
|
||||
wp = phi - plo;
|
||||
|
||||
+11
-10
@@ -367,18 +367,19 @@ inline int PleLayer::declare(RadBuilder* b, Names& nm, const Geom& geom, const C
|
||||
{}, {b_ids});
|
||||
|
||||
/* M IS T * heads HERE, not T: the gather fetches one table row per HEAD per token, and the
|
||||
* band this op resolves on is that count. `resident` only when the deployment asked for the
|
||||
* table in RAM (--ngram-table ram), so the default declares exactly the op it always has. */
|
||||
const RadParam gp[] = { RAD_RANGE("M", 1, g.max_tok * c.heads), RAD_INT("n_embd", HD),
|
||||
RAD_INT("n_vocab", c.rows), RAD_STR("dtype", g.dtype),
|
||||
RAD_INT("resident", 1) };
|
||||
const int n_gp = g.ngram_ram ? 5 : 4;
|
||||
* band this op resolves on is that count. */
|
||||
if (table_bf16)
|
||||
op_gather = rw(b, RAD_OP(b, "embed_lookup_q", gp, n_gp, RAD_WEIGHTS(w_table)),
|
||||
{b_ids}, {b_emb});
|
||||
op_gather = rw(b, RAD_OP(b, "embed_lookup_q",
|
||||
RAD_PARAMS(RAD_RANGE("M", 1, g.max_tok * c.heads), RAD_INT("n_embd", HD),
|
||||
RAD_INT("n_vocab", c.rows), RAD_STR("dtype", g.dtype)),
|
||||
RAD_WEIGHTS(w_table)),
|
||||
{b_ids}, {b_emb});
|
||||
else
|
||||
op_gather = rw(b, RAD_OP(b, "embed_lookup_q", gp, n_gp, RAD_WEIGHTS(w_table, w_scale)),
|
||||
{b_ids}, {b_emb});
|
||||
op_gather = rw(b, RAD_OP(b, "embed_lookup_q",
|
||||
RAD_PARAMS(RAD_RANGE("M", 1, g.max_tok * c.heads), RAD_INT("n_embd", HD),
|
||||
RAD_INT("n_vocab", c.rows), RAD_STR("dtype", g.dtype)),
|
||||
RAD_WEIGHTS(w_table, w_scale)),
|
||||
{b_ids}, {b_emb});
|
||||
|
||||
op_embd = rw(b, RAD_OP(b, "cast",
|
||||
RAD_PARAMS(RAD_RANGE("M", 1, g.max_tok), RAD_INT("n", c.embed_dim),
|
||||
|
||||
+42
-21
@@ -324,33 +324,53 @@ inline bool ar_fused_ok(const Geom& g, int64_t T) {
|
||||
return ar_wire_is_exact(g, T) || (g.n_embd % kArWire6Chunk) == 0;
|
||||
}
|
||||
|
||||
/* THE FOUR-RANK LOSSY WIRE'S TILE: tiered int8 in groups of 32, and a group may not straddle one
|
||||
* of the four shards, so a message whose element count is not a multiple of 128 goes out exact.
|
||||
* Stated here for the reason the rotation's group of 64 is stated in ar_wire_is_exact: the
|
||||
* architecture has to decide, identically on every rank, which wire a step's message takes. */
|
||||
static const int64_t kArWideWireTile = 128;
|
||||
|
||||
/* THE MOST ROWS A DECODE OR SPECULATIVE-VERIFY STEP CARRIES: one a sequence, and 1 + max_spec a
|
||||
* sequence at a verify (max_spec is 0 with speculation off), never more than max_tok. It is a fact
|
||||
* about this engine's own steps, which is why the architecture holds it. The four-rank fused write
|
||||
* and its gather are declared over M up to this, and ar_wide_write_exact takes no step above it, so
|
||||
* a step sent to them is always inside the range they were resolved for. */
|
||||
inline int64_t ar_wide_write_rows(const Geom& g) {
|
||||
const int64_t r = g.max_seqs * (1 + (g.max_spec > 0 ? g.max_spec : 0));
|
||||
return r < g.max_tok ? r : g.max_tok;
|
||||
}
|
||||
|
||||
/* THE ROWS THE EXACT FUSED WRITE IS DECLARED FOR: every step at two ranks, the decode and verify
|
||||
* steps at four (ar_wide_write_rows), and none at any other width. */
|
||||
inline int64_t ar_exact_write_rows(const Geom& g) {
|
||||
if (g.world == 2) return g.max_tok;
|
||||
if (g.world == 4) return ar_wide_write_rows(g);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* THE FOUR-RANK FUSED WRITE'S STEPS. At four ranks ar_hc_write exists on the exact wire only, and
|
||||
* it is the exact ONE-SHOT with the write behind it -- so it may take a message only where the
|
||||
* standalone `all_reduce` would have sent that message exact and as a one-shot:
|
||||
* it is the exact ONE-SHOT with the write behind it. A step takes it where both of these hold:
|
||||
*
|
||||
* exact --tp-wire exact, or a message the four-rank lossy row serves exactly itself: its
|
||||
* tiered-int8 groups of 32 must tile each of the four shards (numel % 128), and below
|
||||
* `min_bytes` it hands the message to the exact entry. ar_wire_is_exact's three facts,
|
||||
* with that wire's tile.
|
||||
* one-shot under 1 MiB. From there libr4d's exact entry runs the two-shot instead
|
||||
* (R4D_AR_EXACT_TWOSHOT_MIN_BYTES, r4d_ar_entry.hip), which moves half the bytes, so
|
||||
* the pair stays. Either way the bytes are the same; this bound is a cost, not a
|
||||
* correctness line.
|
||||
* rows T is at most ar_wide_write_rows. The fused kernel is a one-shot, and the messages a
|
||||
* one-shot is for are the decode and verify steps'. A larger step -- a prefill chunk --
|
||||
* keeps the pair, and there the standalone `all_reduce`'s own size bands choose the
|
||||
* one-shot or the two-shot: where that choice falls is the kernel library's to say,
|
||||
* so the architecture holds no copy of it. The fused one-shot serves any message it was
|
||||
* declared for with the same bytes, so this bound is a cost, not a correctness line.
|
||||
* exact --tp-wire exact, or a message the four-rank lossy row serves exactly itself: one
|
||||
* kArWideWireTile does not tile, or one under `min_bytes`, both of which that row hands
|
||||
* to the exact sum. ar_wire_is_exact's three facts, with that wire's tile.
|
||||
*
|
||||
* ar_wire_is_exact itself stays false off two ranks: the embedding's collective asks it whether
|
||||
* layer 0's fused norm absorbs that reduction, and at four no norm does. Both ranks evaluate this
|
||||
* on the same T, so neither can take a different branch. */
|
||||
static const int64_t kArWideWireTile = 128;
|
||||
static const int64_t kArWideOneshotBytes = 1024 * 1024;
|
||||
|
||||
* layer 0's fused norm absorbs that reduction, and at four no norm does. Every rank evaluates this
|
||||
* on the same T, so none can take a different branch. */
|
||||
inline bool ar_wide_write_exact(const Geom& g, int64_t T) {
|
||||
if (g.world != 4) return false;
|
||||
if (g.world != 4 || T < 1 || T > ar_wide_write_rows(g)) return false;
|
||||
const int64_t numel = T * g.n_embd;
|
||||
const int64_t bytes = numel * 2; /* bf16 on the wire */
|
||||
if (numel <= 0 || bytes >= kArWideOneshotBytes) return false;
|
||||
if (numel <= 0) return false;
|
||||
if (g.wire_exact) return true;
|
||||
if (numel % kArWideWireTile) return true;
|
||||
return bytes < g.wire_min_bytes;
|
||||
return numel * 2 < g.wire_min_bytes; /* bf16 on the wire */
|
||||
}
|
||||
|
||||
/* WHETHER A GATED RESIDUAL'S EXACT FUSED WRITE TAKES THE ALL-REDUCE AT T ROWS: at two ranks on every
|
||||
@@ -367,7 +387,7 @@ inline bool ar_exact_write_takes(const Geom& g, int64_t T) {
|
||||
* (ar_fused_ok);
|
||||
* kArOutExact a gated residual's write with the exact fused form only, so a message that would
|
||||
* go out compressed stays with the block (ar_exact_write_takes -- at four ranks
|
||||
* also one the standalone row would send as a two-shot);
|
||||
* also one of a step larger than a decode or verify step);
|
||||
* kArOutBoth a gated residual's write with a fused form on each wire, which takes every
|
||||
* message (HyperConn::ar_take). */
|
||||
enum ArOut : int {
|
||||
@@ -390,7 +410,8 @@ inline bool ar_taken(const Geom& g, int64_t T, bool out, int take) {
|
||||
* wire, 0 where it was not: at most the tokens one MoE pass carries, so a step it serves is one
|
||||
* pass whose gather is the whole step's. The wire the step's message goes out on picks the bound:
|
||||
* the exact one wherever the exact fused write takes the step (ar_exact_write_takes -- at two
|
||||
* ranks ar_wire_is_exact itself, at four the exact one-shot's steps, where `rows6` is always 0).
|
||||
* ranks ar_wire_is_exact itself, at four the decode and verify steps on the exact wire, where
|
||||
* `rows6` is always 0).
|
||||
* The block that would issue the gather and the write that would absorb it ask this of the same T
|
||||
* and the same bounds, so neither can skip it while the other issues it. */
|
||||
inline bool gather_taken(const Geom& g, int64_t T, int64_t rows, int64_t rows6) {
|
||||
|
||||
Reference in new issue
Block a user