bevelapi / models /llama2.py
BeveledCube's picture
re added num_beams
5525b46
raw
history blame contribute delete
568 Bytes
from transformers import AutoTokenizer, AutoModelForCausalLM
model_name = "meta-llama/Llama-2-13b-chat-hf"
def load():
global model
global tokenizer
model = AutoModelForCausalLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
def generate(input_text):
input_ids = tokenizer.encode(input_text, return_tensors="pt")
output_ids = model.generate(input_ids, no_repeat_ngram_size=2, max_new_tokens=200, num_beams=2, eos_token_id=tokenizer.eos_token_id)
return tokenizer.decode(output_ids[0], skip_special_tokens=True)