Unverified Commit edcf780f authored by Casper's avatar Casper Committed by GitHub
Browse files

Update generate example to llama 3 (#448)

parent 0e52a5c2
...@@ -2,28 +2,36 @@ from awq import AutoAWQForCausalLM ...@@ -2,28 +2,36 @@ from awq import AutoAWQForCausalLM
from transformers import AutoTokenizer, TextStreamer from transformers import AutoTokenizer, TextStreamer
quant_path = "TheBloke/Mistral-7B-Instruct-v0.2-AWQ" quant_path = "casperhansen/llama-3-8b-instruct-awq"
# Load model # Load model
model = AutoAWQForCausalLM.from_quantized(quant_path, fuse_layers=True) model = AutoAWQForCausalLM.from_quantized(quant_path, fuse_layers=True)
tokenizer = AutoTokenizer.from_pretrained(quant_path, trust_remote_code=True) tokenizer = AutoTokenizer.from_pretrained(quant_path, trust_remote_code=True)
streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True) streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
# Convert prompt to tokens
prompt_template = "[INST] {prompt} [/INST]"
prompt = "You're standing on the surface of the Earth. "\ prompt = "You're standing on the surface of the Earth. "\
"You walk one mile south, one mile west and one mile north. "\ "You walk one mile south, one mile west and one mile north. "\
"You end up exactly where you started. Where are you?" "You end up exactly where you started. Where are you?"
tokens = tokenizer( chat = [
prompt_template.format(prompt=prompt), {"role": "system", "content": "You are a concise assistant that helps answer questions."},
return_tensors='pt' {"role": "user", "content": prompt},
).input_ids.cuda() ]
terminators = [
tokenizer.eos_token_id,
tokenizer.convert_tokens_to_ids("<|eot_id|>")
]
tokens = tokenizer.apply_chat_template(
chat,
return_tensors="pt"
).cuda()
# Generate output # Generate output
generation_output = model.generate( generation_output = model.generate(
tokens, tokens,
streamer=streamer, streamer=streamer,
max_new_tokens=512 max_new_tokens=64,
) eos_token_id=terminators
\ No newline at end of file )
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment