Skip to content

Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.

C++

qwen35: keep the base engine's end-of-answer accounting (hybrid text identical), a stop keeps only x, the held tokens list every accepted draft

Niko12211e13cbc8a5d9
diff --git a/docs/QWEN36.md b/docs/QWEN36.md
index 21bb641f0..ae1d408ab 100644
--- a/docs/QWEN36.md
+++ b/docs/QWEN36.md
@@ -72,6 +72,16 @@ answer, **R9700 32 GB, UD-Q4_K_XL, llama.cpp `llama-server -np N`** (5 interleav
| 4 | 252.0 | 165.0 | 1.53 | 5/5 |
| 8 | 325.4 | 208.1 | 1.56 | 5/5 |
+**RTX 3060 12 GB, UD-Q4_K_XL in the hybrid mode** (each engine with the slots it needs: `--batch N` takes room from the expert slots; llama.cpp
+`llama-server -np N -ncmoe 28 -t 8`, the best split of a sweep on this card; 5 interleaved pairs, medians; the box was shared with other
+jobs between runs, never during one):
+
+| Requests at once | Strata | llama.cpp | Ratio | Pairs faster |
+| ---: | ---: | ---: | ---: | ---: |
+| 1 | 64.0 tok/s | 41.1 | 1.56 | 5/5 |
+| 2 | 85.1 | 52.5 | 1.62 | 5/5 |
+| 4 | 99.3 | 63.0 | 1.58 | 5/5 |
+
Every slot's tokens equal the tokens of the same request alone (the base engine's), at 2, 4 and 8 slots, with a 2.5K-token prompt read beside
decoding slots, with slots reused for later requests, with pictures and with sampling (same seed). Through the server: four concurrent chat
requests give the texts of the same four one after the other.
@@ -94,9 +104,10 @@ The text is the same with and without it (every slot equal to its solo tokens).
and the MTP block, 45 KB per token) and 0.07 GB of recurrent state. Setup writes the context for one conversation, so N slots take N times
that from the room the experts would have: on a card that does not hold every expert (12 and 16 GB, the hybrid mode) that is room the
expert slots lose, and a batch reads more distinct experts from RAM. Setup therefore **recommends `--parallel` only where every expert still
-fits** (about 3 on a 32 GB card at 32K) and says why it leaves it at one otherwise; any number you give is kept. On the RTX 3060 12 GB with
-`--batch 4` the engine kept 22 of 256 experts per layer (the sessions, the picture encoder and the MTP block took the rest) and four
-requests at once ran 45 tok/s together against 42 one after the other: not worth it there. The engine says what the sessions take before it
+fits** (about 3 on a 32 GB card at 32K) and says why it leaves it at one otherwise; any number you give is kept. It still pays on a card
+that does not: on the RTX 3060 12 GB, `--batch 4` leaves 37 of 256 experts per layer in VRAM instead of 54, so a request alone decodes
+64.7 tok/s instead of 68.3 (-5%, 3 interleaved runs each, medians of the 10 parity prompts), and four requests at once ran 99 tok/s together
+against 64 for one (table above; each of them slower: ~25 tok/s). The engine says what the sessions take before it
allocates them and refuses (with the numbers) a count that cannot fit.
In the hybrid mode the text of a request can differ a little between running alone and running beside others: the experts that sit on the
diff --git a/setup.py b/setup.py
index 9d2059809..91f3c159f 100644
--- a/setup.py
+++ b/setup.py
@@ -5577,8 +5577,10 @@ def own_path_parallel_note(a_parallel, fam: dict, model: str, vram_gb: float, ct
slot = own_path_parallel_slot_gb(fam, ctx)
if a_parallel is None or a_parallel <= 1:
if not rec:
- return ["Several requests at once: left at one at a time - this card does not hold every expert beside more "
- "sessions, and the experts that run on the CPU make a batch read more of them (docs/BATCHING.md)."]
+ return ["Several requests at once (opt-in, --parallel N): left at one at a time, because this card does not hold every "
+ "expert beside more sessions. Measured there (RTX 3060 12 GB), 4 requests together ran about 1.5x the speed "
+ "of one (99 against 64 tok/s) but each of them slower, and a request alone about 5% slower, as the "
+ "slots take VRAM from the expert cache (docs/QWEN36.md)."]
return [f"Several requests at once (opt-in): --parallel {rec} decodes up to {rec} together instead of one after "
f"the other (each takes ~{slot:.1f} GB of VRAM at this context; docs/BATCHING.md)."]
lines = [f"parallel requests: {a_parallel} at once (each takes ~{slot:.1f} GB of VRAM at this context, "
diff --git a/src/qwen35/q36_engine.cu b/src/qwen35/q36_engine.cu
index 215f0194d..04cbbe623 100644
--- a/src/qwen35/q36_engine.cu
+++ b/src/qwen35/q36_engine.cu
@@ -2285,13 +2285,11 @@ struct Engine {
/// tokens of the rows the block must redo first (the drafts the last window accepted, seeded by hmain rows
/// 0 .. fix.size() - 1 of that window). Drafts d1 .. dD, then the window [x, d1 .. dD] through the main model;
/// returns the accepted count a and writes the picks of rows 0 .. a (row a's pick is the token after them).
- /// `max_a`: at most that many drafts are taken (the answer has room for max_a + 1 more tokens, the last of which is
- /// not fed, as in plain decoding); and no draft past an end-of-answer token is taken (that token is the next one the
- /// caller emits). So the state ends exactly where plain decoding would leave it.
- /// `cancel`: a stop asked for before the state moves keeps only x (the caller then emits no draft: every token emitted but
- /// the last is in the state, so a conversation that continues from the held tokens loses and repeats nothing).
+ /// `cancel`: a stop asked for before the state moves keeps only x (the caller then emits no draft), so that a request
+ /// stopped mid-answer leaves the state at the tokens it has shown: a conversation that continues from them (the server's
+ /// hand-over of a stopped request to a batch slot) reuses it instead of reading them again.
int spec_step(int x_tok, const std::vector<int32_t>& fix, int D, std::vector<int32_t>& drafts, int32_t* picks,
- int max_a = 1 << 20, const std::atomic<bool>* cancel = nullptr) {
+ const std::atomic<bool>* cancel = nullptr) {
const int N = (int) m->g.n_embd;
if (main_hybrid) D = std::min<int>(D, (int) (kRebalanceEvery - pos % kRebalanceEvery) - 1);
const int T0 = (int) fix.size() + 1; // the redo rows and the row of x
@@ -2342,10 +2340,7 @@ struct Engine {
CK(cudaStreamSynchronize(st));
int a = 0;
while (a < D && hpin[2 + a] == drafts[(size_t) a]) ++a;
- a = std::min(a, max_a);
if (cancel != nullptr && cancel->load()) a = 0;
- for (int i = 0; i < a; ++i)
- if (drafts[(size_t) i] == 248044 || drafts[(size_t) i] == 248046) { a = i; break; } // (<|endoftext|>, <|im_end|>)
for (int i = 0; i <= a; ++i) picks[i] = hpin[2 + i];
commit(a + 1);
CK(cudaMemcpyAsync(hlast, hmain + (size_t) a * N, (size_t) N * 4, cudaMemcpyDeviceToDevice, st));
@@ -3229,21 +3224,20 @@ struct Serve {
if (!emit(nx)) break;
if (n_active > 0) window();
if (spec && n_active == 0 && E.pos + E.mtp_d + 1 <= E.ctx) {
- const int a = E.spec_step(nx, fix, E.mtp_d, drafts, picks, (int) std::min<long long>(max_new - produced - 1, 1 << 20), &stop);
+ const int a = E.spec_step(nx, fix, E.mtp_d, drafts, picks, &stop);
offered += E.mtp_d;
accepted += a;
- // the state now holds x and the accepted drafts - spec_step took none past an end-of-answer token or past
- // the room max_new leaves, so the state ends where plain decoding leaves it (the last token emitted is not
- // fed) and a later request that continues this conversation neither misses nor reads a token twice
+ // the state now holds x and every accepted draft, whether or not the answer ends inside them (an end of
+ // answer, max_new): the held tokens say so, so a later request that continues this conversation matches them
+ // (a prompt that has the same tokens next reuses the state, any other reads from the start) and never reads
+ // a token twice
ss.live.push_back(nx);
for (int i = 0; i < a; ++i) ss.live.push_back(drafts[(size_t) i]);
fix.assign(drafts.begin(), drafts.begin() + a);
- for (int i = 0; i < a; ++i) { // (all of them: they are in the state; a stop is seen at the next token)
- std::printf("T %d\n", drafts[(size_t) i]);
- ++produced;
- hist.push_back(drafts[(size_t) i]);
- }
- std::fflush(stdout);
+ bool ended = false;
+ for (int i = 0; i < a && !ended; ++i)
+ if (!emit(drafts[(size_t) i])) ended = true;
+ if (ended) break;
nx = picks[a];
continue;
}