Spaces:
Paused
Paused
modified code
Browse files
app.py
CHANGED
@@ -1,42 +1,52 @@
|
|
1 |
-
import torch
|
2 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline, logging
|
3 |
import gradio as gr
|
|
|
|
|
|
|
|
|
4 |
|
5 |
model_name = "microsoft/phi-2"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
model = AutoModelForCausalLM.from_pretrained(
|
7 |
model_name,
|
|
|
|
|
8 |
trust_remote_code=True
|
9 |
)
|
10 |
model.config.use_cache = False
|
|
|
11 |
|
12 |
-
|
13 |
-
model.load_adapter(adapter_path)
|
14 |
-
|
15 |
-
tokenizer = AutoTokenizer.from_pretrained("checkpoint-500", trust_remote_code=True)
|
16 |
tokenizer.pad_token = tokenizer.eos_token
|
17 |
|
18 |
-
def
|
19 |
-
|
20 |
-
|
21 |
-
result = pipe(
|
22 |
-
|
23 |
-
|
24 |
-
return text[len(sentence):]
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
|
32 |
demo = gr.Interface(
|
33 |
-
|
34 |
-
inputs=[
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
examples=examples
|
40 |
)
|
41 |
-
|
42 |
-
demo.launch(debug=True)
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline,BitsAndBytesConfig
|
4 |
+
|
5 |
+
#model = AutoModelForCausalLM.from_pretrained("checkpoint_500",trust_remote_code=True)
|
6 |
|
7 |
model_name = "microsoft/phi-2"
|
8 |
+
|
9 |
+
import os
|
10 |
+
token = os.environ.get("HUGGING_FACE_TOKEN")
|
11 |
+
|
12 |
+
|
13 |
+
#bnb_config = BitsAndBytesConfig(
|
14 |
+
# load_in_4bit=True,
|
15 |
+
# bnb_4bit_quant_type="nf4",
|
16 |
+
# bnb_4bit_compute_dtype=torch.float16,
|
17 |
+
#)
|
18 |
+
|
19 |
model = AutoModelForCausalLM.from_pretrained(
|
20 |
model_name,
|
21 |
+
#quantization_config=bnb_config,
|
22 |
+
use_auth_token=token,
|
23 |
trust_remote_code=True
|
24 |
)
|
25 |
model.config.use_cache = False
|
26 |
+
model.load_adapter("checkpoint_500")
|
27 |
|
28 |
+
tokenizer = AutoTokenizer.from_pretrained("checkpoint_500", trust_remote_code=True)
|
|
|
|
|
|
|
29 |
tokenizer.pad_token = tokenizer.eos_token
|
30 |
|
31 |
+
def inference(prompt, count):
|
32 |
+
count = int(count)
|
33 |
+
pipe = pipeline(task="text-generation", model=model, tokenizer=tokenizer)
|
34 |
+
result = pipe(f"{prompt}",max_new_tokens=count)
|
35 |
+
out_text = result[0]['generated_text']
|
36 |
+
return out_text
|
|
|
37 |
|
38 |
+
title = "TSAI S21 Assignment: Adaptive QLoRA training on open assist oasst1 dataset, using microsoft/phi2 model"
|
39 |
+
description = "A simple Gradio interface that accepts a context and generates GPT like text "
|
40 |
+
examples = [["What is a large language model?","50"]
|
41 |
+
]
|
42 |
+
|
43 |
|
44 |
demo = gr.Interface(
|
45 |
+
inference,
|
46 |
+
inputs = [gr.Textbox(placeholder="Enter a prompt"), gr.Textbox(placeholder="Enter number of characters you want to generate")],
|
47 |
+
outputs = [gr.Textbox(label="Chat GPT like text")],
|
48 |
+
title = title,
|
49 |
+
description = description,
|
50 |
+
examples = examples
|
|
|
51 |
)
|
52 |
+
demo.launch()
|
|