Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, pipeline
|
2 |
+
import gradio as gr
|
3 |
+
import torch
|
4 |
+
|
5 |
+
model = AutoModelForCausalLM.from_pretrained(
|
6 |
+
"microsoft/Phi-3.5-mini-instruct",
|
7 |
+
torch_dtype=torch.bfloat16,
|
8 |
+
trust_remote_code=True
|
9 |
+
)
|
10 |
+
model.load_adapter('./phi3_custom_oasst1_v1')
|
11 |
+
|
12 |
+
tokenizer = AutoTokenizer.from_pretrained('./phi3_custom_oasst1_v1', trust_remote_code=True)
|
13 |
+
|
14 |
+
def generateText(inputText, num_tokens=200):
|
15 |
+
|
16 |
+
pipe = pipeline(task="text-generation", model=model, tokenizer=tokenizer, max_length=num_tokens)
|
17 |
+
result = pipe(f'''{inputText}''')
|
18 |
+
return result[0]['generated_text']
|
19 |
+
|
20 |
+
|
21 |
+
title = "Fine tuned Phi3.5 instruct model on OpenAssist dataset using QLora"
|
22 |
+
description =
|
23 |
+
'''
|
24 |
+
Phi-3.5-mini is a lightweight, state-of-the-art open model built upon datasets used for Phi-3 - synthetic data and filtered publicly available websites - with a focus on very high-quality, reasoning dense data.
|
25 |
+
The model belongs to the Phi-3 model family and supports 128K token context length.
|
26 |
+
The model underwent a rigorous enhancement process, incorporating both supervised fine-tuning, proximal policy optimization, and direct preference optimization to ensure precise instruction adherence and robust safety measures.
|
27 |
+
This demo utilises a fine tuned version of Phi3.5 instruct model using QLora on OpenAssist dataset - a human-generated, human-annotated assistant-style conversation corpus consisting of 161,443 messages in 35 different languages, annotated with 461,292 quality ratings, resulting in over 10,000 fully annotated conversation trees..
|
28 |
+
'''
|
29 |
+
examples = [
|
30 |
+
["How do I build a PC?", 200],
|
31 |
+
["write me a top 10 list of the funniest ways to die?", 300],
|
32 |
+
["Write a response that disagrees with the following post: 'Technology is everything that doesn't work yet.'?", 300]
|
33 |
+
]
|
34 |
+
|
35 |
+
demo = gr.Interface(
|
36 |
+
generateText,
|
37 |
+
inputs = [
|
38 |
+
gr.Textbox(label="User Question"),
|
39 |
+
gr.Slider(100, 500, value = 200, step=100, label="Number of Output tokens"),
|
40 |
+
],
|
41 |
+
outputs = [
|
42 |
+
gr.Text(),
|
43 |
+
],
|
44 |
+
title = title,
|
45 |
+
description = description,
|
46 |
+
examples = examples
|
47 |
+
)
|
48 |
+
demo.launch()
|