Skip to content

recipes: Flash-Next (qwen4exp) on HRX prefills at -ub 2048 (#572) - #2289

Merged
bong-water-water-bong merged 1 commit into
mainfrom
cl1077/572-flashnext-ub2048
Nov 12, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
cl1077/572-flashnext-ub2048

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Part of #572 (the issue stays open: this is its first change, not its target).

Why

1bit serve starts the chat llama-server without -b/-ub. Only the mmproj, embedding and rerank launches set them in app/serve.cpp. So Qwen3.8-Flash-Next ran on llama-server's default 512-token micro-batch, the slow arm of every -ub pair measured on #572. The file routes each token to 10 of 512 experts (read from its GGUF header). At 512 tokens, the routed expert GEMMs see about 10 rows per expert per launch. Those GEMMs are 34 % of prefill device time at the current pin (profile).

What

  • config/recipes.json: new built-in recipe qwen4exp-hrx-ub2048. It matches device hrx with architecture qwen4exp and adds -ub 2048 unless the command line already has -ub, so --mmproj keeps its 4096. The value stays within llama-server's default -b 2048.
    • It is scoped to qwen4exp, not to every MoE: Qwen3-Coder-30B-A3B is 0.88x at pp512 with 2048, and dense models are fastest at 512 (docs/hrx.md).
  • tests/recipes_route.sh: hrx + qwen4exp gets -ub 2048 exactly once, with the recipe named on stderr. qwen4exp on cpu gets no -ub, and neither does qwen35 on hrx.
  • Docs: the docs/recipes.md table gets the new row (five built-in recipes now), and docs/hrx.md's HRX: Qwen3.8-Flash-Next prefill is 287 tok/s on UD-IQ4_XS vs 1,679 for gufo on the same box (and 500-2,400 across published Strix Halo engines) #572 section says the product now runs the 2048 arm.

Measured (existing pairs, cited in the recipe's measured field)

path file pp512 (ub 2048 vs 512) pp4096 (ub 2048 vs 512)
llama-server, ctx 16384, --cache-reuse 0, one library (11-05) UD-IQ4_XS 183.76 vs 133.38 205.05 vs 101.05 (2.03x)
llama-bench -r 9 (11-09) UD-IQ3_XXS 703.27 vs 710.04 (tied) 548.94 ± 61.17 vs 343.71 ± 14.14 (1.60x)

The pair I still owe is through 1bit serve itself, main against this branch, pp512 and pp4096 in one window. It needs the whole box, so it is requested through the orchestrator. I will add it to this PR before asking for merge.

Checks

  • tests/recipes_route.sh build/1bit: PASS, 22 checks, on onebit built from this branch. strings confirms the recipe is in the binary.
  • Mutant: with the recipe removed from config/recipes.json and the binary rebuilt, on hrx it adds -ub 2048 once and names the recipe fails. Restored, it passes.
  • ctest -R "route|parallel_args|recipes" -E npu: 13/15 pass, including device_route and recipes_route. The two Not Run (pm_routes, systemone_route) need executables outside the onebit target.
  • python3 tools/copyright.py --check: rc 0. No new files.

🤖 Generated with Claude Code

1bit serve starts the chat llama-server without -b/-ub, so Qwen3.8-Flash-Next
ran llama-server's default 512-token micro-batch, the slow arm of every
-ub pair measured on #572. At 10 of 512 experts per token, a 512-token
micro-batch leaves the routed expert GEMMs (34 % of prefill device time at
pin 962507f8e) about 10 rows per expert per launch.

New built-in recipe qwen4exp-hrx-ub2048: device hrx, architecture qwen4exp,
adds -ub 2048 unless the command line already has -ub (mmproj keeps 4096).
Scoped to qwen4exp because Qwen3-Coder-30B-A3B loses 12 % at pp512 with
2048 and dense models are fastest at 512 (docs/hrx.md).

tests/recipes_route.sh: hrx + qwen4exp gets -ub 2048 once with the recipe
named; qwen4exp on cpu and qwen35 on hrx get no -ub. With the recipe
removed the positive check fails. docs/recipes.md and docs/hrx.md updated.

Co-authored-by: bong-water-water-bong <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

ready for review at 865453c

@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

572 - Partially compliant

Compliant requirements:

  • Added new recipe qwen4exp-hrx-ub2048 that sets -ub 2048 for qwen4exp on hrx
  • The recipe is scoped correctly to only apply to qwen4exp architecture on hrx device
  • Updated documentation in docs/recipes.md and docs/hrx.md to reflect the new recipe and performance claims
  • Tests verify the recipe is applied correctly on hrx with qwen4exp and not applied elsewhere

Non-compliant requirements:

  • The PR doesn't include the actual implementation of the micro-batch optimization (the "dispatch profile of pp512 / pp4096" mentioned in the issue description)
  • The PR doesn't include the expert-GEMM tile width fitting or the ub cap implementation mentioned in the issue
  • The PR doesn't include the MTP head for Flash-Next decode side mentioned in the issue

Requires further human verification:

  • The performance claims (1,679 tok/s prefill) need to be verified with actual hardware measurements
  • The specific micro-batch optimization details (pp512 / pp4096 dispatch profile) need to be confirmed in the full implementation
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Recipe Scoping

The new recipe qwen4exp-hrx-ub2048 is correctly scoped to qwen4exp architecture and hrx device, but the documentation in the why field mentions that this is not a general MoE rule and that Qwen3-Coder-30B-A3B loses 12% at pp512 with 2048, and dense models are fastest at 512. This is good for specificity, but the recipe should be more explicit about why it's not applied to other MoE architectures like Qwen3-Coder-30B-A3B.

{
 "id": "qwen4exp-hrx-ub2048",
 "match": {"device": ["hrx"], "architecture": ["qwen4exp"]},
 "args": ["-ub", "2048"],
 "why": "Qwen3.8-Flash-Next routes each token to 10 of 512 experts, so at llama-server's default 512-token micro-batch the routed expert GEMMs (gate/up and down, 34 % of prefill device time) see about 10 rows per expert per launch and run mostly empty; a 2048-token micro-batch gives them four times the rows for the same weight reads. Not a general MoE rule: Qwen3-Coder-30B-A3B (128 experts) is 0.88x at pp512 with -ub 2048, and dense models are fastest at 512 (docs/hrx.md), so this is scoped to qwen4exp. The micro-batch stays within llama-server's default -b 2048.",
 "measured": "Flash-Next, HRX0, -ngl 99 -fa 1, -ub 2048 against -ub 512 in the same window. Product path (llama-server, UD-IQ4_XS q31 d9620119, ctx 16384, --cache-reuse 0, same library 27e7d641, 2026-11-05): pp4096 205.05 vs 101.05 tok/s (2.03x), pp512 183.76 vs 133.38. llama-bench on UD-IQ3_XXS (2026-11-09, -r 9): pp512 703.27 vs 710.04 (tied), pp2048 745.01 vs 644.81 (a second run at -ub 2048 gave 364.28 +/- 189.33), pp4096 548.94 +/- 61.17 vs 343.71 +/- 14.14 (1.60x). Prefill profile at the current pin 962507f8e (UD-IQ3_XXS, pp2048, -ub 512, 2026-11-12): routed gate/up 20.3 % and routed down 13.7 % of 5,345.7 ms device time.",
 "source": "engine #572 (issuecomment-6828676979)"
}
Performance Claims

The documentation states that the prefill performance improved from 287 tok/s to 1,679 tok/s, but this claim is based on the comparison with gufo on the same box, not on the actual performance improvement achieved by this PR. The PR only adds the recipe to set -ub 2048, but doesn't implement the actual optimizations that would lead to the 1,679 tok/s performance. The performance improvement needs to be measured on the hardware to validate the claim.

still not the whole gap. `1bit serve` now starts Flash-Next on HRX at `-ub 2048` through the
`qwen4exp-hrx-ub2048` recipe ([recipes.md](recipes.md)); before it, the product ran the 512 arm of
this pair, llama-server's default.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

pr-agent's two findings, answered: (1) the docs/hrx.md line claims no 1,679 tok/s result; it says the product now runs the 2048 arm of the measured pair, and the only new number this PR owes is the 1bit serve pair named in the body. (2) The reason other MoE files are left out is in the recipe's why (Qwen3-Coder-30B-A3B 0.88x at pp512) and in the docs/recipes.md row. No change at 865453c.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: READY -- a 2x prefill on the product path, measured the way this issue's other numbers should have been, and it invalidates the prefill arms taken before it

The measurement is on the product path and it is a paired one: pp4096 205.05 vs 101.05 tok/s at -ub 512, 2.03x, UD-IQ4_*, -ngl 99 -fa 1, "in the same window". Both of those matter: the product path is what 1bit serve actually starts (not a llama-bench arm), and same-window pairing is the only way this box gives a comparable pair -- the co-tenancy work in #2146 measured the alternative at ~5 % of seconds contended, which is enough to move a 2x claim if the arms are taken hours apart.

The reason is mechanistic rather than statistical, which is why I believe the number: Flash-Next routes each token to 10 of 512 experts (from its own GGUF header), so at a 512-token micro-batch each routed expert GEMM sees about 10 rows, and those GEMMs are 34 % of prefill device time at the current pin. Widening the micro-batch to 2048 is the direct fix for exactly that shape of waste, and the doc says so in the recipe's own why field rather than only in the PR.

The scoping is right in both directions: the recipe matches device hrx + arch qwen4exp and adds -ub 2048 unless the command line already carries -ub, so an explicit --mmproj keeps its 4096; and tests/recipes_route.sh pins the negative -- "the qwen4exp -ub 2048 recipe is hrx-scoped too: no -ub on cpu". A recipe that leaked -ub onto the CPU route would be a silent memory change on a route that does not want it.

The consequence I would write into #679/#572 before anyone reads an old number: this changes the prefill denominator. My own 18.8k row (363.5 and 356.7 / 371.6 tok/s prefill at cef5e2e20 / 60ae4c935 / 03bee0f73) was taken on the shipped config, i.e. the 512 arm this PR replaces. So:

  • the #679 prefill gap (2.54x at the baseline pin, 1.26x against the fork) is not comparable with any row taken after this lands -- it needs re-taking with the recipe active;
  • the decode side is untouched by -ub (a decode step is one row), so the decode gap (2.57x / 1.24x) stands.

That is worth one line in the PR body or in #572, because the next person to quote "2.5x prefill" will be quoting the slow arm.

Not this PR's job, and correctly left out: the issue stays open, this is its first change, and the remaining prefill gap is explicitly not claimed to be closed.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT: READY at 865453c — the perf issue was a missing flag in the serve path, not a kernel, and the body proves it by showing what the measurement was actually measuring.

The cause is a call-site omission with a measurable consequence

"1bit serve starts the chat llama-server without -b/-ub. Only the mmproj, embedding and rerank launches set them in app/serve.cpp. So Qwen3.8-Flash-Next ran on llama-server's default 512-token micro-batch, the slow arm of e[very measurement]"

That reframes #572 entirely: 287 tok/s vs 1,679 was not a kernel gap, it was the micro-batch default on one of four launch paths. Which means every prior number on that row was measuring the default, not the engine — and the row's headline ("prefill is 287 tok/s") has been a statement about a flag nobody set.

The scoping is the part I would not have thought to ask for

"It is scoped to qwen4exp, not to every MoE: Qwen3-Coder-30B-A3B is 0.88x at pp512 with 2048, and dense mode[ls]…"

A blanket -ub 2048 would have made one model faster and another 12 % slower — so the recipe is architecture-scoped, with the counter-example quoted. That is what separates a recipe from a global change, and it is the difference between this PR and "turn the knob up for everyone".

And the arm asserts the narrow scope rather than the wide one: "hrx + qwen4exp gets -ub 2048 exactly once, with the recipe named on stderr. qwen[4exp on another device / other model on hrx do not]" — "exactly once" catches a double-application, "named on stderr" makes it observable, and the two negative cases stop the scope from widening silently.

One ask

put the pp512/pp4096 row in the body's first paragraph — the table exists (| path | file | pp512 (ub 2048 vs 512) | pp4096 … |) and it is the justification; the current opening sentence describes the mechanism, and a reader deciding whether this is the fix for #572 needs the number before the explanation. If the after-numbers are owed (the NPU/HRX device was off or busy), say so where the table is — #572 stays open, so "this closes none of the gap yet" versus "this recovers X of it" is the one thing the row's lead needs from this PR.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

The measurement is the strongest part of this: pp4096 205.05 vs 101.05 tok/s (2.03×) on the product path, not a bench harness — that is the number #572 needs, and it justifies the recipe.

Two things from the memory/measurement side, one of which I checked before raising.

1. The claim does not state its load mode. It gives UD-IQ4_XS, ctx 16384, one library but not -lm, and on this fleet prefill is load-mode-dependent: measured on this box, -lm none moves prefill +17.5 %, decode −1.6 % and +604 MiB GTT against the mmap default (recorded as row 70 of KNOBS.md under engine#1668). So 205.05 is not comparable to another lane's Flash-Next prefill number, or reproducible by a reader, until one word says which. 1bit serve defaults to mmap, so if that is what this ran under, say so — it costs a clause and it is the difference between a number and an anecdote. The policy exists because #572's numbers get quoted across lanes.

2. -ub 2048 and a user-supplied -b — I expected a bug and there isn't one. The recipe adds -ub 2048 unless the command line already has -ub, so 1bit serve -b 1024 produces -b 1024 -ub 2048. That looked like an invalid combination; it is not, because llama.cpp clamps: src/llama-context.cpp:272 is

cparams.n_ubatch = std::min(cparams.n_batch, params.n_ubatch == 0 ? params.n_batch : params.n_ubatch);

so the effective ubatch becomes 1024 and nothing errors. The consequence is smaller but real: with -b < 2048 the recipe's documented effect silently does not apply, and nothing says so. One sentence in docs/recipes.md ("-b below 2048 caps it, because llama.cpp clamps ubatch to batch") would close it — or the recipe could decline to add -ub when -b is smaller, which is one condition.

Not disputing: the qwen4exp scoping (the 0.88× Qwen3-Coder-30B-A3B counter-example is the right reason to scope it), the "unless the command line already has -ub" rule that keeps --mmproj's 4096, or the three negative tests. Comment, not a verdict — the head is minutes old.

@bong-water-water-bong
bong-water-water-bong merged commit ab17f6b into main Nov 12, 2026
9 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the cl1077/572-flashnext-ub2048 branch November 12, 2026 16:29
bong-water-water-bong added a commit that referenced this pull request Nov 13, 2026
…BATCH (#572) (#2292)

* recipes: a recipe's -ub / -b does not replace LLAMA_ARG_UBATCH / LLAMA_ARG_BATCH (#572)

llama-server applies its environment first and its command line after
(common/arg.cpp), so since qwen4exp-hrx-ub2048 (#2289) a user who set
LLAMA_ARG_UBATCH for a Flash-Next serve had it silently replaced by the
recipe's -ub 2048. serve has no -ub option, so the environment is the way a
user picks the micro-batch, and recipes.md promises a recipe never overrides
what is already set.

Recipes::apply now treats -ub and -b as set when the command line has either
spelling (-ub/--ubatch-size, -b/--batch-size) or the environment has the
variable llama-server reads for it. Other flags are matched as before.

docs/recipes.md: the rule, and the review note on #2289 that llama.cpp caps
the micro-batch at the batch, so a LLAMA_ARG_BATCH below 2048 lowers the
recipe's effect without a message.

tests/recipes_route.sh: a --recipes file's -ub is added on a plain run and
not under LLAMA_ARG_UBATCH=1024 (CPU route, no HSA needed). With the
environment check removed that check fails.

Co-authored-by: bong-water-water-bong <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

* recipes: compare flags as llama-server parses them (--ubatch_size is --ubatch-size) (#572)

Review of #2292 at e381697: llama-server's parser turns '_' into '-' in a
"--" option before the lookup (common/arg.cpp, pin e6c80014e), so
--ubatch_size 512 is a valid micro-batch, and flag_set's verbatim compare
let a recipe add -ub over it. flag_set now compares both sides in the
parsed form. A "--opt=value" token is rejected by that parser, so it needs
no case (checked at the pin).

tests/recipes_route.sh: a recipe file whose first recipe sets
--ubatch_size 512 and second sets -ub 999 keeps 512 and adds no -ub.
docs/recipes.md: one sentence; recipes.cpp: which flags the table covers.

Co-authored-by: bong-water-water-bong <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: bong-water-water-bong <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant