preallocate a buffer of fitting size for tokenization (utils.cpp)
This commit is contained in:
parent
d5850c53ca
commit
7b1b575fe8
1 changed files with 3 additions and 1 deletions
|
@ -146,8 +146,10 @@ std::string gpt_random_prompt(std::mt19937 & rng) {
|
||||||
|
|
||||||
// TODO: not great allocating this every time
|
// 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> 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);
|
int n = llama_tokenize(ctx, text.c_str(), res.data(), res.size(), add_bos);
|
||||||
|
assert(n >= 0);
|
||||||
res.resize(n);
|
res.resize(n);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue