MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / tokenize_prompt

Function tokenize_prompt

smallthinker/tools/run/run.cpp:940–953  ·  view source on GitHub ↗

Function to tokenize the prompt

Source from the content-addressed store, hash-verified

938
939// Function to tokenize the prompt
940static int tokenize_prompt(const llama_vocab * vocab, const std::string & prompt,
941 std::vector<llama_token> & prompt_tokens, const LlamaData & llama_data) {
942 const bool is_first = llama_kv_self_seq_pos_max(llama_data.context.get(), 0) == 0;
943
944 const int n_prompt_tokens = -llama_tokenize(vocab, prompt.c_str(), prompt.size(), NULL, 0, is_first, true);
945 prompt_tokens.resize(n_prompt_tokens);
946 if (llama_tokenize(vocab, prompt.c_str(), prompt.size(), prompt_tokens.data(), prompt_tokens.size(), is_first,
947 true) < 0) {
948 printe("failed to tokenize the prompt\n");
949 return -1;
950 }
951
952 return n_prompt_tokens;
953}
954
955// Check if we have enough space in the context to evaluate this batch
956static int check_context_size(const llama_context_ptr & ctx, const llama_batch & batch) {

Callers 1

generateFunction · 0.85

Calls 8

printeFunction · 0.85
llama_tokenizeFunction · 0.50
getMethod · 0.45
c_strMethod · 0.45
sizeMethod · 0.45
resizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected