Created
April 18, 2024 16:51
-
-
Save bigsnarfdude/59b18273a61b22f009e946e0d07b4c1f to your computer and use it in GitHub Desktop.
8b llama instruct https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import transformers | |
import torch | |
model_id = "meta-llama/Meta-Llama-3-8B-Instruct" | |
pipeline = transformers.pipeline( | |
"text-generation", | |
model=model_id, | |
model_kwargs={"torch_dtype": torch.bfloat16}, | |
device="cuda", | |
) | |
messages = [ | |
{"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"}, | |
{"role": "user", "content": "Who are you?"}, | |
] | |
prompt = pipeline.tokenizer.apply_chat_template( | |
messages, | |
tokenize=False, | |
add_generation_prompt=True | |
) | |
terminators = [ | |
tokenizer.eos_token_id, | |
tokenizer.convert_tokens_to_ids("<|eot_id|>") | |
] | |
outputs = pipeline( | |
prompt, | |
max_new_tokens=256, | |
eos_token_id=terminators, | |
do_sample=True, | |
temperature=0.6, | |
top_p=0.9, | |
) | |
print(outputs[0]["generated_text"][len(prompt):]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment