tcftrees commited on
Commit
29734be
β€’
1 Parent(s): ff0c2b6

Add application file

Browse files
Files changed (1) hide show
  1. app.py +65 -51
app.py CHANGED
@@ -1,64 +1,78 @@
1
- # !usr/bin/env python
2
- # -*- coding:utf-8 -*-
3
 
4
- '''
5
- Description :
6
- Version : 1.0
7
- Author : Chaofan Tao
8
9
- Github : https://github.com/sail-sg/scaling-with-vocab
10
- Date : 2024-08-09 00:25
11
- Copyright (C) 2024 Chaofan Tao. All rights reserved.
12
- '''
13
- import gradio as gr
14
- from utils import approach1_isoflops, approach2_derivative, approach3_isoloss
15
 
16
 
17
- def compute_optimal_vocab(Nnv: float,
18
- flops: float,
19
- ):
20
 
21
- if flops is None:
22
- Vopt_app1 = approach1_isoflops(Nnv)
23
- Vopt_app2 = approach2_derivative(Nnv)
24
- Vopt_app3 = approach3_isoloss(Nnv)
25
- else:
26
- Vopt_app1, Vopt_app2 = None, None
27
- Vopt_app3 = approach3_isoloss(Nnv, flops)
28
 
29
- results = f"## The optimal vocabulary size for non-vocabulary parameters {Nnv:1e} is:\nApproach 1: {Vopt_app1}\nApproach 2: {Vopt_app2}Approach 3: {Vopt_app3}"
30
- return results
31
 
32
 
33
- with gr.Blocks() as demo:
34
- with gr.Column():
35
- gr.Markdown(
36
- """<img src="https://raw.githubusercontent.com/MrYxJ/calculate-flops.pytorch/main/screenshot/calflops_hf3.png?raw=true" style="float: left;" width="250" height="250"><h1> ⛽️Model(Transformers) FLOPs and Parameter Calculator</h1>
37
- This tool is used to predict the optimal vocabulary size <h1> given the non-vocabulary parameters $N_{nv}$</h1>.
38
- We provide 3 ways for prediction:
39
 
40
- - Approach 1: Build the relationship between studied attributes and FLOPs: Build the relationship between the optimal data points (the points that reach the lowest loss under the same FLOPs budget) and the FLOPs.
41
- - Approach 2: Derivative-Based Estimation: Fast calculation method using the derivative of FLOPs with respect to the vocabulary size.
42
- - Approach 3: Parametric Fit of Loss Formula: Design a loss formula that considers the effect of vocabulary size and utilizes the loss to make prediction.
43
 
44
- Approach 1 and 2 can only be used to compute the optimal vocabulary size when the compute is optimally allocated to non-vocabulary parameters, vocabulary parameters and data jointly.
45
- Approach 3 will not only consider the case above, but also consider the case when the amount of data does not satisfy the optimal compute allocation, and can calculate the optimal vocabulary size with specified $N_{nv}$ and FLOPs.
46
 
47
- Thanks for trying 🌟🌟🌟!
48
- """)
49
 
50
- with gr.Row():
51
- Nnv = gr.Textbox(label="Non-vocabulary Parameters", value=7*10**9)
52
- flops = gr.Textbox(label="FLOPs", placeholder="Optional (e.g. 7.05*10**21)")
53
- output_text = gr.Textbox(label='output')
54
- with gr.Row():
55
- btn = gr.Button("Compute the optimal vocabulary size")
56
 
57
 
