Spaces:
Sleeping
Sleeping
File size: 665 Bytes
27145dd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
torch_dtype = torch.bfloat16
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
model_name = "bigscience/bloomz-1b7"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto", device_map="auto").to(device=device)
def run(text,**kargs):
inputs = tokenizer.encode(text=text, return_tensors="pt").to(device=device)
outputs = model.generate(inputs,**kargs)
return tokenizer.decode(outputs[0])
if __name__ == "__main__":
print("model test")
model("This is the input text.") |