Skip to content

Get up and running with Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models.

server: fix multimodal embedding load with small num_ctx (#18973)

Jeffrey Morgana5276525531a
diff --git a/llm/llama_server.go b/llm/llama_server.go
index 3b59c2b99..b58b285e2 100644
--- a/llm/llama_server.go
+++ b/llm/llama_server.go
@@ -89,22 +89,6 @@ const (
mmprojOffloadHeadroom = 1 << 30
)
-// DefaultEmbeddingNumBatchForContext caps the embedding batch default to the
-// active context length before it is passed to llama-server.
-func DefaultEmbeddingNumBatchForContext(numCtx int) int {
- if numCtx > 0 {
- return min(DefaultEmbeddingNumBatch, numCtx)
- }
- return DefaultEmbeddingNumBatch
-}
-
-// WithDefaultEmbeddingNumBatch applies the llama-server embedding batch
-// default to a copy of opts.
-func WithDefaultEmbeddingNumBatch(opts api.Options) api.Options {
- opts.NumBatch = DefaultEmbeddingNumBatchForContext(opts.NumCtx)
- return opts
-}
-
// LlamaServerBatch resolves the batch size and extra memory allowance used
// when deciding whether to load a model alongside other models.
func LlamaServerBatch(f *gguf.Model, opts api.Options, completion bool) (int, uint64) {
diff --git a/server/routes.go b/server/routes.go
index be7dfb597..caedc1272 100644
--- a/server/routes.go
+++ b/server/routes.go
@@ -162,7 +162,7 @@ func (s *Server) modelOptionsWithEmbeddingBatchDefault(model *Model, requestOpts
}
if applyEmbeddingBatchDefault {
- opts = llm.WithDefaultEmbeddingNumBatch(opts)
+ opts.NumBatch = llm.DefaultEmbeddingNumBatch
}
if model != nil && model.DraftPath == "" && !draftNumPredictSet {
diff --git a/server/routes_options_test.go b/server/routes_options_test.go
index 49e2a3d11..39ca56381 100644
--- a/server/routes_options_test.go
+++ b/server/routes_options_test.go
@@ -191,10 +191,11 @@ func TestModelOptionsEmbeddingNumBatchDefault(t *testing.T) {
expectedNumBatch: llm.DefaultEmbeddingNumBatch,
},
{
- name: "embedding default is capped by context",
- defaultNumCtx: 1024,
+ name: "embedding default is capped at launch, not by num_ctx",
+ defaultNumCtx: 40960,
capabilities: []string{string(model.CapabilityEmbedding)},
- expectedNumBatch: 1024,
+ requestOpts: map[string]any{"num_ctx": float64(30)},
+ expectedNumBatch: llm.DefaultEmbeddingNumBatch,
},
{
name: "model num_batch overrides embedding default",