Repository navigation
server : allow RANK pooling batch splitting for causal LLM rerankers (ie. Qwen3 and Qwen3-VL) - #28876
Conversation
|
We don't need this arch check do we? We already have And then just a generic |
e669baf to
bc90e23
Compare
|
@CISC I have made the changes you requested. I made the attention type function generic and removed the hardcoding of the models. I also updated the bidirectional encoder model's hparams in the /models folder to show that they do not have causal attention. This makes the patch more generic and flexible for future changes. |
Undo this, they should all have this set in their GGUF metadata already. |
bc90e23 to
b14e308
Compare
|
Undid the model param changes. Are we good to go? |
Not sure, I'm not 100% convinced as it's possible to override attention type with |
|
If you are worried about overrides during runtime, we can add a public getter llama_get_causal_attn(ctx) alongside the existing llama_set_causal_attn(ctx), then use that in can_split() instead of llama_model_is_causal(model)? llama_get_causal_attn(ctx) would be the actual runtime cparams we can use to check splitting? |
Rerank models fall into two categories: bidirectional cross-encoders (BERT, etc.) that require all tokens in a single physical batch, and causal LLMs repurposed as rerankers (Qwen3, Qwen3-VL) that can use chunked prefill like any other decoder. Previously the server rejected all RANK-pooling inputs larger than n_ubatch, and the graph builder hardcoded QWEN3/QWEN3VL arch checks to determine last-token pooling. This broke long-document and multimodal reranking for causal models. Fix: expose llama_get_causal_attn(ctx) so the server can check the effective runtime attention type (reflecting any --attention override or set_causal_attn call). Also expose llama_model_is_causal(model) for querying the static architectural property from GGUF metadata. can_split() now permits chunked prefill for RANK pooling when the context is causal. The graph builder's inline arch check is replaced with the same cparams.causal_attn predicate, removing the duplication. Assisted-by: Opencode/Qwen3.8-27B
b14e308 to
da3ad31
Compare
…ream PR ggml-org#28876) Squash of ggml-org#28876 at da3ad31. The last-token RANK pooling condition now keys on causal_attn instead of an arch list, which covers the Qwen3.5 classifier models added in f8b0dc15f. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Assisted-by: Claude Opus 5
|
@CISC Sorry to bother again, but do you think this PR will be merged? I have other PRs referencing this one that supports multimodality rerankers and embeddings support. |
CISC
left a comment
There was a problem hiding this comment.
LGTM, @ggerganov should sign off on the API.
|
@ggerganov fixed the issues. LGTM? |
Assisted-by: opencode
1212af5 to
38a3d3d
Compare
|
Just force pushed the trailing whitespace fix that the CI flagged. No other changes. |
ggml-opencl.cpp: this branch's layout kept, the three upstream OpenCL changes (ggml-org#29401 q5_K bin kernels, ggml-org#29439 q8_0 dp4a bin kernel, ggml-org#29503 bin kernel loading condition) replayed onto it. The q5_K bin layout and the q8_0 dp4a bin GEMM are opt-in here (GGML_OPENCL_Q5_K_BIN=1, GGML_OPENCL_Q8_0_BIN_DP4A=1): by default they would take the spec/MTP verify widths from the cooperative-K and narrow kernels. q5_K bin is limited to 2-D weights, q8_0 bin to N > 16. common/speculative, server-context: this branch's llama_batch implementation kept (tree drafting puts several seq_ids on one token, which common_batch cannot hold); a common_batch overload of common_speculative_process converts for the new callers, the mtmd post-decode callback takes the new embd batch, and ggml-org#28876, ggml-org#29556 and ggml-org#29648 are applied to server-context.
…ch split; keep MoE packs + decision engine) conflicts: llama-graph.cpp (kept use_moe_packs wrapper + upstream GLM5_NEXT clamp arch + MISTRAL4 F32 down-proj), test-backend-ops.cpp (test_mul_mat_id keeps upstream m_v at arg 10, our skip_ids appended at arg 11; call sites updated), llama-bench.cpp (both sched_async_cpu and repack fields). decision-engine: local batch helpers (upstream ggml-org#29601 removed common_batch_clear/add). local MSVC CPU build of llama-server, test-backend-ops, llama-bench OK.
Overview
Traditionally, rerank models were bidirectional cross-encoders like BERT, which mandated that all the tokens in the input must be within the same physical batch due to bidirectional attention. However, the Qwen3 and Qwen3-VL family of rerankers are just repurposed LLMs (causal decoders). This meant that prefill does not have to be all within the same physical batch. They can be chunked into batches just like any other decoder LLM.
Currently, llama-server is outdated in enforcing this difference. llama-server is too conservative and forces all rerank models to have to batch their prefill into one physical batch (default 512 tokens). In other words, if the document is greater than the physical batch size, the rerank doesn't work. Thus, long documents or images cannot be fed into the rerank model in llama.cpp
Code Changes
Expose llama_get_causal_attn(ctx) so the server can check the effective runtime attention type, reflecting any --attention override or set_causal_attn call. (cparams).
can_split() now permits chunked prefill for causal RANK models instead of rejecting inputs larger than n_ubatch. The graph builder's inline arch check is refactored to use the same cparams.causal_attn predicate, removing the duplication.
Additional information
This first PR is in support of adding full multimodal support for the /embedding and /rerank endpoints. See here for more context (#18665 (comment))
Requirements