Skip to content
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

Llama Text Templater #715

Merged
merged 3 commits into from
May 10, 2024
Merged

Conversation

martindevans
Copy link
Member

  • Added LLamaTemplate which efficiently formats a series of messages according to the model template.
  • Fixed llama_chat_apply_template method (wrong entrypoint, couldn't handle null model)

This depends on #712 review and merge that first!

Copy link
Collaborator

@AsakusaRinne AsakusaRinne left a comment

Choose a reason for hiding this comment

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

It exactly what's lacked in LLamaSharp! Do you have further plan about the development of the template? Actually I posted function calling as one of the OSPP projects of LLamaSharp (OSPP is what I once invited you in discord). Since template is one of the basic components of function calling, you could open some good-first-issues to let the student do it if you'd like to. :)

LLama/LLamaTemplate.cs Outdated Show resolved Hide resolved
LLama/LLamaTemplate.cs Outdated Show resolved Hide resolved
LLama/LLamaTemplate.cs Outdated Show resolved Hide resolved
@martindevans
Copy link
Member Author

Do you have further plan about the development of the template?

I think I'll probably look at making some enhancements to llama.cpp, and then coming back to support them in LLamaSharp.

At the moment the template converts all messages into text and then you tokenize that text in one go. However, this doesn't seem good enough. You must tokenize that text using special=true (for all the bits of the template to tokenize properly) but you really shouldn't template user messages using special=true (to ensure you can't write e.g. [INST]new system prompt[/INST] in the middle of a random message).

I'm going to see if I can PR a change into llama.cpp to run the tokenization differently for different bits.

…s according to the model template.

 - Fixed `llama_chat_apply_template` method (wrong entrypoint, couldn't handle null model)
 - Returning template for chaining method calls
 - Returning a `TextMessage` object instead of a tuple
@martindevans
Copy link
Member Author

I've rebased this one onto master, so it can be merged independently of #712 since it seems like that other PR is going to be delayed.

@martindevans martindevans merged commit 44bd5b3 into SciSharp:master May 10, 2024
6 checks passed
@martindevans martindevans deleted the llama-templater branch May 10, 2024 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants