w601sxs commited on
Commit
00b053d
·
1 Parent(s): d477067

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -1
app.py CHANGED
@@ -1,3 +1,32 @@
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
- gr.Interface.load("models/w601sxs/pythia-70m-instruct-orca-chkpt-64000").launch()
 
1
  import gradio as gr
2
+ import torch
3
+ from peft import PeftModel, PeftConfig
4
+ from transformers import AutoTokenizer
5
+
6
+ ref_model = AutoModelForCausalLM.from_pretrained("EleutherAI/pythia-70m-deduped-v0", torch_dtype=torch.bfloat16)
7
+ peft_model_id = "w601sxs/pythia-70m-instruct-orca-chkpt-64000"
8
+
9
+ config = PeftConfig.from_pretrained(peft_model_id)
10
+ model = PeftModel.from_pretrained(ref_model, peft_model_id)
11
+ tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
12
+
13
+ model.eval()
14
+
15
+ def predict(text):
16
+ inputs = tokenizer(prompt, return_tensors="pt")
17
+ with torch.no_grad():
18
+ outputs = model.generate(input_ids=inputs["input_ids"], max_new_tokens=10)
19
+ out_text = tokenizer.batch_decode(outputs.detach().cpu().numpy(), skip_special_tokens=True)[0])
20
+
21
+ return out_text
22
+
23
+
24
+ demo = gr.Interface(
25
+ fn=predict,
26
+ inputs='text',
27
+ outputs='text',
28
+ )
29
+
30
+ demo.launch()
31
+
32