File size: 1,213 Bytes
eaa8416
 
 
 
 
 
 
d8ff530
eaa8416
 
 
 
 
 
 
 
 
d0e6c3b
 
 
 
eaa8416
 
 
b9d49cf
2ac2871
eaa8416
5e2e076
d8ff530
5e2e076
d497b84
5e2e076
d497b84
d8ff530
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 torch
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline, logging
import gradio as gr


model_name = "microsoft/phi-2"
model = AutoModelForCausalLM.from_pretrained(
    model_name,
    trust_remote_code=True
)
model.config.use_cache = False


tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
tokenizer.pad_token = tokenizer.eos_token

# Loading adapter (trained LORA weights)
# ckpt = '/content/drive/MyDrive/S27/results/checkpoint-500'
# model.load_adapter(ckpt)
adapter_path = 'checkpoint-500'
model.load_adapter(adapter_path)

def inference(prompt):

  pipe = pipeline(task="text-generation",model=model,tokenizer=tokenizer,max_length = 100)
  result = pipe(f"<s>[INST] {prompt} [/INST]")
  return result[0]['generated_text']

INTERFACE = gr.Interface(fn=inference, inputs=[gr.Textbox(label= "Prompt", value= 'what should we do to save time')],
                    
                    outputs=gr.Text(label= "Generated Text"), title="Language Model Phi-2 fine-tuned with OpenAssistant/oasst-1 dataset using QLoRA strategy",
                 
                 examples = [['explain transpiration in plants'],]
                        ).launch(debug=True)