Repository navigation
Conversation
Add an opt-in no-logits mode for embedding contexts without backend samplers. This omits the vocabulary projection and raw logits output allocation and copy while preserving embedding outputs.
|
Hi @nanlongyu, thanks for your contribution! Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:
Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below. |
|
Glad to see someone tackling this. I hit the same thing a few months ago and wrote it up in #24713 (closed by the stale bot, no maintainer reply), with benches across 80 archs on CUDA / ROCm / Metal / CPU, so maybe that counts as the "prior discussion" the bot is asking for here. Short version of what I measured with the same gate (
One thought on the design: given the outputs are identical and nothing consumes the logits when If it helps for parity checks, I have a public corpus (1023 Gutenberg chunks) I used for control vs patched: https://gist.github.com/m4zar/cf5f2f82c51233944bb9493efe2bf692 Happy to re-run the benches on top of this branch if useful. |
|
Thanks for this — it covers most of what we hit running Qwen3-Embedding-8B and Qwen3-Reranker-8B (Q8_0, Vulkan, RTX 5060 Ti 16 GB). One piece it doesn't reach, in case it's useful here or as a follow-up: The duplicated output tensor is still loaded, and placed with the output layer. Qwen3's embedding/reranker GGUFs carry no We've been carrying a small local patch for this since 2026-10-05, applied to
The speed and compute-buffer gains are the same ones this PR gives (the LM head no longer runs on every token in embedding mode). The ~629 MiB of model memory is the part that needs the load-time check. Keying it on the file's declared pooling type kept it safe for us: generation GGUFs don't normally declare one, so nothing changed for our chat models, and the same file can't later be asked for logits without an explicit error. Not proposing our exact patch — it's shaped around our use, and the opt-in route here is more conservative — just flagging the load-time half with numbers, in case it's worth folding in (or a separate PR, if the maintainers prefer). Happy to share the diff or test anything. Related: #30255 frees the host logits buffer when the graph has no logits tensor; for Qwen3-based embedding models the graph still builds (Posted by Steve Flaherty; the investigation, measurements and this write-up were done with Claude.) |
|
Superseded by #30445 |
Overview
This PR adds the no-logits mode which is an optional optimization for embedding workloads. When a causal model is used only for embeddings, the request needs the hidden states and pooled embeddings, but the regular path may still run the vocabulary projection and copy the unused logits to host memory. Enabling this mode skips that extra work while leaving the embedding calculation itself unchanged.
Additional information
llama_context_paramsnow includes a publicno_logits_for_embeddingsoption, which is disabled by default.--no-logits-for-embeddingsandLLAMA_ARG_NO_LOGITS_FOR_EMBEDDINGS.LLAMA_CONTEXT_TYPE_DEFAULT, and do not configure a backend sampler.llama_get_logits()andllama_get_logits_ith()returnNULL.For example, a Qwen3 embedding request using LAST pooling would normally compute the hidden states and then run the LM head to produce a
[tokens, vocabulary]logits tensor, even though those logits are not used afterward. With--no-logits-for-embeddingsenabled, the graph ends at the embedding output instead. LAST pooling still uses the same embedding result, while the LM-head computation and host-side logits buffer are left out.The tests cover the option from the CLI through to the runtime context. For Llama and Qwen3, they compare the enabled and disabled paths and expect both per-token and pooled embeddings to match exactly. There is also coverage for BERT and Llama Embed models, which do not have an LM head. Additional cases check that eligible embedding requests leave out the LM-head/logits branch, while text-generation and backend-sampler requests continue to produce logits.
Requirements