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

Function llama_detokenize_spm

common/common.cpp:1060–1078  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1058}
1059
1060std::string llama_detokenize_spm(llama_context * ctx, const std::vector<llama_token> & tokens) {
1061 const llama_token bos_id = llama_token_bos(llama_get_model(ctx));
1062
1063 std::string piece;
1064 std::string result;
1065
1066 for (size_t i = 0; i < tokens.size(); ++i) {
1067 piece = llama_token_to_piece(ctx, tokens[i]);
1068
1069 // remove the leading space of the first non-BOS token
1070 if (((tokens[0] == bos_id && i == 1) || (tokens[0] != bos_id && i == 0)) && piece[0] == ' ') {
1071 piece = piece.substr(1);
1072 }
1073
1074 result += piece;
1075 }
1076
1077 return result;
1078}
1079
1080std::string llama_detokenize_bpe(llama_context * ctx, const std::vector<llama_token> & tokens) {
1081 std::string piece;

Callers 2

mainFunction · 0.85
mainFunction · 0.85

Calls 5

substrMethod · 0.80
llama_token_to_pieceFunction · 0.70
llama_token_bosFunction · 0.50
llama_get_modelFunction · 0.50
sizeMethod · 0.45

Tested by 2

mainFunction · 0.68
mainFunction · 0.68