forked from nickaggarwal/Vicuna-7b-1.1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
34 lines (28 loc) · 1003 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import os
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline, logging
import torch
import argparse
from huggingface_hub import snapshot_download
model_name_or_path = "lmsys/vicuna-7b-v1.1"
class InferlessPythonModel:
def initialize(self):
self.tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
self.model = AutoModelForCausalLM.from_pretrained(model_name_or_path)
def infer(self, inputs):
prompt = inputs["prompt"]
prompt_template=f'''USER: {prompt}
ASSISTANT:'''
pipe = pipeline(
"text-generation",
model=self.model,
tokenizer=self.tokenizer,
max_new_tokens=512,
temperature=0.7,
top_p=0.95,
repetition_penalty=1.15
)
generated_text = pipe(prompt_template)[0]['generated_text']
return {"generated_text": generated_text}
def finalize(self):
self.tokenizer = None
self.model = None