58
- demo = gr.Interface(fn=compute_optimal_vocab, inputs=[Nnv, flops], outputs=output_text)
59
- btn.click(
60
- compute_optimal_vocab,
61
- inputs=[Nnv, flops],
62
- outputs=output_text
63
- )
64
- demo.launch(share=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # # !usr/bin/env python
2
+ # # -*- coding:utf-8 -*-
3
 
4
+ # '''
5
+ # Description :
6
+ # Version : 1.0
7
+ # Author : Chaofan Tao
8
+ # Mail : [email protected]
9
+ # Github : https://github.com/sail-sg/scaling-with-vocab
10
+ # Date : 2024-08-09 00:25
11
+ # Copyright (C) 2024 Chaofan Tao. All rights reserved.
12
+ # '''
13
+ # import gradio as gr
14
+ # from utils import approach1_isoflops, approach2_derivative, approach3_isoloss
15
 
16
 
17
+ # def compute_optimal_vocab(Nnv: float,
18
+ # flops: float,
19
+ # ):
20
 
21
+ # if flops is None:
22
+ # Vopt_app1 = approach1_isoflops(Nnv)
23
+ # Vopt_app2 = approach2_derivative(Nnv)
24
+ # Vopt_app3 = approach3_isoloss(Nnv)
25
+ # else:
26
+ # Vopt_app1, Vopt_app2 = None, None
27
+ # Vopt_app3 = approach3_isoloss(Nnv, flops)
28
 
29
+ # results = f"## The optimal vocabulary size for non-vocabulary parameters {Nnv:1e} is:\nApproach 1: {Vopt_app1}\nApproach 2: {Vopt_app2}Approach 3: {Vopt_app3}"
30
+ # return results
31
 
32
 
33
+ # with gr.Blocks() as demo:
34
+ # with gr.Column():
35
+ # gr.Markdown(
36
+ # """<img src="https://raw.githubusercontent.com/MrYxJ/calculate-flops.pytorch/main/screenshot/calflops_hf3.png?raw=true" style="float: left;" width="250" height="250"><h1> ⛽️Model(Transformers) FLOPs and Parameter Calculator</h1>
37
+ # This tool is used to predict the optimal vocabulary size <h1> given the non-vocabulary parameters $N_{nv}$</h1>.
38
+ # We provide 3 ways for prediction:
39
 
40
+ # - Approach 1: Build the relationship between studied attributes and FLOPs: Build the relationship between the optimal data points (the points that reach the lowest loss under the same FLOPs budget) and the FLOPs.
41
+ # - Approach 2: Derivative-Based Estimation: Fast calculation method using the derivative of FLOPs with respect to the vocabulary size.
42
+ # - Approach 3: Parametric Fit of Loss Formula: Design a loss formula that considers the effect of vocabulary size and utilizes the loss to make prediction.
43
 
44
+ # Approach 1 and 2 can only be used to compute the optimal vocabulary size when the compute is optimally allocated to non-vocabulary parameters, vocabulary parameters and data jointly.
45
+ # Approach 3 will not only consider the case above, but also consider the case when the amount of data does not satisfy the optimal compute allocation, and can calculate the optimal vocabulary size with specified $N_{nv}$ and FLOPs.
46
 
47
+ # Thanks for trying 🌟🌟🌟!
48
+ # """)
49
 
50
+ # with gr.Row():
51
+ # Nnv = gr.Textbox(label="Non-vocabulary Parameters", value=7*10**9)
52
+ # flops = gr.Textbox(label="FLOPs", placeholder="Optional (e.g. 7.05*10**21)")
53
+ # output_text = gr.Textbox(label='output')
54
+ # with gr.Row():
55
+ # btn = gr.Button("Compute the optimal vocabulary size")
56
 
57
 
58
+ # demo = gr.Interface(fn=compute_optimal_vocab, inputs=[Nnv, flops], outputs=output_text)
59
+ # btn.click(
60
+ # compute_optimal_vocab,
61
+ # inputs=[Nnv, flops],
62
+ # outputs=output_text
63
+ # )
64
+ # demo.launch(share=True)
65
+
66
+ import gradio as gr
67
+ def update(name):
68
+ return f"Welcome to Gradio, {name}!"
69
+
70
+ with gr.Blocks() as demo:
71
+ gr.Markdown("Start typing below and then click **Run** to see the output.")
72
+ with gr.Row():
73
+ inp = gr.Textbox(placeholder="What is your name?")
74
+ out = gr.Textbox()
75
+ btn = gr.Button("Run")
76
+ btn.click(fn=update, inputs=inp, outputs=out)
77
+
78
+ demo.launch()