Spaces:
Runtime error
Runtime error
mrfakename
commited on
Commit
•
449c0ae
1
Parent(s):
67987df
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from transformers import AutoTokenizer
|
3 |
+
from petals import AutoDistributedModelForCausalLM
|
4 |
+
|
5 |
+
model_name = "petals-team/StableBeluga2"
|
6 |
+
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=False, add_bos_token=False)
|
8 |
+
model = AutoDistributedModelForCausalLM.from_pretrained(model_name)
|
9 |
+
model = model.cuda()
|
10 |
+
def gen(text):
|
11 |
+
inputs = tokenizer('A cat in French is "', return_tensors="pt")["input_ids"].cuda()
|
12 |
+
outputs = model.generate(inputs, max_new_tokens=16)
|
13 |
+
return (tokenizer.decode(outputs[0]))
|
14 |
+
import gradio as gr
|
15 |
+
with gr.Blocks() as demo:
|
16 |
+
gr.Markdown("# Run 70B models on CPU *\n\n* (sort of)\n\nPlease do not expect privacy when using this tool as inputs and outputs may be exposed.")
|
17 |
+
t = gr.Textbox(label="INPUT")
|
18 |
+
b = gr.Button("GO")
|
19 |
+
o = gr.Markdown("Output...")
|
20 |
+
b.click(gen, inputs=t, outputs=o)
|
21 |
+
demo.queue().launch()
|