Repository navigation
launch embedding ggufs with --embedding - #8524
Conversation
POST /v1/embeddings always failed with llama-server's 501 "This server does not support embeddings. Start it with `--embeddings`", whatever GGUF was loaded. The proxy in routes/inference.py forwards to the resident chat llama-server, and load_model never passed the flag; nothing in llama.cpp turns it on from the model itself (common/arg.cpp sets params.embedding only from --embedding/--embeddings, --reranking, and the embedding preset). Decide it per GGUF instead. Embedding architectures write `<arch>.pooling_type`, which the existing header parser reads in about 30ms with no hub call, so _read_gguf_metadata now picks it up and load_model emits --embedding when the value pools into one vector per sequence: MEAN, CLS or LAST. NONE (0) pools nothing, and RANK (4) is a reranker head, whose pooled buffer llama_context sizes to n_cls_out while llama-server's send_embedding reads n_embd_out floats from it (n_embd, absent embedding_length_out). Both stay off, so those models keep returning the 501 they return today. Serving slots come down with the micro-batch on an embedding launch. llama-server forces n_batch = n_ubatch under --embedding (server.cpp, the non-causal single-ubatch constraint of ggml-org/llama.cpp#12836), which undoes the floor _emitted_n_batch applies and then aborts on GGML_ASSERT(n_outputs_max <= cparams.n_outputs_max). Measured with bge-small-en-v1.5 f16 on llama-server 10360: --parallel 4 -b 4 -ub 3 --embedding exits 134, the same argv without the flag serves. The clamp lands before the KV estimates so the fit matches what launches, and test_the_recorded_micro_batch_is_derived_from_the_slots_that_launched counts one re-derivation per point that moves the slot count, so its expected count goes from three to four. The RAG path is unaffected: it already spawns its own dedicated `llama-server --embedding --pooling cls` in core/rag/embed_llama_server.py. The denylist is unchanged, so a user still cannot pass the flag by hand; its comment claimed --embedding breaks the chat hop, which the shipped build does not do (params.embedding gates only the embeddings and rerank routes), so it now records the real reasons. Verified against unsloth/bge-small-en-v1.5-GGUF (f16, bert, pooling_type=2) on llama-server 10360: without the flag POST /v1/embeddings returns the 501, with it plus the rest of the launch args Studio emits (--flash-attn on, --no-context-shift, --parallel 4, --jinja, --metrics, -c 512) it returns 384-dim vectors.
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
+1, would like to see this resolved |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 94e7030fad
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| f"{arch}.attention.head_count_kv": "n_kv_heads", | ||
| f"{arch}.attention.head_count": "n_heads", | ||
| f"{arch}.embedding_length": "embedding_length", | ||
| f"{arch}.pooling_type": "pooling_type", |
There was a problem hiding this comment.
Parse pooling metadata regardless of KV order
When a valid GGUF lists <arch>.pooling_type before general.architecture, arch_keys is still empty, so the parser skips the pooling value and never revisits it. _pooling_type therefore remains None, causing load_model to omit --embedding and leaving /v1/embeddings returning 501 for that model. Buffer architecture-dependent entries or determine the architecture before parsing them.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 032948a: pooling metadata is buffered and bound after general.architecture, so valid GGUF KV order no longer changes detection. Spec: https://github.com/ggml-org/ggml/blob/master/docs/gguf.md
| _embedding_slots, | ||
| _effective_ubatch, | ||
| ) | ||
| n_parallel = _embedding_slots # allow-slot-clamp: llama-server would abort |
There was a problem hiding this comment.
Mirror the embedding slot clamp in the admission estimate
When an embedding load is requested during active training with an effective micro-batch below n_parallel, this reduces the runtime slot count, but can_load_chat_during_training still passes the original n_parallel to _estimate_gguf_required_gb. That estimator charges slot-scaled KV and compute buffers, so a model close to the coexistence limit can receive a 409 even though the reduced-slot process would fit. Apply the same header-based embedding clamp before the admission estimate.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 032948a: the coexistence estimate now applies the same embedding micro-batch slot clamp as launch. Upstream constraint: ggml-org/llama.cpp#12836
|
|
||
| # llama-server 501s on /v1/embeddings without this; pooling stays model-default. | ||
| if self.is_embedding_gguf: | ||
| cmd.append("--embedding") |
There was a problem hiding this comment.
Budget embedding-mode compute buffers before launch
Enabling embedding mode makes embedding GGUFs reach the existing _estimate_compute_buffer_bytes placement path, whose non-tensor formula omits the first slot's output buffer and explicitly documents that it would under-count embeddings. Because GPU placement, context fitting, and the training coexistence guard all use this estimate before the command is spawned, a large micro-batch or output width can be admitted with insufficient VRAM and then OOM or evict a running experiment. Add embedding-specific compute-buffer sizing keyed from is_embedding_gguf.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 032948a: embedding mode now budgets the first full output buffer in both local placement and training admission estimates. Upstream allocation: https://github.com/ggml-org/llama.cpp/blob/master/src/llama-context.cpp
| if self.is_embedding_gguf: | ||
| cmd.append("--embedding") |
There was a problem hiding this comment.
Prevent pooling overrides from bypassing the embedding gate
When the header reports MEAN/CLS/LAST but the user supplies the currently allowed --pooling none or --pooling rank in llama_extra_args, those extras are appended after this managed flag and override the model default—the dedicated RAG launcher likewise uses --pooling cls explicitly in core/rag/embed_llama_server.py:243-245. The server is therefore still started with --embedding; NONE makes the endpoint fail, while RANK defeats this change's buffer-safety exclusion and can make send_embedding read an embedding-width result from the smaller classifier buffer. Treat --pooling as managed or base this gate on the effective override.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 032948a: --pooling is now managed so last-wins extras cannot switch an embedding launch to NONE or RANK after the header safety gate. Upstream argument semantics: https://github.com/ggml-org/llama.cpp/blob/master/common/arg.cpp
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f738da1b9d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if self.is_embedding_gguf: | ||
| cmd.append("--embedding") |
There was a problem hiding this comment.
Clear inherited pooling before enabling embeddings
When the child inherits LLAMA_ARG_POOLING=none or LLAMA_ARG_POOLING=rank, this block still emits only --embedding: _llama_server_env_for_binary preserves inherited LLAMA_ARG_* values, and the launch-time environment reconciliation never removes pooling. Because llama.cpp applies those environment defaults before argv and no managed --pooling value overrides them, NONE makes /v1/embeddings fail while RANK bypasses the header-based safety and buffer-budgeting gate. The new denylist closes only the extra-arguments path, so scrub the inherited pooling variable or explicitly emit the detected safe pooling mode.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in f4311f3. The managed launch now removes inherited LLAMA_ARG_POOLING after constructing the child environment, so the GGUF header remains the sole pooling source and cannot be changed to none or rank by a parent-process default. Added a regression assertion and reran the focused backend suite: 491 passed.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f4311f3573
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| env = self._llama_server_env_for_binary(binary) | ||
| # Pooling is derived from the GGUF header and is a managed setting. | ||
| # An inherited env default would otherwise override that decision. | ||
| env.pop("LLAMA_ARG_POOLING", None) |
There was a problem hiding this comment.
Scrub the inherited reranking mode
When the parent environment sets LLAMA_ARG_RERANKING=true, removing only LLAMA_ARG_POOLING does not preserve the header-derived mode: llama.cpp's reranking argument enables embeddings and selects RANK pooling, while the later managed --embedding flag does not restore the model's pooling type. A sequence-pooling GGUF can therefore pass this change's safety gate and buffer estimate but launch with the classifier-width RANK output that the gate explicitly excludes. Fresh evidence beyond the prior pooling fix is that LLAMA_ARG_RERANKING remains in the constructed child environment; scrub it alongside LLAMA_ARG_POOLING.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 79b49d6. Managed embedding launches now remove both LLAMA_ARG_POOLING and LLAMA_ARG_RERANKING, so the GGUF header cannot be replaced with rank pooling by an inherited environment default. The regression assertion covers both variables.
| output_slots = ( | ||
| slots if getattr(probe, "is_embedding_gguf", False) else max(0, slots - 1) |
There was a problem hiding this comment.
Budget uncached remote embedding GGUFs
When training is active and the requested HF GGUF is not cached yet, _estimate_gguf_required_gb bypasses this header-aware local branch and its remote path still hardcodes the chat formula at routes/inference.py:6125, charging max(0, n_parallel - 1) output buffers. With the default single slot that charges zero, but after download the pooling header enables --embedding and the loader budgets the first full output buffer, so a model near the coexistence limit can be admitted and then OOM or evict the running experiment. Fresh evidence beyond the prior compute-buffer fix is that the uncached remote branch still has no corresponding embedding/unknown-header allowance; conservatively include the first buffer there or probe the remote header before admission.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 79b49d6. The uncached remote branch cannot inspect the GGUF header, so it now conservatively reserves output buffers for every slot as if embeddings will be enabled after download. The focused backend gate passes with 491 tests.
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 79b49d6c12
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| # The remote header is unknown, so reserve as if it enables embeddings. | ||
| _out_slots = max(1, n_parallel) |
There was a problem hiding this comment.
Reserve embedding buffers for default remote batches
When an uncached remote GGUF is loaded during training without explicit batch overrides, _extra_args_n_ubatch returns None, so the enclosing if effective_ubatch: skips this newly added embedding output-buffer reserve even though llama-server launches with its default 512-token micro-batch. The guard can therefore admit a default single-slot embedding model near the coexistence limit and then OOM or evict the training job. Fresh evidence after the stated fix is that _out_slots remains reachable only when a batch or micro-batch override makes effective_ubatch non-null; use the known default micro-batch for this conservative remote estimate as well.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in a04989f. When the remote header is unavailable and no batch override is present, the admission estimate now uses llama.cpp's known 512-token default micro-batch instead of skipping the compute reserve. The default single-slot regression now requires more than the weights-only estimate; 491 focused tests pass.
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a04989f87d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for _pooling_var in ("LLAMA_ARG_POOLING", "LLAMA_ARG_RERANKING"): | ||
| env.pop(_pooling_var, None) |
There was a problem hiding this comment.
Scrub inherited embedding enablement
When the parent sets LLAMA_ARG_EMBEDDINGS=true and a RANK-pooled GGUF is loaded, this environment block removes pooling and reranking but preserves llama.cpp's embedding argument environment alias. Because the managed command emits no disabling flag for models rejected by is_embedding_gguf, the inherited value still exposes /v1/embeddings, bypassing both the RANK safety gate and its embedding-buffer budget; scrub LLAMA_ARG_EMBEDDINGS alongside the other mode variables.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 3245420. The managed launch now removes LLAMA_ARG_EMBEDDINGS together with pooling and reranking defaults, so a parent environment cannot enable embeddings for a header mode that Studio rejected and did not budget. The regression covers all three variables; 491 focused tests pass.
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
commented
Aug 12, 2026
|
@codex review |
commented
Aug 12, 2026
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Problem
POST /v1/embeddingsreturns llama-server's 501 for every GGUF:{"error":{"code":501,"message":"This server does not support embeddings. Start it with `--embeddings`","type":"not_supported_error"}}The endpoint in
studio/backend/routes/inference.pyproxies to the resident chat llama-server, andLlamaCppBackend.load_modelnever passed the flag. Nothing in llama.cpp enables it from the model:common/arg.cppsetsparams.embeddingonly from--embedding/--embeddings,--reranking, and the embedding preset, andserver-context.cppgates the handler on that field alone. So the endpoint could not succeed for any model.The flag was left off because
llama_server_args.pydenylists it in user extra args, on the stated grounds that it restricts llama-server to embeddings and breaks the chat hop.Fix
Decide it per GGUF. Embedding architectures write
<arch>.pooling_typeinto the GGUF header, which the existing header-only parser reads in about 30ms with no hub call._read_gguf_metadatanow picks it up,is_embedding_ggufexposes it, andload_modelemits--embeddingwhen the model pools into one vector per sequence.Only MEAN (1), CLS (2) and LAST (3) qualify:
llama_contextsizes its pooled buffer ton_cls_out(2 for a yes/no reranker) whilesend_embeddingreadsn_embd_outfloats from it, which falls back ton_embdwhen the header carries noembedding_length_out. llama.cpp's own converter writes RANK plusclassifier.output_labelsfor Qwen3 rerankers, so this is reachable from a published model. Those keep returning today's 501; serving them needs--reranking, which Studio does not expose.Pooling itself is left at the model default, so a mean-pooled model keeps its own. The denylist is unchanged: the header probe is the only thing that turns the flag on. Its comment claimed
--embeddingbreaks the chat hop, which the shipped build does not do (params.embeddinggates only the embeddings and rerank routes), so it now records the real reason.Serving slots follow the micro-batch down
--embeddingmakes llama-server forcen_batch = n_ubatch(tools/server/server.cpp, the non-causal single-ubatch constraint of ggml-org/llama.cpp#12836). That undoes the floor_emitted_n_batchapplies to keep-bat or above the slot count, and llama-server then aborts:Measured with
bge-small-en-v1.5f16 on llama-server 10360:--parallel 4 --batch-size 4 --ubatch-size 3 --embeddingexits 134, the same argv without the flag serves. Micro-batch is a first-class per-model field with a floor of 1, so a user setting it below the 4 default slots would hit this on a model that loads fine today.load_modelnow reduces the slot count to the effective micro-batch on an embedding launch, before the KV estimates so the fit matches what launches, and re-derives the micro-batch at the reduced count. It floors at one slot, since a degenerate-b 0extra resolves to a zero micro-batch and--parallel 0is rejected at argument parse. Verified:--parallel 3 -b 4 -ub 3,--parallel 2 -b 4 -ub 2and--parallel 1 -b 2 -ub 1all serve.One limit this does not lift: a pooled slot cannot split a prompt across micro-batches, so an input longer than the physical batch (512 by default) comes back as a 500 "input is too large to process". That is still an improvement on the 501 every input got before, and raising the batch for embedding launches is left to a separate change.
This adds a fourth
_ubatch_for_slotscall, sotest_the_recorded_micro_batch_is_derived_from_the_slots_that_launchedmoves from three re-derivations to four. The invariant it pins is unchanged: one re-derivation per point that moves the slot count, plus the post-launch record.The RAG path is untouched. It already spawns its own dedicated
llama-server --embedding --pooling clsinstudio/backend/core/rag/embed_llama_server.py.Verification
Against
unsloth/bge-small-en-v1.5-GGUF(f16, archbert,bert.pooling_type = 2) on llama-server 10360:POST /v1/embeddingsThis server does not support embeddings--embeddingplus the rest of Studio's args (--flash-attn on --no-context-shift --parallel 4 --jinja --metrics -c 512)studio/backend/tests/test_embedding_gguf_launch.pyadds 16 tests: the header probe across MEAN/CLS/LAST, NONE, RANK, a chat GGUF, reset between parses, reset on unload, an arch-prefix mismatch, theload_modelemission and its guard, the slot clamp and its ordering, and that the denylist still rejects the flag from extra args.Neighbouring suites pass: 813 tests across
test_batch_sizes_per_load,test_compute_buffer,test_kv_cache_estimation,test_gpu_memory_mode,test_native_context_length,test_llama_server_argsandtest_gguf_metadata.scripts/lint_no_parallel_clamp.pypasses; the new clamp carries an# allow-slot-clamp:marker.No GPU checks were run: the change is CPU-side launch-argument construction, and the llama-server runs above were
-ngl 0.test_llama_cpp_mtp_detection.py::test_probe_server_capabilities_gates_known_broken_dspark_prebuiltfails in combined runs on unmodifiedmainas well, so it is unrelated to this change.Manual test
unsloth/bge-small-en-v1.5-GGUF.curl -X POST http://127.0.0.1:<port>/v1/embeddings -H 'Content-Type: application/json' -d '{"input":"hello world"}'