From 377be2f39d065c352ece61c59bad79943091efcb Mon Sep 17 00:00:00 2001 From: vvhg1 Date: Fri, 6 Oct 2023 20:34:04 +0200 Subject: [PATCH] removing any leading whitespace from infill suffix and removing leeading space token from suffix when params.escape --- examples/infill/infill.cpp | 5 +++++ examples/server/server.cpp | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/examples/infill/infill.cpp b/examples/infill/infill.cpp index 9542d7b6c..81e037265 100644 --- a/examples/infill/infill.cpp +++ b/examples/infill/infill.cpp @@ -235,7 +235,12 @@ int main(int argc, char ** argv) { std::vector embd_inp; std::vector inp_pfx = ::llama_tokenize(ctx, params.input_prefix, false); + params.input_suffix.erase(0, params.input_suffix.find_first_not_of(" ")); std::vector inp_sfx = ::llama_tokenize(ctx, params.input_suffix, false); + const int space_token = 29871; + if (params.escape && inp_sfx.size() > 1 && inp_sfx[0] == space_token) { + inp_sfx.erase(inp_sfx.begin()); + } inp_pfx.insert(inp_pfx.begin(), llama_token_prefix(ctx)); if (add_bos) { inp_pfx.insert(inp_pfx.begin(), llama_token_bos(ctx)); diff --git a/examples/server/server.cpp b/examples/server/server.cpp index fa5e52e82..53c0fb800 100644 --- a/examples/server/server.cpp +++ b/examples/server/server.cpp @@ -344,8 +344,13 @@ struct llama_server_context void loadInfill() { + params.input_suffix.erase(0, params.input_suffix.find_first_not_of(" ")); auto prefix_tokens = tokenize(params.input_prefix, false); auto suffix_tokens = tokenize(params.input_suffix, false); + const int space_token = 29871; + if (params.escape && suffix_tokens.size() > 1 && suffix_tokens[0] == space_token) { + suffix_tokens.erase(suffix_tokens.begin()); + } prefix_tokens.insert(prefix_tokens.begin(), llama_token_prefix(ctx)); prefix_tokens.insert(prefix_tokens.begin(), llama_token_bos(ctx)); // always add BOS prefix_tokens.insert(prefix_tokens.end(), llama_token_suffix(ctx));