-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
server : clean up built-in template detection #11026
server : clean up built-in template detection #11026
Conversation
common/common.cpp
Outdated
static const char * template_key = "tokenizer.chat_template"; | ||
// call with NULL buffer to get the total size of the string | ||
int32_t res = llama_model_meta_val_str(model, template_key, NULL, 0); | ||
if (res < 2) { |
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.
What's the reason for the 2
here? llama_model_meta_val_str
returns either -1 if the key is not found, or the length of the string.
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.
Hmm yeah someone added this in the PR to fix the null terminator. I suppose that it's to make sure model_template.size() - 1
stay positive.
In any case, we can change it to
if (res < 2) { | |
if (res < 0) { |
Then below:
return std::string(model_template.data(), res);
What do you think?
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.
model_template.size()
should always be at least 1, since the size is res + 1
. So I don't expect the -1 to cause issues, but that should also work.
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 ended up just flipping the condition to if (res > 0)
, it's more readable this way.
Ref: #10900 (comment)
Bug: when starting the server, templates longer than 2048 bytes is shown as "not supported" in the log output, while it's still being formatted correctly in
/v1/chat/completions