Views
No views yet
meta-llama/Meta-Llama-3.1-8B fine-tuned for chat completions.Built with Llama.1from transformers import (
2 AutoModelForCausalLM,
3 AutoTokenizer,
4)
5
6
7model = AutoModelForCausalLM.from_pretrained("mathewhe/Llama-3.1-8B-Chat")
8tokenizer = AutoTokenizer.from_pretrained("mathewhe/Llama-3.1-8B-Chat")
9
10messages = [
11 {"role": "user", "content": "What is an LLM?"},
12]
13
14inputs = tokenizer.apply_chat_template(messages)
15
16print(tokenizer.decode(model.generate(**inputs)[0]))chat_class.py module into your local
directory and just import the Chat class:1from chat_class import Chat
2chat = Chat(
3 "mathewhe/Llama-3.1-8B-Chat",
4 device="cuda",
5)
6
7# for one-off instructions
8instruction = "Write an ingredient list for banana pudding."
9print(chat.instruct(instruction))
10
11# for multi-turn chat
12response1 = chat.message("Hi, please explain what DNA is.")
13response2 = chat.message("Tell me more about how its discovery affected society.")
14
15# to reset the chat
16chat.reset()| Model | AlpacaEval | AlpacaEval-LC |
|---|---|---|
| meta-llama/Meta-Llama-3.1-8B-Instruct | 21.84 | 20.85 |
| mathewhe/Llama-3.1-8B-Chat | 12.16 | 20.53 |
<|begin_of_text|>[INST]<user-message>[/INST][ASST]<llm-response>[/ASST]<|end_of_text|>apply_chat_template() method on a list of
messages.
Each message should be a dict with two keys:1from transformers import AutoTokenizer
2
3tokenizer = AutoTokenizer.from_pretrained("mathewhe/Llama-3.1-8B-Chat")
4
5messages = [
6 {"role": "user", "content": "Solve for x: 3x=4"},
7 {"role": "assistant", "content": "3x=4\n(3x)/3=(4)/3\nx=4/3"},
8 {"role": "user", "content": "Please explain your work."},
9]
10print(tokenizer.apply_chat_template(messages, tokenize=False)<|begin_of_text|>[INST]Solve for x: 3x=4[/INST][ASST]3x=4
(3x)/3=(4)/3
x=4/3[/ASST]<|end_of_text|><|begin_of_text|>[INST]Please explain your work[/INST]chat_class.py module for more details.