8000 Added --chat-template-file to llama-run by engelmi · Pull Request #11922 · ggml-org/llama.cpp · GitHub
[go: up one dir, main page]

Skip to content

Added --chat-template-file to llama-run #11922

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

Closed

Conversation

engelmi
Copy link
Contributor
@engelmi engelmi commented Feb 17, 2025

Relates to: #11178

Added --chat-template-file CLI option to llama-run. If specified, the file will be read and the content passed for overwriting the chat template of the model to common_chat_templates_from_model.

This also enables running the granite-code model from ollama:

# using a jinja chat template file 
# (when prefix, e.g. hf://, is not specified, llama-run pulls from ollama)
$ llama-run  --chat-template-file ./chat.tmpl granite-code
> write code

Here is a code snippet in Python:

"""
def f(x):
    return x**2
"""

# without a jinja chat template file
$ llama-run granite-code
> write code
failed to apply the chat template

Make sure to read the contributing guidelines before submitting a PR

@engelmi
Copy link
Contributor Author
engelmi commented Feb 17, 2025

@ericcurtin PTAL
(This change would allow ramalama to pass converted Go Templates to llama-run)

@engelmi engelmi force-pushed the added-chat-template-file-to-llama-run branch from 36a0c4f to 2ec2107 Compare February 19, 2025 14:29
@engelmi engelmi force-pushed the added-chat-template-file-to-llama-run branch from 2ec2107 to 6e50443 Compare February 19, 2025 14:35
@ericcurtin
Copy link
Collaborator

This code LGTM waiting on builds

@engelmi
Copy link
Contributor Author
engelmi commented Feb 19, 2025

This code LGTM waiting on builds

Should pass now. Didn't review the latest changes from master thoroughly.

Not sure why I get

    Merge is not an allowed merge method in this repository.
    This branch must not contain merge commits. 

return "";
}

FILE* file = ggml_fopen(chat_template_file.c_str(), "r");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be better if it used the File class from this code. It would automatically fclose the file when necessary. I would also change fopen -> ggml_fopen in that File class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file class from this code is behind the LLAMA_USE_CURL macro. So I'd need to move it since the --chat-template should also work without that macro. What do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'd move it out of the LLAMA_USE_CURL macro. It doesn't actually do any curl stuff.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. PTAL @ericcurtin

@engelmi engelmi force-pushed the added-chat-template-file-to-llama-run branch from 6e50443 to f01a139 Compare February 19, 2025 14:41
printe("Error reading chat template file '%s': %s", chat_template_file.c_str(), strerror(errno));
return "";
}
return std::string(data.begin(), data.end());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One could actually fread directly to a std::string and save a copy. It's a optimisation, a small one. A std::string is basically a vector of chars.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

@ericcurtin
Copy link
Collaborator

This code LGTM waiting on builds

Should pass now. Didn't review the latest changes from master thoroughly.

Not sure why I get

    Merge is not an allowed merge method in this repository.
    This branch must not contain merge commits. 

Never seen that before 🤷

Relates to: ggml-org#11178

Added --chat-template-file CLI option to llama-run. If specified, the file
will be read and the content passed for overwriting the chat template of
the model to common_chat_templates_from_model.

Signed-off-by: Michael Engel <mengel@redhat.com>
@engelmi engelmi force-pushed the added-chat-template-file-to-llama-run branch from f01a139 to 86f68a8 Compare February 19, 2025 15:13
@engelmi
Copy link
Contributor Author
engelmi commented Feb 19, 2025

This code LGTM waiting on builds

Should pass now. Didn't review the latest changes from master thoroughly.
Not sure why I get

    Merge is not an allowed merge method in this repository.
    This branch must not contain merge commits. 

Never seen that before 🤷

Hmm... closing and reopening it. Hopefully this fixes that error.

@engelmi engelmi closed this Feb 19, 2025
@engelmi
Copy link
Contributor Author
engelmi commented Feb 19, 2025

#11961

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0