Skip to content

llama : query chunking for Inkling 2, QFN, GLM Flash, etc - #27

Draft
sanmai wants to merge 34 commits into
masterfrom
feat/moe-ffn-chunks
Draft

sanmai wants to merge 34 commits into
masterfrom
feat/moe-ffn-chunks

Conversation

@sanmai

@sanmai sanmai commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Overview

The goal to reduce memory footprint of work buffers via sub-ubatch attention:

  • Store K/V for the whole ubatch, so each query sees the same cells it would see in one pass
  • Take the first N tokens of the batch, at 1 GB budget per tensor (so 1024 tokens at 262144 ctx for QFN)
  • Build the mask, indexer score, etc
  • Run the attention
  • Free that mask and reuse it for the next chunk
  • Join the outputs, and since chunks attend to the same kv cache the result is same*

*as results are different with different ub

This is an early working prototype, and I mostly focused on Inkling 2 Mini as far as benchmarking, and QFN as far benchmarking and correctness.

QFN benchmarks

build ub MoE cache MiB CUDA0 compute MiB warm pp best t/s warm tg best t/s decode hit rate
master 4096 17700 5046.28 1258.7 35.53 83.47%
master 8192 13400 9236.56 1960.6 32.32 75.73%
chunks 4096 19900 2841.28 1286.1 34.58 85.27%
chunks 8192 18500 4180.56 2036.5 36.34 84.71%

Inkling 2 Mini

build ub MoE cache MiB CUDA0 compute MiB warm pp best t/s warm tg best t/s decode hit rate
master 1024 19675 8993 749.8 42.42 94.99%
master 2048 17075 11359 936.1 32.96 91.32%
master 4096 11950 16134 970.3 30.67 82.82%
master 8192 1625 25793 758.2 16.06 34.24%
chunks 1024 19675 8993 748.1 41.37 93.28%
chunks 2048 18825 9567 953.9 36.07 93.71%
chunks 4096 15825 12239 978.9 37.70 90.88%
chunks 8192 3200 24144 756.1 18.92 48.06%

To compare with 32752:

Compute buffer, GiB. Dry run with llama-fit-params, -fa on, KV q8_0/q8_0, no -cmoe.

ctx ub 512: master -> chunks ub 1024: master -> chunks ub 2048: master -> chunks
32k 3.28 -> 2.28 6.56 -> 2.56 13.13 -> 3.13
90k 8.69 -> 2.44 17.39 -> 2.88 34.78 -> 3.78
200k 19.08 -> 2.72 38.17 -> 3.48 76.36 -> 5.01

Speed, t/s, best warm round. Context 10240, -cmoe, KV q8_0/q5_1, largest MoE cache for 5090.

test ub 1024: master -> chunks ub 2048: master -> chunks ub 4096: master -> chunks ub 8192: master -> chunks
pp9193 749.8 -> 748.1 936.1 -> 953.9 970.3 -> 978.9 758.2 -> 756.1
tg1024 @ d9193 42.42 -> 41.37 32.96 -> 36.07 30.67 -> 37.70 16.06 -> 18.92

Additional information

Prior implementation: link TBD

Requirements

@sanmai sanmai changed the title QSA token chunking chunking Nov 13, 2026
@sanmai sanmai mentioned this pull request Nov 22, 2026
@sanmai sanmai changed the title chunking query chunking for Inkling 2, QFN, etc Nov 23, 2026
@sanmai sanmai changed the title query chunking for Inkling 2, QFN, etc query chunking for Inkling 2, QFN, GLM Flash, etc Nov 23, 2026
@sanmai sanmai changed the title query chunking for Inkling 2, QFN, GLM Flash, etc llama : query chunking for Inkling 2, QFN, GLM Flash, etc Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant