context : use n_embd_out for pooled embedding extraction#20840
Merged
ggerganov merged 1 commit intoggml-org:masterfrom Mar 21, 2026
Merged
context : use n_embd_out for pooled embedding extraction#20840ggerganov merged 1 commit intoggml-org:masterfrom
ggerganov merged 1 commit intoggml-org:masterfrom
Conversation
The MEAN/CLS/LAST pooling paths in encode() and decode() used n_embd_inp() (16384 for qwen3vl with deepstack) to read from the pooled embedding tensor, which only has n_embd_out() (4096) floats per sequence. This caused a tensor read out of bounds assertion. Fixes embedding mode for Qwen3-VL-Embedding models.
ggerganov
approved these changes
Mar 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The MEAN/CLS/LAST pooling paths in
encode()anddecode()usen_embd(set tohparams.n_embd_inp()) to read from the pooled embedding tensort_embd. For models with deepstack layers (qwen3vl),n_embd_inp()returns 16384 while the pooled tensor only hasn_embd_out()= 4096 floats per sequence, causing:GGML_ASSERT(offset + size <= ggml_nbytes(tensor) && "tensor read out of bounds")
The fix uses
hparams.n_embd_out()instead, consistent with howPOOLING_TYPE_NONE(line 1756) already handles it.Affected models
Qwen3-VL-Embedding-8B (and any model with
n_deepstack_layers > 0)Test
Tested with
Qwen3-VL-Embedding-8B-Q4_K_M.gguf,--embedding --pooling last:No impact on models without deepstack (
n_embd_inp == n_embd_out).Use case
Qwen3-VL-Embedding can create embeddings for both images and text in the same vector space. A typical workflow is to index images using the full model on GPU, then run text-only retrieval queries against that index using a quantized GGUF on CPU. This fix makes the second step possible.
Disclosure
AI was used as a research/debugging aid to locate the root cause.