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

Add example script for rendering jinja2 templates #7246

Open
wants to merge 30 commits into
base: master
Choose a base branch
from

Conversation

teleprint-me
Copy link
Contributor

@teleprint-me teleprint-me commented May 13, 2024

Sometimes I need to inspect the models chat templates and I created a script awhile back to do this. This is a updated and modified version of the same script.

It's useful for debugging and comprehending how the model creator might have intended the chat template to be rendered. I like being able to visualize these things and this script helps me do that.

Example usage:

$ python gguf-py/scripts/gguf-template.py -r /mnt/valerie/models/mistralai/Mistral-7B-Instruct-v0.2/ggml-model-f16.gguf
<s>[INST] Hello! [/INST]Hello! How may I assist you today?</s>[INST] Can you tell me what pickled mayonnaise is? [/INST]Certainly! What would you like to know about it?</s>

This isn't a high priority, I just thought it might be useful.

@mofosyne mofosyne added Review Complexity : Low Trivial changes to code that most beginner devs (or those who want a break) can tackle. e.g. UI fix python python script changes labels May 13, 2024
gguf-py/scripts/gguf-template.py Outdated Show resolved Hide resolved
gguf-py/scripts/gguf-template.py Outdated Show resolved Hide resolved
gguf-py/scripts/gguf-template.py Outdated Show resolved Hide resolved
gguf-py/scripts/gguf-template.py Outdated Show resolved Hide resolved
gguf-py/scripts/gguf-template.py Outdated Show resolved Hide resolved
gguf-py/scripts/gguf-template.py Outdated Show resolved Hide resolved
gguf-py/scripts/gguf-template.py Outdated Show resolved Hide resolved
@CISC
Copy link
Contributor

CISC commented May 17, 2024

I'm thinking it would be better to just extract bos/eos from metadata instead of allowing user to set them from command line. I've been working on some improvements to GGUFReader which would make it a lot easier to do things like that, and also enable the reduction of a lot of code duplication across the bundled scripts due to missing basic functionality.

If it's OK by you I'll wait until this is merged and then submit a PR with those improvements and remove --bos and --eos parameters at the same time.

@teleprint-me
Copy link
Contributor Author

@CISC No need to ask me for permission. If you think it's good, try it out. Would love to know about the results.

@CISC
Copy link
Contributor

CISC commented May 19, 2024

Just checking, in case you had a particular use for swapping out BOS/EOS. A --no-bos could be useful I guess.

This script can be really useful for generating prompts for main as well (esp. if --user and --assistant options were added to create a conversation instead of using dummy data) - giving me ideas - I like it! :)

@teleprint-me teleprint-me deleted the gguf-model-template branch May 20, 2024 18:53
@teleprint-me teleprint-me restored the gguf-model-template branch May 20, 2024 18:53
@teleprint-me teleprint-me reopened this May 20, 2024
@teleprint-me
Copy link
Contributor Author

teleprint-me commented May 20, 2024

This is ready for a review/merge.

Copy link
Collaborator

@compilade compilade left a comment

Choose a reason for hiding this comment

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

Seems useful, and it mostly looks good to me.

gguf-py/scripts/gguf_template.py Show resolved Hide resolved
gguf-py/scripts/gguf_template.py Show resolved Hide resolved
Comment on lines +842 to +844
{file = "sentencepiece-0.2.0-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:188779e1298a1c8b8253c7d3ad729cb0a9891e5cef5e5d07ce4592c54869e227"},
{file = "sentencepiece-0.2.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:bed9cf85b296fa2b76fc2547b9cbb691a523864cebaee86304c43a7b4cb1b452"},
{file = "sentencepiece-0.2.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:d7b67e724bead13f18db6e1d10b6bbdc454af574d70efbb36f27d90387be1ca3"},
Copy link
Collaborator

Choose a reason for hiding this comment

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

Note: I haven't verified the hashes; in my workflow I'm ignoring poetry's lock file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Remove poetry.lock and add a ignore rule to .gitignore?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove poetry.lock and add a ignore rule to .gitignore?

I don't have to. What I'm saying is that pypi/poetry are a good place for a supply chain attack because it's infeasible to review these diffs without respective automation. This doesn't concern me personally, because I'm only relying on the toml file, not on the lock file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see. That's always been the case with packaging.
I ran the following:

poetry remove sentencepiece
poetry add 'sentencepiece@^0.2.0'

I personally prefer requirements.txt, but poetry does make distribution less painful.

Regardless, seems outside scope. Still good to be aware of.

Choose a reason for hiding this comment

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

I see. That's always been the case with packaging. I ran the following:

poetry remove sentencepiece
poetry add 'sentencepiece@^0.2.0'

I personally prefer requirements.txt, but poetry does make distribution less painful.

Regardless, seems outside scope. Still good to be aware of.

Forgive me if this is a stupid question, but why not conda (mamba)? Works great for me

Copy link
Collaborator

Choose a reason for hiding this comment

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

Conda is orthogonal to this. Pyproject is the format consumed by the majority of python-related tools including and beyond pip (e.g. Nixpkgs' buildPythonPackage). The lock file is just there because of the pyproject back-end/build-system we'd (arbitrarily) chosen.

Copy link
Collaborator

@SomeoneSerge SomeoneSerge left a comment

Choose a reason for hiding this comment

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

(I reviewed the pyproject part)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python python script changes Review Complexity : Low Trivial changes to code that most beginner devs (or those who want a break) can tackle. e.g. UI fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants