Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -44,19 +44,60 @@ def evaluate(
|
|
44 |
token_count=200,
|
45 |
temperature=1.0,
|
46 |
top_p=0.7,
|
47 |
-
|
|
|
48 |
):
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
g = gr.Interface(
|
53 |
fn=evaluate,
|
54 |
inputs=[
|
55 |
gr.components.Textbox(lines=2, label="Instruction", value="Tell me about alpacas."),
|
56 |
gr.components.Textbox(lines=2, label="Input", placeholder="none"),
|
57 |
-
gr.components.Slider(minimum=10, maximum=250, step=10, value=200),
|
58 |
-
gr.components.Slider(minimum=0.2, maximum=2.0, step=0.1, value=1.0),
|
59 |
-
gr.components.Slider(minimum=0, maximum=1, step=0.05, value=0.7),
|
|
|
|
|
60 |
],
|
61 |
outputs=[
|
62 |
gr.inputs.Textbox(
|
@@ -64,8 +105,8 @@ g = gr.Interface(
|
|
64 |
label="Output",
|
65 |
)
|
66 |
],
|
67 |
-
title="🐦Raven
|
68 |
-
description="Raven
|
69 |
)
|
70 |
g.queue(concurrency_count=1, max_size=10)
|
71 |
g.launch(share=False)
|
|
|
44 |
token_count=200,
|
45 |
temperature=1.0,
|
46 |
top_p=0.7,
|
47 |
+
presencePenalty = 0.1,
|
48 |
+
countPenalty = 0.1,
|
49 |
):
|
50 |
+
args = PIPELINE_ARGS(temperature = max(0.2, float(temperature)), top_p = float(top_p),
|
51 |
+
alpha_frequency = countPenalty,
|
52 |
+
alpha_presence = presencePenalty,
|
53 |
+
token_ban = [], # ban the generation of some tokens
|
54 |
+
token_stop = [0]) # stop generation whenever you see any token here
|
55 |
+
|
56 |
+
instruction = instruction.strip()
|
57 |
+
input = input.strip()
|
58 |
+
ctx = generate_prompt(instruction, input)
|
59 |
+
|
60 |
+
gpu_info = nvmlDeviceGetMemoryInfo(gpu_h)
|
61 |
+
print(f'vram {gpu_info.total} used {gpu_info.used} free {gpu_info.free}')
|
62 |
+
|
63 |
+
all_tokens = []
|
64 |
+
out_last = 0
|
65 |
+
out_str = ''
|
66 |
+
occurrence = {}
|
67 |
+
state = None
|
68 |
+
for i in range(int(token_count)):
|
69 |
+
out, state = model.forward(pipeline.encode(ctx)[-ctx_limit:] if i == 0 else [token], state)
|
70 |
+
for n in occurrence:
|
71 |
+
out[n] -= (args.alpha_presence + occurrence[n] * args.alpha_frequency)
|
72 |
+
|
73 |
+
token = pipeline.sample_logits(out, temperature=args.temperature, top_p=args.top_p)
|
74 |
+
if token in args.token_stop:
|
75 |
+
break
|
76 |
+
all_tokens += [token]
|
77 |
+
if token not in occurrence:
|
78 |
+
occurrence[token] = 1
|
79 |
+
else:
|
80 |
+
occurrence[token] += 1
|
81 |
+
|
82 |
+
tmp = pipeline.decode(all_tokens[out_last:])
|
83 |
+
if '\ufffd' not in tmp:
|
84 |
+
out_str += tmp
|
85 |
+
yield out_str.strip()
|
86 |
+
out_last = i + 1
|
87 |
+
gc.collect()
|
88 |
+
torch.cuda.empty_cache()
|
89 |
+
yield out_str.strip()
|
90 |
|
91 |
g = gr.Interface(
|
92 |
fn=evaluate,
|
93 |
inputs=[
|
94 |
gr.components.Textbox(lines=2, label="Instruction", value="Tell me about alpacas."),
|
95 |
gr.components.Textbox(lines=2, label="Input", placeholder="none"),
|
96 |
+
gr.components.Slider(minimum=10, maximum=250, step=10, value=200), # token_count
|
97 |
+
gr.components.Slider(minimum=0.2, maximum=2.0, step=0.1, value=1.0), # temperature
|
98 |
+
gr.components.Slider(minimum=0, maximum=1, step=0.05, value=0.7), # top_p
|
99 |
+
gr.components.Slider(0.0, 1.0, step=0.1, value=0.2), # presencePenalty
|
100 |
+
gr.components.Slider(0.0, 1.0, step=0.1, value=0.2), # countPenalty
|
101 |
],
|
102 |
outputs=[
|
103 |
gr.inputs.Textbox(
|
|
|
105 |
label="Output",
|
106 |
)
|
107 |
],
|
108 |
+
title=f"🐦Raven {title}",
|
109 |
+
description="Raven is [RWKV 7B](https://github.com/BlinkDL/ChatRWKV) finetuned to follow instructions. It is trained on the [Stanford Alpaca](https://github.com/tatsu-lab/stanford_alpaca) dataset and more.",
|
110 |
)
|
111 |
g.queue(concurrency_count=1, max_size=10)
|
112 |
g.launch(share=False)
|