Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: multimodal - fix misreported prompt and num prompt tokens #392

Merged
merged 1 commit into from
May 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions llama.cpp/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,7 @@ struct llama_server_context
bool ingest_images(llama_client_slot &slot, int n_batch)
{
int image_idx = 0;
std::string prompt = "";

while (image_idx < (int) slot.images.size())
{
Expand Down Expand Up @@ -1432,6 +1433,11 @@ struct llama_server_context
slot.params.input_suffix : // no more images, then process suffix prompt
(json)(slot.images[image_idx].prefix_prompt);

// rebuild the prompt since it was cleared earlier
prompt += img.prefix_prompt;
prompt += "[img-" + std::to_string(img.id) + "]";
prompt += json_prompt;

std::vector<llama_token> append_tokens = tokenize(json_prompt, false); // has next image
for (int i = 0; i < (int) append_tokens.size(); ++i)
{
Expand All @@ -1440,6 +1446,13 @@ struct llama_server_context
}
}

// There is no prompt caching in multimodal currently
slot.num_prompt_tokens = slot.n_past;
slot.num_prompt_tokens_processed = slot.n_past;

// prompt for multimodal is set to empty to avoid processing those tokens here
slot.prompt = prompt;

return true;
}

Expand Down