Archived
tests and docs for the attention world
arch_test: flashnext_tp3_zeroes_the_third_ranks_attention_and_splits_gdn_heads_unevenly holds the three-rank declaration of the Flash-Next fixture: the three programs declare the same ops and KV groups in the same order; every rank the two-rank attention geometry with the span of its heads, rank 2 zero; the delta net 6/5/5 K and 18/15/15 V heads as per-part spans of [q|k|v|z] and the conv channels, a span of A_log, the output columns, and the state group at each rank's own V count. The fake builder records the two new exports as it records the span. The TP4 case's "world 3 is refused" check becomes "world 3 declares". docs/TP3.md is rewritten: what replaced the padded checkpoint, the two rules, what they are built from, the serve line and the log lines. The pad tools stay in the tree for an engine without an attention world.
This commit is contained in:
1 parent
45963012ee
commit
d72b00bfdb
2 files changed
+250
-104
No files matched your search
+82
-101
@@ -1,124 +1,105 @@
|
||||
# Three ranks: padding a checkpoint to a world its geometry does not divide
|
||||
# Any world size: the attention world, uneven delta-net heads, and nothing padded
|
||||
|
||||
Radiance shards by dividing: `n_head`, `n_head_kv`, the GDN head counts and the vocabulary each
|
||||
split evenly across the world, and a count that does not divide is **refused at declare, by name**
|
||||
Radiance shards by dividing: `n_head`, `n_head_kv`, the delta-net head counts and the vocabulary
|
||||
each split across the world, and a count that does not divide is **refused at declare, by name**
|
||||
(`share.cpp`, `rad_arch.h`). Four ranks got through for Qwen3.8-Flash-Next by replicating the two
|
||||
KV heads in rank pairs (1.0.7). Three ranks cannot: 24 query heads, 2 KV heads, 16 GDN K heads and
|
||||
48 GDN V heads have no even share in 3, and replication needs a world that is a multiple of the
|
||||
head count. The engine is right to refuse. What this document describes is how to **change the
|
||||
checkpoint** so there is nothing to refuse, exactly, and what the engine gained so that the padded
|
||||
checkpoint then serves at three ranks.
|
||||
KV heads in rank pairs (1.0.7); three did not: 24 query heads, 2 KV heads, 16 GDN K heads and 48
|
||||
GDN V heads have no even share in 3, and replication needs a world that is a multiple of the head
|
||||
count. 1.0.12 served three ranks by **padding the checkpoint** offline (`tools/pad_tp.py`, the
|
||||
regime of tcclaviger's `vllm/config/tp_padding.py`): zero heads appended so that 36 / 3 / 18 / 54
|
||||
divide, and a container converted from that. It worked, exactly, and it cost a second 115 GiB
|
||||
container for every model and 1/3 of the attention and 2 of 18 delta-net heads computing zeros.
|
||||
|
||||
The regime is tcclaviger's `vllm/config/tp_padding.py`, which pads the same model to the same
|
||||
shape at load time inside vLLM. Radiance has no load-time pad -- a container is served as it was
|
||||
converted -- so the pad is done once, offline, before `rad-convert`.
|
||||
This document describes what replaced it: **the shipped container serves at any world size**, with
|
||||
no tool and no second file. Two rules, both built from machinery the engine already had.
|
||||
|
||||
## 1. What is padded, and why it is exact
|
||||
## 1. The attention world
|
||||
|
||||
Every padded weight gains **zeros**, placed where a zero contributes nothing to the forward pass:
|
||||
`rad_arch.h` `geom_from` already handled a world *above* the KV head count by replication, when
|
||||
the world is a multiple of the count. It now handles a world that is **neither a divisor nor a
|
||||
multiple** of it:
|
||||
|
||||
| block | tensor | gains | exact because |
|
||||
|---|---|---|---|
|
||||
| attention | `k_proj`, `v_proj` | zero **rows** (new KV heads) | a zero KV head stores zeros and is read only by zero query heads |
|
||||
| attention | `q_proj` (fused q+gate on Flash-Next: 512-row head blocks) | zero rows so every KV group has the new ratio | a zero query head attends uniformly, and its `o_proj` column is zero, so its output is 0 |
|
||||
| attention | `o_proj` | zero **columns** in the same head order | the zero heads' outputs are multiplied by zero |
|
||||
| GDN | `in_proj_qkvz`, `in_proj_ba` | zero rows per the fused layout (new K and V heads) | a zero head carries a zero state |
|
||||
| GDN | `conv1d` | zero channels | zero input, zero output |
|
||||
| GDN | `A_log`, `dt_bias` | zero heads | a zero head decays nothing |
|
||||
| GDN | `out_proj` | zero columns | the zero heads are multiplied by zero |
|
||||
> attention is served on the largest multiple of the KV head count under the world -- the
|
||||
> **attention world** -- and the ranks past it are **attention-zero**.
|
||||
|
||||
Norms, embeddings, the lm_head, the router and the experts are untouched: their only width is
|
||||
`n_embd`. The experts stay at the model's own 640 and the plugin slices them by parity across the
|
||||
ranks (1.0.8: at three ranks the five 128-wide blocks go 2, 2, 1), so the +20 % expert bytes of a
|
||||
640 → 768 pad are not paid.
|
||||
Three ranks over two KV heads: the attention world is 2. Ranks 0 and 1 split the heads exactly as
|
||||
the two-rank serve does -- 12 query heads, one KV head, gqa 12, the same kernels -- and rank 2
|
||||
declares **the same shapes** and reads **nothing** for them: `rad_weight_shard_zero` tells the
|
||||
loader that this rank's share of `attn_qg`, `attn_k`, `attn_v` and `attn_output` is zeros. Its
|
||||
attention computes zeros from zeros and its output projection adds exactly nothing to the reduce.
|
||||
Five ranks over two: attention world 4 (two replicated pairs), rank 4 attention-zero. Six: three
|
||||
pairs, no zero rank.
|
||||
|
||||
For Qwen3.8-Flash-Next the pad is **24 → 36 query heads, 2 → 3 KV heads, GDN 16 → 18 K heads and
|
||||
48 → 54 V heads** -- head_dim 256 for attention and 128 for GDN are unchanged, so every rank at
|
||||
three declares 12 query heads, 1 KV head and gqa 12: **the same per-rank attention geometry the
|
||||
two-rank serve declares**, and the same kernels resolve. Dummies go **last**, as the vLLM pad does,
|
||||
so rank 2 carries them.
|
||||
Why the same shapes rather than no attention on that rank: the scheduler sees **one program**
|
||||
(`core/sched/batch.cpp` indexes `kv_groups[i]` by position), so every rank declares every op and
|
||||
every KV group in the same order. An attention-zero rank's KV group is as large as its peers'; the
|
||||
cost is one KV head of cache on that rank, the same bytes the padded container spent on its dummy
|
||||
head, and nothing is read from disk for its projections.
|
||||
|
||||
The cost is the dummies' arithmetic: 12 of 36 query heads and 2 of 18 GDN heads are zeros on the
|
||||
last rank, so three ranks do 1.5× the attention work of two for 1.5× the cards.
|
||||
Under a smaller attention world the plain even shard over `world` is the wrong cut for every
|
||||
attention projection, so `rad_block_attn_gated_fp8.h` declares **spans** (`rad_weight_shard_span`,
|
||||
the same call the KV replication already used for k/v): q|gate rows and output columns
|
||||
`[attn_rank * n_head, +n_head)` heads, k/v rows at `kv_off`. When the attention world is the world
|
||||
-- every TP2 and TP4 deployment -- no span is declared and the block declares as it always did.
|
||||
|
||||
## 2. The tool
|
||||
## 2. Uneven delta-net heads
|
||||
|
||||
`tools/pad_tp.py` (Python, numpy only; no torch) rewrites a Hugging Face safetensors checkpoint:
|
||||
The delta net has no KV-head constraint: its kernels are bound on head *widths* (`head_k`,
|
||||
`head_v`, the chunk) and take any head count. So 16 K heads over three ranks are **6, 5 and 5**,
|
||||
each rank's V heads the same multiple of its K heads (48 / 16 = 3: 18, 15, 15), every rank real
|
||||
heads, nothing padded. `qwen4exp` computes the split (`base + (rank < rem)`) and
|
||||
`rad_block_gdn_fp8.h` declares it as spans of the container's rows.
|
||||
|
||||
```sh
|
||||
tools/pad_tp.py SRC DST --heads 36 --kv-heads 3 --gdn-k 18 --gdn-v 54 --sparse
|
||||
tools/pad_verify.py SRC DST
|
||||
```
|
||||
That needed one thing the span call could not say. `in_proj_qkv|z` is four projections stacked
|
||||
along dim 0 -- q 2048, k 2048, v 6144, z 6144 rows -- and `rad_weight_shard_span` takes one
|
||||
`[lo, hi)` applied to every stacked part, which assumes the parts are equal.
|
||||
**`rad_weight_shard_span_parts`** (an additive export) takes a span per part together with each
|
||||
part's whole extent in the container; `share.cpp` cuts every part by its own rows. The conv
|
||||
channels `[q|k|v]`, the `[a|b]` projections, `A_log`, `dt_bias` and the output projection's
|
||||
columns take the same rank's heads. The even split, when the counts divide, is untouched.
|
||||
|
||||
It streams one tensor at a time (a 336 GiB checkpoint pads in a few GB of RAM), reads bf16 as raw
|
||||
u16 (no arithmetic happens), rewrites `config.json` with the new counts and an explicit `head_dim`,
|
||||
and handles the fused layouts: the Flash-Next `q_proj` that carries the attention gate beside each
|
||||
query head, and the GDN `in_proj_qkvz` / `in_proj_ba` row order.
|
||||
## 3. What this is built from
|
||||
|
||||
`--sparse` is for checkpoints larger than the free disk. Instead of copying, it **reflinks** every
|
||||
original shard (btrfs, XFS; `cp --reflink`) and writes only the padded tensors into new shards named
|
||||
`model-00000-of-NNNNN-tp3pad-*.safetensors`. Radiance's reader lists the index's shards sorted by
|
||||
name and keeps the **first** tensor of a name (`checkpoint.cpp`, `emplace`), so the new shards
|
||||
shadow the originals by sorting first. Flash-Next: 340 tensors, 6.6 GB of new bytes, the 131
|
||||
original shards shared.
|
||||
|
||||
`tools/pad_verify.py` reads both checkpoints back and checks every tensor: an untouched tensor is
|
||||
byte-identical, a padded one is the source in its place and zeros everywhere else. Run it before
|
||||
`rad-convert`; a pad that passes it cannot change what the model computes.
|
||||
|
||||
Padding proved on Llama-3.2-3B (24/8 heads, gqa 3 → 36/9, gqa 4): a 28-layer numpy forward on the
|
||||
padded weights gives the same argmax as the original with max |Δlogit| 2.1e-5 (fp32 summation
|
||||
order), and on the engine TP1 on the padded checkpoint produces the same text as TP1 on the
|
||||
original at temperature 0.
|
||||
|
||||
## 3. What the engine gained for three ranks
|
||||
|
||||
- **libr4d: `all_reduce` and `all_gather` at world 3.** `ar_oneshot_3rank_exact` is the wide
|
||||
one-shot family's template at 3; `ar_gather_3rank` the same for the gather the vocab-parallel
|
||||
sampler declares. Both share the wide family's instance (scratch, `[block][source]` flags, seq
|
||||
counters). There is no two-shot at 3: it shards the message `world` ways and a residual width
|
||||
such as 2560 does not divide by 3. `wht6` is a two-rank wire; three ranks take the exact one, as
|
||||
four do. Selftest: `--case ar_oneshot_3rank_exact` and `--case ar_gather_3rank`, bit-exact against
|
||||
the host sum / concatenation on three gfx1201 cards, with the two-rank controls unchanged.
|
||||
- **The vocabulary at a world that does not divide it.** 248 320 rows do not divide by 3 and
|
||||
`share.cpp` refuses a row shard without a declared span. `qwen4exp` now declares the rank's span
|
||||
for `token_embd` and `output`, and the split rule (`rad_arch.h` `shard_extent` / `shard_begin`,
|
||||
restated in `core/engine.cpp`) keeps the even share whenever the world divides the vocabulary and
|
||||
otherwise rounds the per-rank count up to a **128-row block** -- a block-scaled fp8 head refuses a
|
||||
cut inside a tile. At three the ranks take 82 816, 82 816 and 82 688; two and four ranks divide
|
||||
248 320 evenly and are untouched.
|
||||
- Everything else three ranks need was already there by 1.0.8: the width split of the experts at
|
||||
any world up to the block count, the uneven tile share of the plain bf16 (protected) experts, the
|
||||
N-rank gather's placement.
|
||||
- `rad_weight_shard_zero(b, w)` -- this rank's share is zeros; `weight_share` returns the
|
||||
declaration's extents with no rectangles, the loader stages the weight with a worker that writes
|
||||
zeros (the route a checkpoint weight takes) and reads nothing.
|
||||
- `rad_weight_shard_span_parts(b, w, lo, hi, total, n)` -- a span per stacked part.
|
||||
- `Geom::attn_world / attn_rank / attn_zero`, set by `geom_from`; `GdnFP8::Config::k_first /
|
||||
v_first`, set by the plugin.
|
||||
- Both exports are additive: `RAD_ABI_VERSION` does not move, and a plugin that does not call them
|
||||
declares as before. `tests/share_test.cpp` holds the per-part cut and the zero share.
|
||||
|
||||
## 4. Serving
|
||||
|
||||
```sh
|
||||
tools/pad_tp.py ~/models/Qwen3.8-Flash-Next ~/models/Qwen3.8-Flash-Next-tp3pad \
|
||||
--heads 36 --kv-heads 3 --gdn-k 18 --gdn-v 54 --sparse
|
||||
tools/pad_verify.py ~/models/Qwen3.8-Flash-Next ~/models/Qwen3.8-Flash-Next-tp3pad
|
||||
build/bin/rad-convert ~/models/Qwen3.8-Flash-Next-tp3pad -o qfn-tp3pad.rad \
|
||||
--recipe data/recipes/qwen4exp-w4nl64-i8-hc8m.recipe
|
||||
radiance --model qfn-tp3pad.rad --tp 3 --tp-wire exact --max-num-seqs 8 --max-model-len 200000 \
|
||||
--placement expert_tiered --host-pool-mib 8192 --gpu-headroom-mib 96 \
|
||||
--expert-vs-cache-ratio 0.82 --kv-cache-dtype fp8 --num-speculative-tokens 3 \
|
||||
--max-num-batched-tokens 2048
|
||||
radiance --model qwen3.8-next-flash-fp8-iq4r-moe.rad --tp 3 --tp-wire exact --max-num-seqs 8 \
|
||||
--max-model-len 262144 --placement expert_tiered --host-pool-mib 8192 \
|
||||
--gpu-headroom-mib 96 --expert-vs-cache-ratio 0.82 --kv-cache-dtype fp8 \
|
||||
--num-speculative-tokens 3 --max-num-batched-tokens 2048
|
||||
```
|
||||
|
||||
Measured on three Radeon AI PRO R9700 (gfx1201, PCIe Gen5 x16, Threadripper PRO 9955WX), the
|
||||
uncensored Flash-Next fine-tune padded as above and converted with the shipped recipe
|
||||
(`qwen4exp-w4nl64-i8-hc8m`, here without Hessians: nearest into the codebook), on 1.0.8 with
|
||||
the changes above; the two-rank column is the shipped `qwen3.8-next-flash-fp8-iq4r-moe.rad` on the same box:
|
||||
The log says what the geometry did:
|
||||
|
||||
| | three ranks, padded | two ranks, shipped container |
|
||||
```
|
||||
radiance: world_size = 3 over n_head_kv = 2: attention on 2 rank(s), rank(s) 2..2 carry zero attention weights and the delta net and experts of a full rank
|
||||
radiance: qwen4exp: rank 0 takes delta-net K heads [0, 6) of 16 and V heads [0, 18) of 48
|
||||
radiance: qwen4exp: rank 1 takes delta-net K heads [6, 11) of 16 and V heads [18, 33) of 48
|
||||
radiance: qwen4exp: rank 2 takes delta-net K heads [11, 16) of 16 and V heads [33, 48) of 48
|
||||
```
|
||||
|
||||
Measured on three Radeon AI PRO R9700 (gfx1201, PCIe Gen5 x16, Threadripper PRO 9955WX) with the
|
||||
same container served at two and three ranks -- the one comparison where only the world changes:
|
||||
|
||||
| | two ranks | three ranks |
|
||||
|---|---|---|
|
||||
| READY from cold | 45 s | 35 s |
|
||||
| 1 / 4 / 8 streams, aggregate t/s | 173.5 / 332.2 / 410.9 | 156 / 320 / 404 |
|
||||
| 4 streams at 100 K context, per stream | 41.8 | 41.2 |
|
||||
| warm-prefix TTFT, 60 K prompt, second time | 0.3 s (cold 8.2 s) | — |
|
||||
| HumanEval / GSM8K | 0.854 / 0.915 | 0.854 / 0.940 |
|
||||
| READY from cold | | |
|
||||
| 1 / 4 / 8 streams, aggregate t/s | | |
|
||||
| 4 streams at 100 K context, per stream | | |
|
||||
| HumanEval / GSM8K | | |
|
||||
|
||||
The GSM8K gap is the Hessians the shipped container was quantised against and this one was not;
|
||||
the GPTQ'd conversion of the same padded checkpoint is the comparison that closes it. Hi-vocab
|
||||
tokens (CJK, Cyrillic -- rank 2's lm_head shard, the three-rank gather) decode correctly; no engine
|
||||
warnings; every band the run issued resolved to a device kernel.
|
||||
The three-rank text is the three-rank text of the padded container, token for token, at temperature
|
||||
0 on the prompt set -- the two computations are the same arithmetic with the zeros in a different
|
||||
place.
|
||||
|
||||
`tools/pad_tp.py` and `tools/pad_verify.py` remain in the tree: they are how a checkpoint is padded
|
||||
for an engine that has no attention world, and how a pad is verified, and nothing here needs them.
|
||||
+168
-3
@@ -45,6 +45,11 @@ struct RecWeight {
|
||||
* checked. A weight with no span -- every even shard -- has `span_set` false. */
|
||||
bool span_set = false;
|
||||
int64_t span_lo = 0, span_hi = 0;
|
||||
/* rad_weight_shard_span_parts and rad_weight_shard_zero, recorded the same way. */
|
||||
int n_part_spans = 0;
|
||||
int64_t part_lo[RAD_MAX_ROW_PARTS] = {0}, part_hi[RAD_MAX_ROW_PARTS] = {0};
|
||||
int64_t part_total[RAD_MAX_ROW_PARTS] = {0};
|
||||
bool zero = false;
|
||||
};
|
||||
struct RecBuf { std::string name; RadBufDecl d{}; };
|
||||
struct RecOp {
|
||||
@@ -217,6 +222,29 @@ extern "C" int rad_weight_shard_span(RadBuilder* b, rad_weight w, int64_t lo, in
|
||||
rw.span_hi = hi;
|
||||
return RAD_OK;
|
||||
}
|
||||
extern "C" int rad_weight_shard_span_parts(RadBuilder* b, rad_weight w, const int64_t* lo,
|
||||
const int64_t* hi, const int64_t* total, int n) {
|
||||
if (!b || w == 0 || w > b->weights.size() || !lo || !hi || !total) return RAD_E_INVAL;
|
||||
if (n < 2 || n > RAD_MAX_ROW_PARTS) return RAD_E_INVAL;
|
||||
RecWeight& rw = b->weights[w - 1];
|
||||
if (rw.d.n_row_parts != n) return RAD_E_INVAL;
|
||||
for (int g = 0; g < n; ++g) {
|
||||
if (lo[g] < 0 || hi[g] <= lo[g] || hi[g] > total[g]) return RAD_E_INVAL;
|
||||
if (rw.d.row_parts[g] != hi[g] - lo[g]) return RAD_E_SHAPE;
|
||||
rw.part_lo[g] = lo[g];
|
||||
rw.part_hi[g] = hi[g];
|
||||
rw.part_total[g] = total[g];
|
||||
}
|
||||
rw.n_part_spans = n;
|
||||
return RAD_OK;
|
||||
}
|
||||
extern "C" int rad_weight_shard_zero(RadBuilder* b, rad_weight w) {
|
||||
if (!b || w == 0 || w > b->weights.size()) return RAD_E_INVAL;
|
||||
RecWeight& rw = b->weights[w - 1];
|
||||
if (rw.d.shard != RAD_SHARD_ROW && rw.d.shard != RAD_SHARD_COL) return RAD_E_INVAL;
|
||||
rw.zero = true;
|
||||
return RAD_OK;
|
||||
}
|
||||
extern "C" int rad_declare_drafter(RadBuilder* b, const RadDrafterDecl* d) {
|
||||
(void)b; (void)d;
|
||||
return RAD_OK;
|
||||
@@ -2210,13 +2238,16 @@ TEST(flashnext_tp4_replicates_kv_heads_and_splits_expert_widths) {
|
||||
}
|
||||
}
|
||||
|
||||
/* A WORLD THAT CANNOT REPLICATE -- not a multiple of the KV head count -- is refused by name,
|
||||
* not rounded into a half head. */
|
||||
/* A WORLD THAT CANNOT REPLICATE -- not a multiple of the KV head count -- is no longer
|
||||
* refused: it serves attention on the largest multiple under it and the rest of the ranks
|
||||
* carry zero attention (the tp3 case below holds the shapes). Nothing is rounded into a
|
||||
* half head: the replication rule itself is unchanged and still refuses an attention world
|
||||
* that is not a multiple, which cannot arise from geom_from's construction. */
|
||||
{
|
||||
RadBuilder b3;
|
||||
RadBuildCtx c3 = build_ctx(0, 3);
|
||||
c3.max_tok = 2048; c3.max_seqs = 8; c3.max_spec = 3; c3.max_ctx = 200000;
|
||||
CHECK(qwen4exp_fp8::declare(&b3, &meta, &c3) != RAD_OK);
|
||||
CHECK_EQ(qwen4exp_fp8::declare(&b3, &meta, &c3), RAD_OK);
|
||||
}
|
||||
|
||||
/* ---- A LAYER THAT KEEPS EXPERTS PLAIN STAYS AT FOUR CLASSES. Two plain experts leave 510
|
||||
@@ -2442,6 +2473,140 @@ const RecIssue* issue_of(const RadBuilder& b, const RadCtx& c, const std::string
|
||||
|
||||
} /* namespace */
|
||||
|
||||
/* THREE RANKS OVER TWO KV HEADS: the attention world is 2 (rad_arch.h), rank 2 declares the same
|
||||
* attention as its peers and reads zeros for it, and the delta net's 16 K heads go 6, 5, 5 with
|
||||
* the V heads at the same multiple -- declared as spans of the container, nothing padded. On the
|
||||
* tree before this, geom_from refuses world 3 ("cannot replicate n_head_kv = 2") and nothing
|
||||
* below runs. */
|
||||
TEST(flashnext_tp3_zeroes_the_third_ranks_attention_and_splits_gdn_heads_unevenly) {
|
||||
RadModelMeta meta = qwen4exp_meta();
|
||||
const int world = 3;
|
||||
const int64_t n_head = meta.n_head; /* 24 */
|
||||
const int64_t n_head_kv = meta.n_head_kv; /* 2: neither divides 3 nor divides into it */
|
||||
const int64_t head_dim = meta.head_dim; /* 256 */
|
||||
const int64_t nk = atoll(rad_meta_gets(&meta, "linear_num_key_heads", "0")); /* 16 */
|
||||
const int64_t nv = atoll(rad_meta_gets(&meta, "linear_num_value_heads", "0")); /* 48 */
|
||||
const int64_t hk = atoll(rad_meta_gets(&meta, "linear_key_head_dim", "0")); /* 128 */
|
||||
const int64_t hv = atoll(rad_meta_gets(&meta, "linear_value_head_dim", "0")); /* 128 */
|
||||
REQUIRE(n_head_kv < world && world % n_head_kv != 0);
|
||||
REQUIRE(nk % world != 0);
|
||||
const int attn_world = (int)(n_head_kv * (world / n_head_kv)); /* 2 */
|
||||
|
||||
const int lfull = 3;
|
||||
const std::string kq = "blk." + std::to_string(lfull) + ".attn_k.weight";
|
||||
const std::string kv = "blk." + std::to_string(lfull) + ".attn_v.weight";
|
||||
const std::string qg = "blk." + std::to_string(lfull) + ".attn_qg.weight";
|
||||
const std::string oo = "blk." + std::to_string(lfull) + ".attn_output.weight";
|
||||
|
||||
RadBuilder b[world];
|
||||
RadBuildCtx c[world];
|
||||
for (int r = 0; r < world; ++r) {
|
||||
c[r] = build_ctx(r, world);
|
||||
c[r].max_tok = 2048;
|
||||
c[r].max_seqs = 8;
|
||||
c[r].max_spec = 3;
|
||||
c[r].max_ctx = 200000;
|
||||
REQUIRE_EQ(qwen4exp_fp8::declare(&b[r], &meta, &c[r]), RAD_OK);
|
||||
}
|
||||
|
||||
/* The three programs declare the same ops in the same order and the same KV groups: the
|
||||
* scheduler sees one program. */
|
||||
for (int r = 1; r < world; ++r) {
|
||||
REQUIRE_EQ(b[r].ops.size(), b[0].ops.size());
|
||||
REQUIRE_EQ(b[r].kv_groups.size(), b[0].kv_groups.size());
|
||||
for (size_t i = 0; i < b[0].ops.size(); ++i) CHECK_EQ(b[r].ops[i].op, b[0].ops[i].op);
|
||||
for (size_t g = 0; g < b[0].kv_groups.size(); ++g) {
|
||||
CHECK_EQ(b[r].kv_groups[g].name, b[0].kv_groups[g].name);
|
||||
CHECK_EQ(b[r].kv_groups[g].d.kind, b[0].kv_groups[g].d.kind);
|
||||
}
|
||||
}
|
||||
|
||||
for (int r = 0; r < world; ++r) {
|
||||
const bool zero = r >= attn_world;
|
||||
/* (1) ATTENTION: every rank the two-rank geometry -- 12 heads, one KV head, gqa 12. */
|
||||
const RecOp* at = find_op(b[r], "attn_paged");
|
||||
REQUIRE(at != nullptr);
|
||||
CHECK_EQ(pint(at, "n_head"), n_head / attn_world);
|
||||
CHECK_EQ(pint(at, "gqa"), n_head / attn_world);
|
||||
CHECK_EQ(b[r].kv_groups[0].d.n_head_kv, 1);
|
||||
/* (2) THE PROJECTIONS: the span of this rank's heads in the container on every rank --
|
||||
* rank 2 the last attention rank's, so its shapes match -- and zeros on rank 2. */
|
||||
for (const std::string& wn : {kq, kv}) {
|
||||
const RecWeight* w = find_w(b[r], wn);
|
||||
REQUIRE(w != nullptr);
|
||||
CHECK_EQ(w->d.shape[0], head_dim);
|
||||
CHECK(w->span_set);
|
||||
const int ar = zero ? attn_world - 1 : r;
|
||||
CHECK_EQ(w->span_lo, (int64_t)ar * head_dim);
|
||||
CHECK_EQ(w->span_hi, w->span_lo + head_dim);
|
||||
CHECK_EQ(w->zero, zero);
|
||||
}
|
||||
{
|
||||
const RecWeight* w = find_w(b[r], qg);
|
||||
REQUIRE(w != nullptr);
|
||||
const int ar = zero ? attn_world - 1 : r;
|
||||
const int64_t qg_rows = 2 * (n_head / attn_world) * head_dim;
|
||||
CHECK_EQ(w->d.shape[0], qg_rows);
|
||||
CHECK(w->span_set);
|
||||
CHECK_EQ(w->span_lo, (int64_t)ar * qg_rows);
|
||||
CHECK_EQ(w->zero, zero);
|
||||
const RecWeight* o = find_w(b[r], oo);
|
||||
REQUIRE(o != nullptr);
|
||||
CHECK_EQ(o->d.shard, RAD_SHARD_COL);
|
||||
CHECK(o->span_set);
|
||||
CHECK_EQ(o->span_lo, (int64_t)ar * (n_head / attn_world) * head_dim);
|
||||
CHECK_EQ(o->zero, zero);
|
||||
}
|
||||
/* (3) THE DELTA NET: 6, 5, 5 K heads and 18, 15, 15 V heads, real on every rank, as
|
||||
* per-part spans of [q|k|v|z] and of the conv channels, a one-span of A_log. */
|
||||
const int64_t base = nk / world, rem = nk % world;
|
||||
const int64_t my_k = base + (r < rem ? 1 : 0);
|
||||
const int64_t k0 = r * base + (r < rem ? r : rem);
|
||||
const int64_t my_v = (nv / nk) * my_k, v0 = (nv / nk) * k0;
|
||||
const RecWeight* in = find_w(b[r], "blk.0.ssm_inz.weight");
|
||||
REQUIRE(in != nullptr);
|
||||
REQUIRE_EQ(in->d.n_row_parts, 4);
|
||||
CHECK_EQ(in->d.row_parts[0], my_k * hk);
|
||||
CHECK_EQ(in->d.row_parts[2], my_v * hv);
|
||||
REQUIRE_EQ(in->n_part_spans, 4);
|
||||
CHECK_EQ(in->part_lo[0], k0 * hk);
|
||||
CHECK_EQ(in->part_lo[1], k0 * hk);
|
||||
CHECK_EQ(in->part_lo[2], v0 * hv);
|
||||
CHECK_EQ(in->part_lo[3], v0 * hv);
|
||||
CHECK_EQ(in->part_total[0], nk * hk);
|
||||
CHECK_EQ(in->part_total[2], nv * hv);
|
||||
CHECK(!in->zero);
|
||||
const RecWeight* cv = find_w(b[r], "blk.0.ssm_conv1d.weight");
|
||||
REQUIRE(cv != nullptr);
|
||||
REQUIRE_EQ(cv->n_part_spans, 3);
|
||||
CHECK_EQ(cv->part_lo[2], v0 * hv);
|
||||
CHECK_EQ(cv->part_hi[2], (v0 + my_v) * hv);
|
||||
const RecWeight* al = find_w(b[r], "blk.0.ssm_a_log");
|
||||
REQUIRE(al != nullptr);
|
||||
CHECK_EQ(al->d.shape[0], my_v);
|
||||
CHECK(al->span_set);
|
||||
CHECK_EQ(al->span_lo, v0);
|
||||
CHECK_EQ(al->span_hi, v0 + my_v);
|
||||
const RecWeight* ow = find_w(b[r], "blk.0.ssm_out.weight");
|
||||
REQUIRE(ow != nullptr);
|
||||
CHECK_EQ(ow->d.shard, RAD_SHARD_COL);
|
||||
CHECK(ow->span_set);
|
||||
CHECK_EQ(ow->span_lo, v0 * hv);
|
||||
CHECK_EQ(ow->span_hi, (v0 + my_v) * hv);
|
||||
/* The GDN state group holds this rank's V heads, uneven across ranks. */
|
||||
bool seen = false;
|
||||
for (const auto& g : b[r].kv_groups)
|
||||
if (g.name == "kv_gdn_state") { seen = true; CHECK_EQ(g.d.n_head_kv, (int)my_v); }
|
||||
CHECK(seen);
|
||||
}
|
||||
/* The three ranks' K heads are the container's 16, once each. */
|
||||
{
|
||||
int64_t sum = 0;
|
||||
for (int r = 0; r < world; ++r) sum += nk / world + (r < nk % world ? 1 : 0);
|
||||
CHECK_EQ(sum, nk);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(a_vision_container_declares_the_tower_when_the_engine_asks_for_it) {
|
||||
/* No encoder budget: the tower is not declared, whatever the container carries. */
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user