|
import gradio as gr |
|
|
|
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline |
|
import torch |
|
from peft import LoraConfig, PeftModel |
|
|
|
base_model_name = "microsoft/phi-2" |
|
new_model = "./checkpoint_360" |
|
|
|
model = AutoModelForCausalLM.from_pretrained( "microsoft/phi-2", trust_remote_code=True) |
|
model.config.use_cache = False |
|
model.load_adapter(new_model) |
|
|
|
tokenizer = AutoTokenizer.from_pretrained(base_model_name, trust_remote_code=True) |
|
tokenizer.pad_token = tokenizer.eos_token |
|
tokenizer.padding_side = "right" |
|
|
|
def QLoRA_Chatgpt(prompt): |
|
print(prompt) |
|
pipe = pipeline(task="text-generation", model=model, tokenizer=tokenizer, max_length=200) |
|
result = pipe(f"<s>[INST] {prompt} [/INST]") |
|
return(result[0]['generated_text']) |
|
|
|
|
|
iface = gr.Interface(fn=QLoRA_Chatgpt, inputs=gr.Textbox("how can help you today", label='prompt'), outputs=gr.Textbox(label='Generated-output')) |
|
iface.launch(share=True) |