Repository navigation
Conversation
The selection mask and the indexer scores of a QSA layer are [n_kv, n_tokens] and [n_pool, n_tokens]. Score, select and attend 2048 query tokens at a time, so the chunks of a layer reuse one chunk worth of memory. The views of the token inputs are shared by the layers, so each slice is uploaded once. LLAMA_QSA_CHUNK sets the chunk size for tests, 0 disables the split.
A [n_kv, 1, 1, 1] mask applies to every token and gives a [n_kv, n_tokens] result, so a selection that is causal on its own does not need a dense [n_kv, n_tokens] mask as its source.
Like llm_graph_input_attn_kv, do not fill a mask that no op reads.
A token sees only the pools that end at or before it and the tail up to itself, all of its own sequence, so every kept cell is already visible in the kq_mask and the selection is causal on its own. Keep a zero row instead of the kq_mask cells, then no op reads the dense [n_kv, n_tokens] mask, and the graph does not allocate or upload it.
Master has the final PR 30640, which renames ggml_kpool_mask to ggml_top_k_mask and broadcasts the mask natively; take its version of the op and call it with the zero row from qwen4exp.
|
@dagbdagb Replying here. Asked one of the agents to benchmark and find the best setting. |
am17an
left a comment
There was a problem hiding this comment.
Is the main problem here at long context? i.e. uploading the kq mask?
|
Not entirely sure if that question was directed at me or not. If it is: The help-text for |
|
@dagbdagb it was not for you. Re the guidance, yes I will make some changes there soon |
|
These are ideas pulled straight from Strata, with the goal to reduce memory footprint of work buffers:
Shrinking And there's a bug with CUDA top_k tie ordering - haven't looked into it.
1750 t/s pp is the major win here |
|
@am17an Feel free to slice and dice this thing into pieces as much as you want or need. |
|
Okay so this is because the kq_mask being the largest user of the compute buffer at these ub sizes. But do we need to allocate the kq_mask for this model since we're using sparse attention? cc @ServeurpersoCom if you have a good idea. EDIT: maybe I'm not correct and need to measure again. |
|
all 12 attention layers are QSA so we should not need kq_mask |
ggml_top_k_mask with a single keep row returns [n_kv, n_tokens], while build_attn_qsa expects the kq_mask layout [n_kv, n_tokens/n_stream, 1, n_stream]. With several streams the shape assert failed at graph reserve.
|
it looks it may help with large ubatch on dsv4.1/glm5.3 as well |
Upstream's version is kept wherever it does what the branch did; the branch's stays where upstream has none: - MoE cache: the constructor takes upstream's no_alloc flag beside the CPU share, buffers come from llama_memory_bufs::alloc_buf; phases and host mode as before. - build_moe_ffn: the branch's experts lambda (cache slots, host mode, shared batches) with upstream's DeepSeek-4.1 and Laguna changes. - qwen4exp: the selection is built over the cache cells as upstream now does (ggml-org#30965, ggml-org#31243), the branch keeps its query chunks (ggml-org#30815's earlier version); upstream's hc_mix outputs and merged tensors. - CUDA MMQ: the tile map of active MoE tiles also launches upstream's fused gate/up/GLU kernel (ggml-org#31188, ggml-org#29948); the fused paths zero the rows of negative ids as ggml_cuda_mul_mat_id does. - CPU MUL_MAT_ID: upstream's -1 skip (ggml-org#26631) and the branch's two-pass grouping agree, negative ids are skipped. - tests: the QSA chunk tests move with upstream's archs tests; a MUL_MAT_ID result marked by ggml_mul_mat_id_set_negative_ids runs on CUDA again, only unmarked ones are excluded ([TAG_MUL_MAT_ID_SKIP]). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01P3vd8iuiuxiev7wMPyJmSf
# Conflicts: # src/llama-graph.cpp # src/models/models.h # src/models/qwen4exp.cpp # tests/CMakeLists.txt
LLAMA_QSA_CHUNK is read at each graph build, so one process can compare contexts with chunking on and off. The existing chunk tests compare CPU against GPU with the same chunks, so a misplaced chunk passes them.
The empty QSA chunk has one mask row and zero top-k rows, which the original asserts accept. Only set_rows and the meta backend need the empty-shape changes: without them the unfused selection (Vulkan, SYCL) divides by zero and the meta backend asserts on the empty concat source.
5127cc1 dropped it by mistake, the meta device of test-llama-archs needs it.
|
Data point from a 2-node Strix Halo (gfx1151) Vulkan+RPC setup, 1M context with GLM-5.3-Flash. Adjacent to your chunked QSA work, so posting here instead of a separate issue. Setup
Not a minimal repro: the model needs both nodes, so RPC is part of the setup, not a variable I can remove. Results
v1.0.0 log: With a temporary ≥2 GiB allocation log (op/shape/sources), the remaining large tensors are the k-pool update gathers:
Local WIP chunkingSplitting the token axis (256 tokens per chunk, per-chunk attention, At 1M it then hangs after Context limits: the 512k run that loads and answers used v0.7.0 + the token-axis patch; vanilla v1.0.0 was not tested at 512k, and master ( Environment note (not a request)Capping the RPC worker with Questions
I can share the WIP patch (~320 lines) and full logs if useful. No action requested — just a data point. |
|
@StormstoutLau |
Overview
This is just a prototype. No review is needed.
Additional information
Benchmarks with UD-Q4_K_XL:
KLD changes with batching and chunking is just one more batch shape
Requirements