diff options
author | Erik Scholz <Green-Sky@users.noreply.github.com> | 2023-03-22 17:09:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-22 18:09:38 +0200 |
commit | 56e659a0b271436e24813a801640d015e7b05328 (patch) | |
tree | 599b4c53f4f81b5de59f477d331b28bd260fc78d /utils.cpp | |
parent | 40ea807a972ec7b5a426f034ebfa593b5e7a06ed (diff) |
fix perplexity after c-api refactor (#390)
* preallocate a buffer of fitting size for tokenization (utils.cpp)
* don't create a new std::string (especially here, where it's usually large)
Diffstat (limited to 'utils.cpp')
-rw-r--r-- | utils.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
@@ -146,8 +146,10 @@ std::string gpt_random_prompt(std::mt19937 & rng) { // TODO: not great allocating this every time std::vector<llama_token> llama_tokenize(struct llama_context * ctx, const std::string & text, bool add_bos) { - std::vector<llama_token> res(8096); + // initialize to prompt numer of chars, since n_tokens <= n_prompt_chars + std::vector<llama_token> res(text.size() + (int)add_bos); int n = llama_tokenize(ctx, text.c_str(), res.data(), res.size(), add_bos); + assert(n >= 0); res.resize(n); return res; |