Skip to content

model: qwen4exp: reduce number of graph splits - #27880

Merged
ngxson merged 1 commit into
masterfrom
xsn/reduce_split_qwen4
Aug 28, 2026
Merged

model: qwen4exp: reduce number of graph splits#27880
ngxson merged 1 commit into
masterfrom
xsn/reduce_split_qwen4

Conversation

@ngxson

@ngxson ngxson commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

Overview

As discussed with @ggerganov , we can regroup the PLE embd lookup to the same split as build_inp_embd, similar to #21612

qwen4 gemma4
image image

Validation

On my mac M5:

# before
0.00.618.526 I sched_reserve:       MTL0 compute buffer size =  2161.01 MiB
0.00.618.528 I sched_reserve:        CPU compute buffer size =   397.05 MiB
0.00.618.529 I sched_reserve:        CPU compute buffer size =   397.05 MiB
0.00.618.530 I sched_reserve: graph splits = 4

# after
0.00.664.041 I sched_reserve:       MTL0 compute buffer size =  2149.03 MiB
0.00.664.044 I sched_reserve:        CPU compute buffer size =   402.05 MiB
0.00.664.044 I sched_reserve:        CPU compute buffer size =   402.05 MiB
0.00.664.045 I sched_reserve: graph splits = 2

Mac + CUDA via RPC:

config before after
Metal only, full offload 4 2
Metal (layer 0) + RTX 5060 Ti over RPC (layers 1-3) 7 5
build MTL0 CPU
before 2161.01 MiB 397.05 MiB
after 2149.03 MiB 402.05 MiB

llama-bench -p 128 -n 32 -r 3

build pp128 t/s tg32 t/s
before 665.65 +/- 38.65 27.99 +/- 1.76
after 665.27 +/- 78.53 27.29 +/- 2.85

Requirements

@github-actions github-actions Bot added the model Model specific label Aug 28, 2026
icedream added a commit to icedream/llama.cpp that referenced this pull request Aug 28, 2026
Cherry-pick of ggml-org/llama.cpp PR ggml-org#27880 (aa1b06d, ngxson).
Regroups the PLE embd lookup into the same split as build_inp_embd,
reducing graph splits (4->2 full offload, 7->5 mixed CPU/GPU).
Fewer split boundaries = fewer H2D/D2H transfers + sync points.
@gopinath87607

This comment was marked as off-topic.

@ngxson
ngxson marked this pull request as ready for review August 28, 2026 17:24
@ngxson
ngxson requested a review from CISC as a code owner August 28, 2026 17:24
@ngxson
ngxson merged commit 6fe7498 into master Aug 28, 2026
23 of 26 checks passed
@ggerganov
ggerganov deleted the xsn/reduce_split_qwen4 branch August 28, 2026 18:43
@Anothers

Copy link
Copy Markdown

Measured this on AMD Strix Halo (Ryzen AI MAX+ 395 / gfx1151, RADV, Mesa 26.1.7) with Qwen3.8-Flash-Next UD-Q4_K_XL. It is a two-way trade on this hardware rather than a straight win — helping short generations and costing long ones by about the same margin.

Setup: -c 131072 -fa on -np 1 -ctk q8_0 -ctv q8_0 --spec-draft-n-max 2 with the MTP draft head from #27842. Two cases at the working point that dominates real traffic on this machine — a short-prompt question generating 400 tokens, and a code-generation prompt generating 600. Three repeats per cell, median reported, ranges within 2%.

build short-prompt chat code generation
before this commit 31.79 37.90
with this commit 33.29 36.13
with this commit, minus #26686 33.45 36.24
upstream minus this commit only 31.76 37.91

Reverting this commit alone reproduces the pre-commit numbers to within 0.1% on both cases, so it is the only variable among the 15 commits between the two baselines I compared. #26686 (shader hoisting for row IDs / expert count) has no measurable effect on this model.

+4.8% on short generation, −4.7% on long generation.

I have not established the mechanism and would rather not guess — graph node count and split count are unchanged in my logs (8642 nodes, 28 splits at -c 131072 in both), so whatever changes is not visible at that granularity here. My working assumption is that hoisting the PLE embedding into the same split as build_inp_embd trades a per-step fixed cost against something that scales with generation length, but I have not measured that.

Not asking for a revert — the short-generation case is the more common one in my own traffic and I am shipping with this commit. Flagging it in case the long-generation regression is unintended, or in case it is worth a per-backend guard.

Happy to run further measurements on this hardware if useful.

jbooth pushed a commit to jbooth/llama.cpp that referenced this pull request Aug 30, 2026
horvay pushed a commit to horvay/atomic-llama-cpp-turboquant that referenced this pull request Aug 30, 2026
sangharshadhyeta pushed a commit to sangharshadhyeta/solid.cpp that referenced this pull request Sep 3, 2026
TheTom pushed a commit to TheTom/llama-cpp-turboquant that referenced this pull request Sep 3, 2026
Ports every upstream qwen4exp (Qwen3.8-Flash-Next) commit from the past
10 days that this fork's manual PR port had not received:

- reduce graph splits by hoisting the PLE embedding gather out of the
  per-layer loop (ggml-org#27880)
- sum indexer heads via strided adds instead of transpose+sum_rows (ggml-org#28023)
- support recurrent state rollback for MTP speculative decoding (ggml-org#28123)
- rewrite QSA sparse-attention block/bias selection: fixes NaN-producing
  bias rows for short sequences, fixes cross-sequence block pooling in a
  unified KV cache, adds mrope duplicate-position ranking, and fixes a
  CUDA rms_norm gridDim.y overflow (ggml-org#27941)
- indexer cache seq_cp staleness fix, ext.x/ext.y state-restore fix,
  PLE-must-be-linear-attention validation, correct -sm tensor
  disablement (ggml-org#27941)
- Hadamard k_rot context-shift crash fix, shared with other archs (ggml-org#27967)

Also replaces raw GGML_ASSERT aborts in hparams loading with proper
error messages, and adds test coverage: a PLE fixture in
test-llama-archs (which required porting the per_layer_token_embd
row-count-from-metadata fix to make it loadable) and a state
round-trip test in test-save-load-state.

Verified against the real Qwen3.8-Flash-Next model: correct generation
at short and long (~66k token) context, and test-llama-archs passes
qwen4exp on both CUDA and CPU.
fewtarius pushed a commit to fewtarius/CachyLLama that referenced this pull request Sep 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

model Model specific

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants