Skip to content

Commit 0ef46da

Browse files
authored
llava-cli : always tokenize special tokens (#5382)
* llava-cli: tokenize special tokens in prompt * llava-cli: use the escape CLI argument, remove incomplete separate escaping process
1 parent ee1628b commit 0ef46da

File tree

1 file changed

+1
-13
lines changed

1 file changed

+1
-13
lines changed

examples/llava/llava-cli.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static bool eval_id(struct llama_context * ctx_llama, int id, int * n_past) {
3434

3535
static bool eval_string(struct llama_context * ctx_llama, const char* str, int n_batch, int * n_past, bool add_bos){
3636
std::string str2 = str;
37-
std::vector<llama_token> embd_inp = ::llama_tokenize(ctx_llama, str2, add_bos);
37+
std::vector<llama_token> embd_inp = ::llama_tokenize(ctx_llama, str2, add_bos, true);
3838
eval_tokens(ctx_llama, embd_inp, n_batch, n_past);
3939
return true;
4040
}
@@ -152,20 +152,8 @@ static void process_prompt(struct llava_context * ctx_llava, struct llava_image_
152152
size_t image_pos = prompt.find("<image>");
153153
if (image_pos != std::string::npos) {
154154
// new templating mode: Provide the full prompt including system message and use <image> as a placeholder for the image
155-
156155
system_prompt = prompt.substr(0, image_pos);
157156
user_prompt = prompt.substr(image_pos + std::string("<image>").length());
158-
// We replace \n with actual newlines in user_prompt, just in case -e was not used in templating string
159-
size_t pos = 0;
160-
while ((pos = user_prompt.find("\\n", pos)) != std::string::npos) {
161-
user_prompt.replace(pos, 2, "\n");
162-
pos += 1; // Advance past the replaced newline
163-
}
164-
while ((pos = system_prompt.find("\\n", pos)) != std::string::npos) {
165-
system_prompt.replace(pos, 2, "\n");
166-
pos += 1; // Advance past the replaced newline
167-
}
168-
169157
printf("system_prompt: %s\n", system_prompt.c_str());
170158
printf("user_prompt: %s\n", user_prompt.c_str());
171159
} else {

0 commit comments

Comments
 (0)