Repository navigation
Conversation
0xArx
force-pushed
the
fix/2478-embed-n-embd-out
branch
from
December 4, 2026 21:11
76949fc to
41aabe3
Compare
This branch has not been deployed
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.
Llama.embed()sized its output withn_embd()(the hidden size), but llama.cpp writes embeddings with the model's output size,llama_model_n_embd_out. For EmbeddingGemma 2 (n_embd 512, n_embd_out 768)embed(),create_embedding()and/v1/embeddingsreturned only the first 512 of the 768 floats.Changes:
LlamaModel.n_embd_out()andLlama.n_embd_out()wrapllama_model_n_embd_out(it falls back ton_embdin llama.cpp, so other models are unchanged).embed()reads both the pooled and the per-token buffers withn_embd_out. I kept the local variable namen_embdso the change stays one line and does not conflict with fix: preserve sequence offsets in unpooled batched embeddings #2395, which fixes the per-sequence offset in the unpooled path.test_embed_uses_model_output_sizedrivesembed()with a fake context whosen_embd_outdiffers fromn_embd(pooled single and batched, unpooled). It fails on main ([0.0, 1.0] != [0.0, 1.0, 2.0]) and passes here.test_real_llama_embeddingsnow also checkslen(embedding) == n_embd_out().Testing (macOS arm64, Metal build of the vendored llama.cpp f5e6915):
ggml-org/embeddinggemma-2-GGUFembeddinggemma-2-Q8_0.gguf, the issue's repro: main returns 512 floats, this branch 768 (pooled, single and batched; unpooled rows are 768 wide). With fix: preserve sequence offsets in unpooled batched embeddings #2395's one-line offset fix applied on top, batched unpooled output also matches the single-input output.pytest tests: 27 passed.make lint(ruff check + format --check): clean.Fixes #2478