Spaces:
Sleeping
Sleeping
add
Browse files- .gitignore +2 -0
- .vscode/settings.json +5 -0
- app.py +34 -2
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
__pycache__/
|
2 |
+
flagged/
|
.vscode/settings.json
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"[python]": {
|
3 |
+
"editor.defaultFormatter": "ms-python.autopep8"
|
4 |
+
}
|
5 |
+
}
|
app.py
CHANGED
@@ -1,7 +1,39 @@
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
def greet(name):
|
4 |
return "Hello " + name + "!!"
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#%%
|
2 |
+
import numpy as np
|
3 |
import gradio as gr
|
4 |
|
5 |
def greet(name):
|
6 |
return "Hello " + name + "!!"
|
7 |
|
8 |
+
def calc_extra_token_length(old_seq_len: int = 4096, old_base: int = 10000, new_base: int = 1000000, dim: int = 128):
|
9 |
+
"""
|
10 |
+
from arXiv:2310.05209v1 [cs.CL] 8 Oct 2023
|
11 |
+
"""
|
12 |
+
b = int(dim/2 * np.log(old_seq_len / 2 / np.pi) /
|
13 |
+
np.log(old_base)) * 2 / dim
|
14 |
+
extra = 2 * np.pi * new_base ** b
|
15 |
+
return extra / 1024
|
16 |
+
|
17 |
+
#%%
|
18 |
+
with gr.Blocks() as demo:
|
19 |
+
gr.Markdown("# some tools")
|
20 |
+
|
21 |
+
with gr.Tab("greet"):
|
22 |
+
inputs = gr.Text(label="input text")
|
23 |
+
btn = gr.Button()
|
24 |
+
outputs = gr.Text(label="output text")
|
25 |
+
btn.click(fn=greet, inputs=inputs, outputs=outputs)
|
26 |
+
|
27 |
+
with gr.Tab("calc_extra_token_length"):
|
28 |
+
with gr.Row():
|
29 |
+
with gr.Column():
|
30 |
+
inputs = [gr.Number(4096), gr.Number(
|
31 |
+
10000), gr.Number(1000000), gr.Number(128)]
|
32 |
+
btn = gr.Button("calc")
|
33 |
+
outputs = gr.Textbox(value=0, label="extra max token (k)")
|
34 |
+
btn.click(fn=calc_extra_token_length, inputs=inputs, outputs=outputs)
|
35 |
+
|
36 |
+
demo.launch()
|
37 |
+
|
38 |
+
|
39 |
+
# %%
|