Get up and running with Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models.
prompt: Use a single token when estimating mllama context size
Jesse Gross34a75102f7b1
diff --git a/server/prompt.go b/server/prompt.goindex f91b94d84..a64019833 100644--- a/server/prompt.go+++ b/server/prompt.go@@ -27,6 +27,16 @@ func chatPrompt(ctx context.Context, m *Model, tokenize tokenizeFunc, opts *api.isMllama := checkMllamaModelFamily(m)+ var imageNumTokens int+ // TODO: Ideally we would compute this from the projector metadata but some pieces are implementation dependent+ if isMllama {+ // Our mllama implementation packs all of the embeddings into a single token+ imageNumTokens = 1+ } else {+ // Clip images are represented as 768 tokens, each an embedding+ imageNumTokens = 768+ }+n := len(msgs) - 1// in reverse, find all messages that fit into context windowfor i := n; i >= 0; i-- {@@ -59,9 +69,7 @@ func chatPrompt(ctx context.Context, m *Model, tokenize tokenizeFunc, opts *api.ctxLen := len(s)if m.ProjectorPaths != nil {for _, m := range msgs[i:] {- // images are represented as 768 sized embeddings- // TODO: get embedding length from project metadata- ctxLen += 768 * len(m.Images)+ ctxLen += imageNumTokens * len(m.Images)}}