Spaces:
Running
Running
jadehardouin
commited on
Commit
•
0680f69
1
Parent(s):
50f19fa
Update models.py
Browse files
models.py
CHANGED
@@ -36,11 +36,23 @@ class BaseTCOModel(ABC):
|
|
36 |
|
37 |
def set_name(self, name):
|
38 |
self.name = name
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
class OpenAIModel(BaseTCOModel):
|
41 |
|
42 |
def __init__(self):
|
43 |
self.set_name("(SaaS) OpenAI")
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
super().__init__()
|
45 |
|
46 |
def render(self):
|
@@ -54,11 +66,11 @@ class OpenAIModel(BaseTCOModel):
|
|
54 |
return gr.Dropdown.update(choices=["4K", "16K"])
|
55 |
|
56 |
self.model = gr.Dropdown(["GPT-4", "GPT-3.5 Turbo"], value="GPT-4",
|
57 |
-
label="OpenAI
|
58 |
interactive=True, visible=False)
|
59 |
self.context_length = gr.Dropdown(["8K", "32K"], value="8K", interactive=True,
|
60 |
label="Context size",
|
61 |
-
visible=False)
|
62 |
self.model.change(on_model_change, inputs=self.model, outputs=self.context_length)
|
63 |
self.input_length = gr.Number(350, label="Average number of input tokens",
|
64 |
interactive=True, visible=False)
|
@@ -77,13 +89,22 @@ class OpenAIModel(BaseTCOModel):
|
|
77 |
else:
|
78 |
cost_per_1k_input_tokens = 0.003
|
79 |
|
80 |
-
cost_per_output_token = cost_per_1k_input_tokens *
|
81 |
|
82 |
return cost_per_output_token
|
83 |
|
84 |
class OpenSourceLlama2Model(BaseTCOModel):
|
|
|
85 |
def __init__(self):
|
86 |
self.set_name("(Open source) Llama 2")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
super().__init__()
|
88 |
|
89 |
def render(self):
|
@@ -101,18 +122,20 @@ class OpenSourceLlama2Model(BaseTCOModel):
|
|
101 |
def on_vm_change(model, vm):
|
102 |
# TO DO: load info from CSV
|
103 |
if model == "Llama 2 7B" and vm == "1x Nvidia A100 (Azure NC24ads A100 v4)":
|
104 |
-
return gr.Number.update(value=
|
105 |
elif model == "Llama 2 7B" and vm == "2x Nvidia A100 (Azure NC48ads A100 v4)":
|
106 |
-
return gr.Number.update(value=
|
107 |
|
108 |
-
self.model = gr.Dropdown(["Llama 2 7B", "Llama 2 70B"], value="Llama 2 7B", visible=False)
|
109 |
-
self.vm = gr.Dropdown(vm_choices,
|
|
|
110 |
visible=False,
|
111 |
-
label="Instance of VM with GPU"
|
|
|
112 |
)
|
113 |
-
self.vm_cost_per_hour = gr.Number(3.
|
114 |
interactive=True, visible=False)
|
115 |
-
self.tokens_per_second = gr.Number(
|
116 |
label="Number of tokens per second for this specific model and VM instance",
|
117 |
interactive=False
|
118 |
)
|
@@ -120,17 +143,22 @@ class OpenSourceLlama2Model(BaseTCOModel):
|
|
120 |
interactive=True, visible=False)
|
121 |
|
122 |
self.model.change(on_model_change, inputs=self.model, outputs=self.vm)
|
123 |
-
self.vm.change(on_vm_change, inputs=[self.model, self.vm], outputs=self.tokens_per_second)
|
124 |
-
self.maxed_out = gr.Slider(minimum=0.01, value=
|
125 |
info="How much the GPU is fully used.",
|
126 |
interactive=True,
|
127 |
visible=False)
|
|
|
|
|
|
|
|
|
128 |
|
129 |
-
def compute_cost_per_token(self, vm_cost_per_hour, tokens_per_second, maxed_out):
|
130 |
-
cost_per_token = vm_cost_per_hour / (tokens_per_second * 3600 * maxed_out)
|
131 |
return cost_per_token
|
132 |
|
133 |
class ModelPage:
|
|
|
134 |
def __init__(self, Models: BaseTCOModel):
|
135 |
self.models: list[BaseTCOModel] = []
|
136 |
for Model in Models:
|
@@ -170,8 +198,10 @@ class ModelPage:
|
|
170 |
for model in self.models:
|
171 |
model_n_args = len(model.get_components_for_cost_computing())
|
172 |
if current_model == model.get_name():
|
|
|
173 |
model_args = args[begin:begin+model_n_args]
|
174 |
-
print("Model args: ",model_args)
|
175 |
model_tco = model.compute_cost_per_token(*model_args)
|
176 |
-
|
|
|
|
|
177 |
begin = begin+model_n_args
|
|
|
36 |
|
37 |
def set_name(self, name):
|
38 |
self.name = name
|
39 |
+
|
40 |
+
def set_formula(self, formula):
|
41 |
+
self.formula = formula
|
42 |
+
|
43 |
+
def get_formula(self):
|
44 |
+
return self.formula
|
45 |
|
46 |
class OpenAIModel(BaseTCOModel):
|
47 |
|
48 |
def __init__(self):
|
49 |
self.set_name("(SaaS) OpenAI")
|
50 |
+
self.set_formula(r"""$CT = \frac{CT\_1K \times 1000}{L}$ <br>
|
51 |
+
with: <br>
|
52 |
+
CT = Cost per output Token <br>
|
53 |
+
CT_1K = Cost per 1000 Tokens (from OpenAI's pricing web page) <br>
|
54 |
+
L = Input Length
|
55 |
+
""")
|
56 |
super().__init__()
|
57 |
|
58 |
def render(self):
|
|
|
66 |
return gr.Dropdown.update(choices=["4K", "16K"])
|
67 |
|
68 |
self.model = gr.Dropdown(["GPT-4", "GPT-3.5 Turbo"], value="GPT-4",
|
69 |
+
label="OpenAI models",
|
70 |
interactive=True, visible=False)
|
71 |
self.context_length = gr.Dropdown(["8K", "32K"], value="8K", interactive=True,
|
72 |
label="Context size",
|
73 |
+
visible=False, info="Number of tokens the model considers when processing text")
|
74 |
self.model.change(on_model_change, inputs=self.model, outputs=self.context_length)
|
75 |
self.input_length = gr.Number(350, label="Average number of input tokens",
|
76 |
interactive=True, visible=False)
|
|
|
89 |
else:
|
90 |
cost_per_1k_input_tokens = 0.003
|
91 |
|
92 |
+
cost_per_output_token = cost_per_1k_input_tokens * 1000 / input_length
|
93 |
|
94 |
return cost_per_output_token
|
95 |
|
96 |
class OpenSourceLlama2Model(BaseTCOModel):
|
97 |
+
|
98 |
def __init__(self):
|
99 |
self.set_name("(Open source) Llama 2")
|
100 |
+
self.set_formula(r"""$CT = \frac{VM\_CH}{TS \times 3600 \times MO \times U}$<br>
|
101 |
+
with: <br>
|
102 |
+
CT = Cost per Token <br>
|
103 |
+
VM_CH = VM Cost per Hour <br>
|
104 |
+
TS = Tokens per Second (for an input length of 233 tokens) <br>
|
105 |
+
MO = Maxed Out <br>
|
106 |
+
U = Used
|
107 |
+
""")
|
108 |
super().__init__()
|
109 |
|
110 |
def render(self):
|
|
|
122 |
def on_vm_change(model, vm):
|
123 |
# TO DO: load info from CSV
|
124 |
if model == "Llama 2 7B" and vm == "1x Nvidia A100 (Azure NC24ads A100 v4)":
|
125 |
+
return [gr.Number.update(value=3.6730), gr.Number.update(value=694.38)]
|
126 |
elif model == "Llama 2 7B" and vm == "2x Nvidia A100 (Azure NC48ads A100 v4)":
|
127 |
+
return [gr.Number.update(value=7.346), gr.Number.update(value=1388.76)]
|
128 |
|
129 |
+
self.model = gr.Dropdown(["Llama 2 7B", "Llama 2 70B"], value="Llama 2 7B", label="OpenSource models", visible=False)
|
130 |
+
self.vm = gr.Dropdown(vm_choices,
|
131 |
+
value="1x Nvidia A100 (Azure NC24ads A100 v4)",
|
132 |
visible=False,
|
133 |
+
label="Instance of VM with GPU",
|
134 |
+
info="Your options for this choice depend on the model you previously chose"
|
135 |
)
|
136 |
+
self.vm_cost_per_hour = gr.Number(3.6730, label="VM instance cost per hour",
|
137 |
interactive=True, visible=False)
|
138 |
+
self.tokens_per_second = gr.Number(694.38, visible=False,
|
139 |
label="Number of tokens per second for this specific model and VM instance",
|
140 |
interactive=False
|
141 |
)
|
|
|
143 |
interactive=True, visible=False)
|
144 |
|
145 |
self.model.change(on_model_change, inputs=self.model, outputs=self.vm)
|
146 |
+
self.vm.change(on_vm_change, inputs=[self.model, self.vm], outputs=[self.vm_cost_per_hour, self.tokens_per_second])
|
147 |
+
self.maxed_out = gr.Slider(minimum=0.01, value=50., step=0.01, label="% maxed out",
|
148 |
info="How much the GPU is fully used.",
|
149 |
interactive=True,
|
150 |
visible=False)
|
151 |
+
self.used = gr.Slider(minimum=0.01, value=50., step=0.01, label="% used",
|
152 |
+
info="Percentage of time the GPU is used.",
|
153 |
+
interactive=True,
|
154 |
+
visible=False)
|
155 |
|
156 |
+
def compute_cost_per_token(self, vm_cost_per_hour, tokens_per_second, maxed_out, used):
|
157 |
+
cost_per_token = vm_cost_per_hour / (tokens_per_second * 3600 * maxed_out * used)
|
158 |
return cost_per_token
|
159 |
|
160 |
class ModelPage:
|
161 |
+
|
162 |
def __init__(self, Models: BaseTCOModel):
|
163 |
self.models: list[BaseTCOModel] = []
|
164 |
for Model in Models:
|
|
|
198 |
for model in self.models:
|
199 |
model_n_args = len(model.get_components_for_cost_computing())
|
200 |
if current_model == model.get_name():
|
201 |
+
|
202 |
model_args = args[begin:begin+model_n_args]
|
|
|
203 |
model_tco = model.compute_cost_per_token(*model_args)
|
204 |
+
formula = model.get_formula()
|
205 |
+
return f"Model {current_model} has TCO {model_tco}", model_tco, formula
|
206 |
+
|
207 |
begin = begin+model_n_args
|