Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Replace Fastchat Chat Templates with HF apply_chat_template#1499

Merged
mgoin merged 14 commits into
mainfrom
replace-fastchat
Dec 27, 2023
Merged

Replace Fastchat Chat Templates with HF apply_chat_template#1499
mgoin merged 14 commits into
mainfrom
replace-fastchat

Conversation

@mgoin
Copy link
Copy Markdown
Member

@mgoin mgoin commented Dec 21, 2023

Inspired by vllm-project/vllm#1365 and instigated by prefill benchmarking, using the HF Chat Templates hidden within the model's tokenizer seems to be a more elegant approach.

From a performance perspective, fastchat's default template adds over 400 tokens as a preamble to chat conversations, without actually using the right prompt format the model was trained on! Example below:

### Human: Got any creative ideas for a 10 year old’s birthday?
### Assistant: Of course! Here are some creative ideas for a 10-year-old's birthday party:
1. Treasure Hunt: Organize a treasure hunt in your backyard or nearby park. Create clues and riddles for the kids to solve, leading them to hidden treasures and surprises.
2. Science Party: Plan a science-themed party where kids can engage in fun and interactive experiments. You can set up different stations with activities like making slime, erupting volcanoes, or creating simple chemical reactions.
3. Outdoor Movie Night: Set up a backyard movie night with a projector and a large screen or white sheet. Create a cozy seating area with blankets and pillows, and serve popcorn and snacks while the kids enjoy a favorite movie under the stars.
4. DIY Crafts Party: Arrange a craft party where kids can unleash their creativity. Provide a variety of craft supplies like beads, paints, and fabrics, and let them create their own unique masterpieces to take home as party favors.
5. Sports Olympics: Host a mini Olympics event with various sports and games. Set up different stations for activities like sack races, relay races, basketball shooting, and obstacle courses. Give out medals or certificates to the participants.
6. Cooking Party: Have a cooking-themed party where the kids can prepare their own mini pizzas, cupcakes, or cookies. Provide toppings, frosting, and decorating supplies, and let them get hands-on in the kitchen.
7. Superhero Training Camp: Create a superhero-themed party where the kids can engage in fun training activities. Set up an obstacle course, have them design their own superhero capes or masks, and organize superhero-themed games and challenges.
8. Outdoor Adventure: Plan an outdoor adventure party at a local park or nature reserve. Arrange activities like hiking, nature scavenger hunts, or a picnic with games. Encourage exploration and appreciation for the outdoors.
Remember to tailor the activities to the birthday child's interests and preferences. Have a great celebration!
### Human:

All of the above is just a default preamble, and then it proceeds to contain it within a ### Human: ... ### Assistant: format is not correct for our tested hf:neuralmagic/TinyLlama-1.1B-Chat-v0.4-pruned50-quant-ds, which prefers <s>[INST] ... <<SYS>> ... <</SYS>> ... [/INST]. HF tokenizer.apply_chat_template has no problem generating that right format and integrating the roles properly in the same list of dictionaries format.

@mgoin mgoin changed the base branch from main to fix-chat-protocol December 21, 2023 19:10
@mgoin mgoin requested review from Satrat, bfineran and dsikka December 21, 2023 19:14
@mgoin mgoin changed the title Replace Fastchat Chat Templates with HF Replace Fastchat Chat Templates with HF apply_chat_template Dec 21, 2023
rahul-tuli
rahul-tuli previously approved these changes Dec 21, 2023
Comment thread src/deepsparse/server/openai_server.py Outdated
Comment thread src/deepsparse/server/openai_server.py Outdated
Base automatically changed from fix-chat-protocol to main December 21, 2023 19:35
@dsikka dsikka dismissed rahul-tuli’s stale review December 21, 2023 19:35

The base branch was changed.

dsikka
dsikka previously approved these changes Dec 21, 2023
Copy link
Copy Markdown
Contributor

@dsikka dsikka left a comment

Choose a reason for hiding this comment

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

LGTM pending merge conflicts fixed

@mgoin mgoin merged commit 4b7645f into main Dec 27, 2023
@mgoin mgoin deleted the replace-fastchat branch December 27, 2023 20:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants