tcftrees commited on
Commit
996d8f7
β€’
1 Parent(s): 76c896a

Add application file

Browse files
Files changed (1) hide show
  1. app.py +21 -16
app.py CHANGED
@@ -11,28 +11,33 @@ import gradio as gr
11
  from utils import approach1_isoflops, approach2_derivative, approach3_isoloss
12
 
13
 
14
- def compute_optimal_vocab(Nnv: float,
15
- flops: float,
16
- ):
17
-
18
- if flops is None:
 
 
 
 
 
 
 
 
19
  Vopt_app1 = approach1_isoflops(Nnv)
20
  Vopt_app2 = approach2_derivative(Nnv)
21
- Vopt_app3 = approach3_isoloss(Nnv)
22
  else:
23
- Vopt_app1, Vopt_app2 = None, None
24
- Vopt_app3 = approach3_isoloss(Nnv, flops)
25
- # Vopt_app1, Vopt_app2, Vopt_app3=1.,2.,3.
26
-
27
- results = 'test'
28
- # results = f"The optimal vocabulary size is:\nApproach 1: {Vopt_app1}\nApproach 2: {Vopt_app2}\nApproach 3: {Vopt_app3}"
29
- return results
30
 
 
 
31
 
32
  with gr.Blocks() as demo:
33
  with gr.Column():
34
  gr.Markdown(
35
- """<img src="https://github.com/sail-sg/scaling-with-vocab/blob/main/figures/figure_1_left_scaling_v5.png" style="float: left;" width="250" height="250"><h1>The Optimal Vocabulary Size Predictor</h1>
36
  This tool is used to predict the optimal vocabulary size given the non-vocabulary parameters.
37
  We provide 3 ways for prediction:
38
 
@@ -47,8 +52,8 @@ with gr.Blocks() as demo:
47
  """)
48
 
49
  with gr.Row():
50
- Nnv = gr.Textbox(label="Non-vocabulary Parameters", value=7*10**9)
51
- flops = gr.Textbox(label="FLOPs", placeholder="Optional (e.g. 7.05*10**21)")
52
  output_text = gr.Textbox(label="Prediction")
53
  with gr.Row():
54
  btn = gr.Button("Compute the optimal vocabulary size")
 
11
  from utils import approach1_isoflops, approach2_derivative, approach3_isoloss
12
 
13
 
14
+ def compute_optimal_vocab(Nnv, flops):
15
+ try:
16
+ Nnv = float(Nnv)
17
+ except ValueError:
18
+ return "Invalid input for Non-vocabulary Parameters."
19
+
20
+ if flops:
21
+ try:
22
+ flops = float(flops)
23
+ except ValueError:
24
+ return "Invalid input for FLOPs."
25
+
26
+ if flops is None or flops == "":
27
  Vopt_app1 = approach1_isoflops(Nnv)
28
  Vopt_app2 = approach2_derivative(Nnv)
29
+ Vopt_app3 = approach3_isoloss(Nnv)
30
  else:
31
+ Vopt_app1, Vopt_app2 = None, None
32
+ Vopt_app3 = approach3_isoloss(Nnv, flops)
 
 
 
 
 
33
 
34
+ results = f"The optimal vocabulary size is:\nApproach 1: {Vopt_app1}\nApproach 2: {Vopt_app2}\nApproach 3: {Vopt_app3}"
35
+ return results
36
 
37
  with gr.Blocks() as demo:
38
  with gr.Column():
39
  gr.Markdown(
40
+ """<h1>The Optimal Vocabulary Size Predictor</h1>
41
  This tool is used to predict the optimal vocabulary size given the non-vocabulary parameters.
42
  We provide 3 ways for prediction:
43
 
 
52
  """)
53
 
54
  with gr.Row():
55
+ Nnv = gr.Textbox(label="Non-vocabulary Parameters", value=str(7*10**9))
56
+ flops = gr.Textbox(label="FLOPs", placeholder="Optional (e.g. 7.05e21)")
57
  output_text = gr.Textbox(label="Prediction")
58
  with gr.Row():
59
  btn = gr.Button("Compute the optimal vocabulary size")