-
Notifications
You must be signed in to change notification settings - Fork 5
Mirror https://github.com/ggml-org/llama.cpp/pull/22121 #103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
74fbcb2
72d9180
b6387d2
492a14f
3828da4
af7af8a
6b190ab
0e9b56d
36fe0b0
2b00549
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -319,7 +319,9 @@ actor LlamaContext { | |
| result.deallocate() | ||
| } | ||
| let nTokens = llama_token_to_piece(vocab, token, result, 8, 0, false) | ||
|
|
||
| if nTokens == Int32.min { | ||
| return [] | ||
| } | ||
|
Comment on lines
+322
to
+324
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don’t collapse
🤖 Prompt for AI Agents |
||
| if nTokens < 0 { | ||
| let newResult = UnsafeMutablePointer<Int8>.allocate(capacity: Int(-nTokens)) | ||
| newResult.initialize(repeating: Int8(0), count: Int(-nTokens)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1130,11 +1130,14 @@ extern "C" { | |
| bool add_special, | ||
| bool parse_special); | ||
|
|
||
| // Token Id -> Piece. | ||
| // Uses the vocabulary in the provided context. | ||
| // Does not write null terminator to the buffer. | ||
| // User can skip up to 'lstrip' leading spaces before copying (useful when encoding/decoding multiple tokens with 'add_space_prefix') | ||
| // @param special If true, special tokens are rendered in the output. | ||
| /// Token Id -> Piece. | ||
| /// Uses the vocabulary in the provided context. | ||
| /// Does not write null terminator to the buffer. | ||
| /// @return Returns the number of chars/bytes on success, no more than length. | ||
| /// @return Returns a negative number on failure - the number of chars/bytes that would have been returned. | ||
| /// @return Returns INT32_MIN if the token is not in the vocabulary. | ||
| /// @param lstrip User can skip up to 'lstrip' leading spaces before copying (useful when encoding/decoding multiple tokens with 'add_space_prefix') | ||
| /// @param special If true, special tokens are rendered in the output. | ||
|
Comment on lines
+1133
to
+1140
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clarify that These return-value bullets still read like “any negative value means required size”, so callers using the usual 🤖 Prompt for AI Agents |
||
| LLAMA_API int32_t llama_token_to_piece( | ||
| const struct llama_vocab * vocab, | ||
| llama_token token, | ||
|
|
@@ -1147,6 +1150,7 @@ extern "C" { | |
| /// @param text The char pointer must be large enough to hold the resulting text. | ||
| /// @return Returns the number of chars/bytes on success, no more than text_len_max. | ||
| /// @return Returns a negative number on failure - the number of chars/bytes that would have been returned. | ||
| /// @return Returns INT32_MIN if any of the tokens is not in the vocabulary. | ||
| /// @param remove_special Allow to remove BOS and EOS tokens if model is configured to do so. | ||
| /// @param unparse_special If true, special tokens are rendered in the output. | ||
| LLAMA_API int32_t llama_detokenize( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clear the pending UTF-8 buffer on the invalid-token path.
This early return preserves
buffer. If the stream was holding the first bytes of a multi-byte scalar, the next valid piece gets decoded against stale bytes and the printed output becomes corrupted.🩹 Proposed fix
if nTokens == Int32.min { + buffer.removeAll(keepingCapacity: true) return nil }📝 Committable suggestion
🤖 Prompt for AI Agents