Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
a69e611
qwen4: read the published 35B-A3B trunk view, add its MTP drafter and…
skygunner Dec 4, 2026
acbf13d
docs: put the qwen4 run config in the page, because .gitignore keeps …
skygunner Dec 4, 2026
773f512
docs: explain how the qwen4 adaptation works, add a one-command runne…
skygunner Dec 4, 2026
99376fc
docs: add the qwen4 serving monitor capture behind the agent-session …
skygunner Dec 4, 2026
52c562f
qwen4: speak its effort dialect, keep model-card sampling with MTP, a…
skygunner Dec 4, 2026
23e8cc4
[Docs] add bilingual Qwen4 engine-route comparison (strata vs strata-…
skygunner Dec 5, 2026
5f75cb7
[Engine] qsa_pattn: support the 16:2 (G=8) geometry on the sm_6x pref…
skygunner Dec 5, 2026
ee40092
[Docs] pass the polystrata_names gate: lowercase route names, PolyStr…
skygunner Dec 5, 2026
42fe3c4
[Engine] mtp_qwen4_rt: convert the sidecar's indexer tensors into the…
skygunner Dec 5, 2026
aecfe3c
[Engine] mtp: the draft layer's own indexer (MTP QSA), with its conve…
skygunner Dec 5, 2026
96025b9
[Engine] mtp: --mtp-hnorm defaults to stream, the reading every refer…
skygunner Dec 5, 2026
5b0c896
[Docs] qwen4: the drafter's indexer is implemented; record the two me…
skygunner Dec 5, 2026
9353f58
[Docs] qwen4: add the Chinese mirror of the technical page
skygunner Dec 5, 2026
cc5faef
[Engine] qwen4-run: reconvert a drafter runtime that predates the ind…
skygunner Dec 5, 2026
848286c
[Docs] qwen4: the completion record states whether the drafter's inde…
skygunner Dec 5, 2026
54d2e10
[Other] qwen4-run: --update and --stop, fork-local convenience
skygunner Dec 5, 2026
a742ed0
[Engine] serve: qwen4 maps client medium to high instead of a 400
skygunner Dec 5, 2026
f6b10a4
[Docs] qwen4: medium maps to high; record the fail-first evidence
skygunner Dec 5, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/DETAILS.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ that reads this line must accept `ms/window = adapt wait` for a serial run.
| `--mtp` | Use the model's MTP draft layer (setup passes it). The server also runs without it: drafts then come from the suffix and prompt-lookup drafter only, every token is still verified, and the draft layer's ~0.7-1 GiB of VRAM goes to the expert cache. |
| `--spec N`, `--spec-min-p P` | Draft depth and the confidence needed to add a guess. Setup's default is `--spec 4 --spec-min-p 0.5`. |
| `--draft-vocab en\|cyrillic\|fr\|latin` (setup) | The draft layer can only propose tokens from a subset of the vocabulary. The default subset includes every Chinese, Japanese and Korean token. `en` keeps the English and code subset (~110 MiB less VRAM, English 1-2% faster, CJK gets almost no drafts). `cyrillic` and `fr` add those scripts; `latin` adds German, Spanish, French and Polish together. With no choice, PolyStrata picks `cyrillic` or `latin` by itself when the languages of this computer (display language, regional format, keyboards) are Cyrillic or Latin-script and none of them is Chinese, Japanese or Korean; the pick is made at every start and written nowhere, and a choice you make always wins. On an RTX PRO 5000 (IQ3_S), default file -> chosen file, tok/s: Russian 180.0 -> 227.6 (`cyrillic`); German 211.7 -> 233.6, Spanish 220.1 -> 244.5, French 221.9 -> 249.1, Polish 188.4 -> 203.2 (`latin`); English 265.2 with the default, 266.0 with `latin`, 266.6 with `cyrillic`; Chinese 238.4 -> 199.2 and Japanese 222.2 -> 194.4 with `latin`, which is why any Chinese, Japanese or Korean signal keeps the default. `terminal/tools/draft_vocab.py` builds and inspects subsets. |
| `--lookup-chain-min M`, `--mtp-hnorm stream`, `--mtp-draft-vocab FILE` | Finer controls: the shortest context match `--lookup-chain` extends (default 3), one norm per stream, and a token subset of your own. |
| `--lookup-chain-min M`, `--mtp-hnorm pooled`, `--mtp-draft-vocab FILE` | Finer controls: the shortest context match `--lookup-chain` extends (default 3), one RMS over all four hyper-connection streams instead of the default one per stream (`stream`, which is what the reference MTP graphs do), and a token subset of your own. |

When the start stops with "the draft head does not fit" (a 12 GB card with a long context), the engine says how much it needs
and which smaller subset fits. Setup suggests `--draft-vocab en` on cards under 14 GB and does not set it.
Expand Down
2 changes: 1 addition & 1 deletion docs/DGX_SPARK_LINUX.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ The Spark settings in the run config:
| `--mmap-experts` | the experts are read from the model files in place, so the GPU's cache holds all 24,576 of them instead of a second copy in RAM |
| `--prefill auto:32768` | a 32,768-token prompt chunk; the automatic 8,192 measured 2 to 6% slower here |
| `--mtp-q4 all` | the draft layer as 4-bit copies: +3.5% decode, the answers do not change because the target checks every draft |
| `--mtp-hnorm stream` | one norm per hyper-connection stream in the draft layer: draft acceptance 0.60 to 0.63, +4.3% decode |
| `--mtp-hnorm stream` | one norm per hyper-connection stream in the draft layer: draft acceptance 0.60 to 0.63, +4.3% decode. Now the engine's default on every card (the reference MTP graphs normalize per stream); `pooled` is the opt-out |

Setup prints `--draft-vocab en` as a tip and does not set it: it measured +3.1% decode on English prompts, and it would cut the Chinese,
Japanese and Korean drafts.
Expand Down
576 changes: 576 additions & 0 deletions docs/QWEN4.md

Large diffs are not rendered by default.

536 changes: 536 additions & 0 deletions docs/QWEN4.zh-CN.md

Large diffs are not rendered by default.

161 changes: 161 additions & 0 deletions docs/QWEN4_ENGINE_PATHS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
# Qwen4-35B-A3B: the strata and strata-poly engine routes, measured

[中文版](QWEN4_ENGINE_PATHS.zh-CN.md)

This page compares the two implementations that now exist for Qwen4-35B-A3B (`qwen4exp`):

- **This branch** ([PR #430](https://github.com/simplexai-labs/PolyStrata/pull/430), `qwen4-35b` @ `52c562ff0`):
the model adapted to the existing **strata engine path** — the `strata` binary built with
`-DSTRATA_GEOMETRY=q4_lite`, a preprocessed trunk view and native pack, an external Q8_0 MTP drafter
runtime, and a fixed `--spec 2` verify window. The adaptation itself is described in [QWEN4.md](QWEN4.md).
- **Upstream main** (@ `df2c3ff30`): a native Qwen4 implementation on the **strata-poly engine**
(`engine/src/poly/qwen4.cpp`), reading the published two-shard GGUF directly, drafting with the MTP block
embedded in the file, and choosing the verify window per round with an adaptive policy.

Both repositories contain both engine families; what differs is which one serves Qwen4 and how the model is
prepared for it. This page records the route differences and a same-box measurement snapshot. **It does not
claim that either route is better.** Upstream's implementation is evolving (for example
[#440](https://github.com/simplexai-labs/PolyStrata/pull/440), PLE row-by-row O_DIRECT reads, is open, and
BasinKV sparse KV offload has landed), so its numbers can move. All measurements here are one RTX 3080 Ti
12 GB (sm_86), 46 GB RAM, Linux, CUDA 12.8, one request at a time, Unsloth UD-IQ4_XS — the same published
GGUF files on both routes.

## The two routes

| Aspect | This branch (strata route) | Upstream main (strata-poly route) |
| --- | --- | --- |
| Engine binary | `strata` (`-DSTRATA_GEOMETRY=q4_lite`) | `strata-poly` |
| Qwen4 code | `engine/src/program/generate.cpp`, `engine/src/split/`, `engine/src/core/layer.cpp` adaptations | `engine/src/poly/qwen4.cpp` / `.cu`, native `qwen4exp` forward pass |
| Model loading | 40-layer trunk view (`tools/qwen4_split_gguf.py`) → native pack (`tools/iq_pack.py`), passed as `--pack` / `--native` | published 2-shard GGUF mmap'd directly (`--model`), no repack |
| Fused projections | split into separate tensors **by quantized byte rows** (no requantization) | read natively in fused form (`attn_qkv_gate`, `ssm_beta_alpha`, `*_down_inject`) |
| PLE n-gram table | published shard 2 passed separately as `--ple-gguf` | read by the poly engine from the published shard; [#440](https://github.com/simplexai-labs/PolyStrata/pull/440) (open) reworks this to row-by-row O_DIRECT reads |
| Expert profile | `tools/make_profile.py --n-layer 40` → `expert-profile.bin` | setup preparation → `expert-profile.txt` |
| MTP weights | separate Q8_0 sidecar (`MTP/mtp-Qwen4-35B-A3B-Q8_0.gguf`, 1.87 GiB) → drafter runtime (`tools/mtp_qwen4_rt.py`), passed as `--mtp`; costs 1,915 MiB VRAM | `blk.40` embedded in the published UD file: Q5_K matrices, F32 norms, BF16 indexer; loaded automatically, no flag |
| MTP attention | indexer/QSA path **implemented** — the sidecar's `blk.40.indexer.*` converted, block scores → top-k → selected cells; `STRATA_MTP_INDEXER=0` keeps the dense approximation ([details](QWEN4.md#the-mtp-drafters-indexer-mtp-qsa)) | indexer/QSA path retained (`blk.40.indexer.*` loaded like a trunk attention block) |
| Verify window | `--spec 2` fixed cap; `--spec-min-p` stays `0.0`; suffix drafter available | no `--window` → the engine resolves a default cap of **8** for this model (GDN recurrent state, `snaps_spread()` true because `full_snaps_` is only set on the DFlash2 path); the adaptive `DraftPolicy` then picks the size per round |
| KV / RAM | `--kv-grow`: KV allocated only for cells reached | `--conversation-cache-mib auto` (8 GiB, up to 4 parked conversations here); BasinKV offload available but not enabled in the measured config |
| Sampling default with MTP | Qwen4 (`pre="qwen4"`) requests that name no sampling use the **model card** (this branch's change) | #3354 rule: MTP requests that name no sampling stay **greedy** (`serve/server.py`, `mtp_greedy`) |
| Model aliases | the runner writes `aliases` into the run config | serve supports `aliases` (#297); the qwen4 setup writes none |

What is shared: the published GGUF files, the serving surface (OpenAI and Anthropic APIs), and — byte for
byte — `engine/include/strata/spec/draft_policy.hpp`, the adaptive draft policy and its cost learner. The
routes differ in the cap they give that policy and in the drafter they feed it, not in the policy code.

## Measurement 1: the window cap, within upstream (controlled)

The same upstream stack and the same harness sweep (7 requests, 256 generated tokens each, prompts of
1,017 / 1,023 / 1,023 / 31,718 / 32,765 / 65,499 / 130,652 tokens, all cold reads) were run with the default
window and with a variant config adding `--window 2`. Two passes of the capped variant were recorded.
Acceptance is per draft token, from the serve log's `drafts accepted X of Y` lines.

| Run | Acceptance | Mean decode | Tokens committed per round | Rounds per 256 tokens |
| --- | ---: | ---: | ---: | ---: |
| default (adaptive, cap 8) | 942/1281 = **73.5%** | **154.4 tok/s** | ~2.11 | ~121 |
| `--window 2`, pass 1 | 785/955 = **82.2%** | **152.4 tok/s** | ~1.78 | ~144 |
| `--window 2`, pass 2 | 786/923 = **85.2%** | **148.2 tok/s** | ~1.78 | ~144 |

Per-request decode (tok/s):

| Prompt tokens | default | w2 pass 1 | w2 pass 2 |
| ---: | ---: | ---: | ---: |
| 1,017 | 148.1 | 146.8 | 124.6 * |
| 1,023 | 170.1 | 167.1 | 170.6 |
| 1,023 | 172.0 | 173.9 | 162.3 |
| 31,718 | 159.7 | 150.4 | 154.6 |
| 32,765 | 165.4 | 160.9 | 161.1 |
| 65,499 | 150.6 | 146.5 | 144.6 |
| 130,652 | 114.9 | 121.4 | 119.6 |

\* The pass-2 run at 1,017 tokens also prefilled 14× slower than usual (6,326 ms at 160.8 tok/s against
~450 ms at ~2,250 tok/s in every other run). That points to machine-level contention during that request,
not to the window setting; it is kept in the table and flagged, not silently dropped.

What this shows:

- **Capping the window at 2 raises acceptance from ~73.5% to ~82–85%.** The cap removes the deeper,
lower-confidence drafts from the denominator; the drafter is the same Q5_K embedded block in both runs.
- **Decode does not improve with the cap — it drops ~1–4% on average.** The adaptive policy commits ~2.11
tokens per verification round against ~1.78 capped: ~18% more rounds, each ~16% cheaper (14.2 ms vs
11.9 ms per round on the 1,017-token request). The two effects nearly cancel, with a small net loss.
- **At 130,652 tokens the capped window is ~6% faster** (114.9 → 121.4/119.6 tok/s): verifying a deep
window over a very long KV costs more, and the shallow window wins there.
- Acceptance rate and decode throughput are different objectives. The shared adaptive policy optimizes
learned per-round cost (tokens/s), not acceptance; a lower acceptance at a wider cap is the policy
spending draft tokens where they still pay off.

## Measurement 2: across the two routes (observational, not a controlled A/B)

The branch's own serve log on the same box and the same UD-IQ4_XS file, same harness prompt sizes
(128-token generations there, 256 above), cold reads on both sides:

| Prompt tokens | This branch, prefill | Upstream, prefill |
| ---: | ---: | ---: |
| 1,017 | 2,262–2,329 tok/s | 2,181–2,290 tok/s |
| 31,718 | 3,884–3,905 tok/s | 2,357–2,385 tok/s |
| 65,499 | 3,704–3,731 tok/s | 2,094–2,169 tok/s |
| 130,652 | 3,466–3,516 tok/s | 1,819–1,887 tok/s |

Decode: this branch measured 147.4–178.9 tok/s across those requests (acceptance 69.9–92.4% per request);
upstream's default-window sweep measured 114.9–172.0 tok/s. Expert residency at the shipped 131,072
context: this branch keeps 3,305 of 10,240 trunk experts in VRAM plus the 1,915 MiB drafter
([QWEN4.md](QWEN4.md)); upstream's log reports 4,796 of 10,496 routed experts in 7.6 GiB (its count includes
the embedded drafter block) with 723 MiB free at the end.

**These cross-route numbers carry real caveats:**

1. **Different verification sampling by default.** This branch applies model-card sampling to Qwen4 MTP
requests that name no sampling; upstream keeps such requests greedy (#3354). Unless the harness pins
sampling explicitly, acceptance and decode on the two routes are measured under different verification
regimes. Prefill is unaffected by sampling.
2. **Different generation lengths** (128 vs 256 tokens) and different sessions; fixed costs amortize
differently.
3. **One card, one quantization, one request at a time.** Nothing here generalizes to other hardware.
4. **No ablation.** Attributing the prefill gap to the native pack layout and the CPU prefill share
(`--prefill auto`) versus the poly mmap path is static analysis of the two code paths, not a verified
cause.

The prefill gap at long prompts (~1.5–1.9× at 31K–131K, cold on both sides) is the most robust of these
observations because it does not depend on the sampling regime. The decode and acceptance comparisons are
directional reference points, not a like-for-like verdict.

## Analysis

- **The acceptance gap between the routes is mostly window depth, not drafter precision.** At a matched
cap of 2, upstream's embedded Q5_K drafter accepts 82–85% (greedy verification) — in the same range as
this branch's Q8_0 sidecar at `--spec 2` (~82% in its own serve regime; 0.703 teacher-forced greedy in
[QWEN4.md](QWEN4.md#speed)). The 73.5% at the default cap is what the adaptive policy's deeper rounds
produce, and Measurement 1 shows it buys throughput rather than losing quality. This snapshot therefore
does **not** support a claim that the Q5_K embedded drafter is intrinsically worse than the Q8_0 sidecar.
- **Drafter precision trades against VRAM and residency.** The Q8_0 sidecar costs 1,915 MiB of VRAM; the
embedded Q5_K block is a fraction of that (its matrices are Q5_K in the published file). On a 12 GB card
that difference goes to trunk expert residency. On a card where everything fits, the trade is different.
- **This branch now runs the indexer too.** The sidecar's `blk.40.indexer.*` tensors are converted and the draft
layer runs the same block-score / top-k selection as the trunk, so the dense-attention approximation is no longer
this branch's limitation — it is the opt-out (`STRATA_MTP_INDEXER=0`, or a sidecar without the tensors). At a 64K
prompt the indexer decoded **10.8% faster** than the approximation on the same box
([details](QWEN4.md#the-mtp-drafters-indexer-mtp-qsa)). The matched-cap acceptance above was measured with the
approximation and still stands as that configuration's number.
- **This analysis changed no defaults on either side.** The `--window 2` variant was a diagnostic config on the
upstream checkout; this branch ships `--spec 2` as before. Separate later work settled `--mtp-hnorm` to `stream`
on reference-implementation and same-box A/B evidence ([details](QWEN4.md#two-defaults-measured));
`--spec-min-p` stays `0.0`.

## What would verify the remaining questions

- A cross-route run with the harness pinning sampling and generation length on both stacks, repeated to
bound variance, would turn Measurement 2 into a controlled comparison.
- A prefill-share ablation on the strata route (and the equivalent on poly) would test the static-analysis
attribution of the prefill gap.
- Upstream's in-flight work (#440's PLE reader, BasinKV configurations) should be re-measured when it
lands; the numbers above are a snapshot at `df2c3ff30`, not a moving target.

## References

- [QWEN4.md](QWEN4.md) — this branch's adaptation, conversion chain and speed measurements.
- [PR #430](https://github.com/simplexai-labs/PolyStrata/pull/430) — this branch's submission.
- [#440](https://github.com/simplexai-labs/PolyStrata/pull/440) — upstream's PLE O_DIRECT reader (open).
- [Niko1221/Strata#7774](https://github.com/Niko1221/Strata/pull/7774) — the reference implementation this
branch's conversion tools follow.
- Upstream sources at `df2c3ff30`: `engine/src/poly/qwen4.cpp` (embedded MTP, fused tensors, indexer),
`engine/src/poly/engine.cpp` (window default resolution), `terminal/setup.py` (`QWEN4_FAMILIES`),
`terminal/serve/server.py` (`mtp_greedy`, #3354).
Loading