Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
|
3 |
+
|
4 |
+
pipe = pipeline('text-generation', model=model, tokenizer=tokenizer, device='cuda:0')
|
5 |
+
|
6 |
+
INSTRUCTION_KEY = "### Instruction:"
|
7 |
+
RESPONSE_KEY = "### Response:"
|
8 |
+
INTRO_BLURB = "Below is an instruction that describes a task. Write a response that appropriately completes the request."
|
9 |
+
PROMPT_FOR_GENERATION_FORMAT = """{intro}
|
10 |
+
{instruction_key}
|
11 |
+
{instruction}
|
12 |
+
{response_key}
|
13 |
+
""".format(
|
14 |
+
intro=INTRO_BLURB,
|
15 |
+
instruction_key=INSTRUCTION_KEY,
|
16 |
+
instruction="{instruction}",
|
17 |
+
response_key=RESPONSE_KEY,
|
18 |
+
)
|
19 |
+
|
20 |
+
example = "James decides to run 3 sprints 3 times a week. He runs 60 meters each sprint. How many total meters does he run a week? Explain before answering."
|
21 |
+
fmt_ex = PROMPT_FOR_GENERATION_FORMAT.format(instruction=example)
|
22 |
+
|
23 |
+
|
24 |
+
|
25 |
+
with torch.autocast('cuda', dtype=torch.bfloat16):
|
26 |
+
print(
|
27 |
+
pipe('Here is a recipe for vegan banana bread:\n',
|
28 |
+
max_new_tokens=100,
|
29 |
+
do_sample=True,
|
30 |
+
use_cache=True))
|
31 |
+
|
32 |
+
|
33 |
+
|