Created
July 24, 2023 19:32
-
-
Save simonw/b46c24c3c9c0604f4030caf5891728ac to your computer and use it in GitHub Desktop.
Interactive Llama 2
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
from transformers import AutoTokenizer | |
import transformers | |
import torch | |
model = "meta-llama/Llama-2-7b-chat-hf" | |
print("AutoTokenizer.from_pretrained(model)") | |
tokenizer = AutoTokenizer.from_pretrained(model) | |
print("pipeline = transformers.pipeline(...") | |
pipeline = transformers.pipeline( | |
"text-generation", | |
model=model, | |
torch_dtype=torch.float16, | |
device_map="auto", | |
) | |
print("sequences = pipeline(...") | |
print("Entering interactive mode...") | |
while True: | |
sequences = pipeline( | |
input("prompt: ") + "\n", | |
do_sample=True, | |
top_k=10, | |
num_return_sequences=1, | |
eos_token_id=tokenizer.eos_token_id, | |
# max_length=200, | |
) | |
for seq in sequences: | |
print(seq['generated_text']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment