-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Fix func call tokens for internlm2 #8506
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'm not sure these tokens should be marked as USER_DEFINED; this would mean they would always be specially pre-tokenized even if
parse_special
isfalse
, making it impossible to avoid injections from text containing these tokens when not desired. This is related to #8228.If this is simply a display issue, then it might be more appropriate to revisit whether to detokenize the control tokens output by the model.
These may be relevant:
llama.cpp/examples/main/main.cpp
Line 858 in 5e116e8
llama.cpp/examples/server/server.cpp
Line 1185 in 5e116e8
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.
@compilade hi, these special tokens are used to parse function content in the output string, meaning they should be pre-tokenized even if
parse_special
isfalse
. The following is an example. Nowllama-cli
works with--special
, butllama-server
does not work with--special
. Ideally, it's desired only to show these function-call related special tokens.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.
@RunningLeon Thanks for giving an example.
If I understand correctly, what you want is to get the function call tokens to render in the output, right? Pre-tokenization is about the input. If these tokens were pre-tokenized even when
parse_special
isfalse
, this means it would be impossible to include<|plugin|>
in some non-special text without the model seeing it as the<|plugin|>
token.For example:
If the problem is about the output of
llama-server
, this should be fixable by changing how it calls thellama_token_to_piece
function.If you want to hide control tokens, while still showing these ones, then... hmm. This seems complicated to do with the current token attributes (USER_DEFINED and CONTROL), given that USER_DEFINED is intended for always pre-tokenized tokens like the multi-space tokens in GPT-NeoX, while CONTROL is intended for tokens with special meaning, like
<|im_start|>
, and in my opinion the function call tokens fit the intention for CONTROL tokens.Why not show all special tokens, like
llama-cli --special
does?Would this work?
This is because
llama-cli
handles it here:llama.cpp/examples/main/main.cpp
Line 766 in 5e116e8
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.
@compilade thanks for your quick response. Yes, ideally, we want to hide control tokens and show function call related tokens. But since
<|plugin|>
can be input, there might be a problem. Sollama-server
with--special
works for me. @apresence, hi, what do you think of it as the real user?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.
Yes, I believe that works! I'm happy to test it once a fix is available.
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.
@compilade @ggerganov hi, guys. What's the good way to include special tokens as input when using
llama-cli
andllama-server
? I find something interesting.The
sys prompt
is'<|im_start|>system\nYou are InternLM2-Chat, a harmless AI assistant.<|im_end|>\n<|im_start|>system name=<|plugin|>[{"name": "get_current_weather", "parameters": {"required": ["location"], "type": "object", "properties": {"location": {"type": "string", "description": "The city and state, e.g. San Francisco, CA"}, "unit": {"type": "string"}}}, "description": "Get the current weather in a given location"}]<|im_end|>\n'
which has special tokens.
It does not work when using
--prompt
to pass the sys prompt while creating service usingllama-server
, but it works with--system-prompt-file
when putting them in a local file. Besides, it also does not work when you put special tokens inmessages
like this