-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript1.js
288 lines (263 loc) · 13.5 KB
/
script1.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
precision = 5;
function toggleCustomModel() {
var modelDropdown = document.getElementById("model-dropdown");
var modelInput = document.getElementById("model-input");
console.log(modelDropdown.value);
//if the model dropdown is set to custom, change the html to show the input box
if (modelDropdown.value === "custom") {
document.getElementById("params-custom").disabled = false;
document.getElementById("custom-model-row-params").style.display = "";
document.getElementById("params-tokens").disabled = false;
document.getElementById("custom-model-row-tokens").style.display = "";
// change the placeholder text
document.getElementById("params-custom").placeholder = "Enter custom parameters";
} else {
document.getElementById("params-custom").disabled = true;
document.getElementById("custom-model-row-params").style.display = "none";
document.getElementById("params-tokens").disabled = true;
document.getElementById("custom-model-row-tokens").style.display = "none";
}
// run checkvars
checkVars();
}
function toggleCustomCompute(){
var computeDropdown = document.getElementById("compute-dropdown");
var computeInput = document.getElementById("compute-input");
//if the compute dropdown is set to custom, change the html to show the input box
if (computeDropdown.value === "custom") {
document.getElementById("compute-custom-input").disabled = false;
document.getElementById("custom-compute-row").style.display = "";
} else {
document.getElementById("compute-custom-input").disabled = true;
document.getElementById("custom-compute-row").style.display = "none";
}
checkVars();
}
var toUpdate = "";
var shouldUpdateNewField = true;
function checkVars(){
var compute_params;
var compute_tokens;
var compute_flops;
var compute_chips;
var compute_utilization;
var compute_time;
console.log("checkVars ran");
if (document.getElementById("model-dropdown").value != "custom") {
if (document.getElementById("model-dropdown").value == "gpt-3") {
compute_params = 175000000000;
compute_tokens = 500000000000;
} else if (document.getElementById("model-dropdown").value == "PaLM") {
compute_params = 540000000000;
compute_tokens = 780000000000;
} else if (document.getElementById("model-dropdown").value == "gpt-2") {
compute_params = 1500000000;
compute_tokens = 400000000000;
}
} else {
compute_params = (document.getElementById("params-custom").value == "") ? null : document.getElementById("params-custom").value;
compute_tokens = (document.getElementById("params-tokens").value == "") ? null : document.getElementById("params-tokens").value;
}
if (document.getElementById("compute-dropdown").value != "custom") {
if (document.getElementById("compute-dropdown").value == "a100") {
compute_flops = 3.12e14;
} else if (document.getElementById("compute-dropdown").value == "v100") {
compute_flops = 1.3e14;
} else if (document.getElementById("compute-dropdown").value == "rtx-3090") {
compute_flops = .7e14;
}
} else {
compute_flops = (document.getElementById("compute-custom-input").value == "") ? null : document.getElementById("compute-custom-input").value;
}
compute_chips = (document.getElementById("compute-chips").value == "") ? null : document.getElementById("compute-chips").value;
compute_utilization = (document.getElementById("compute-utilization").value == "") ? 30 : document.getElementById("compute-utilization").value;
compute_time = (document.getElementById("compute-time").value == "") ? null : document.getElementById("compute-time").value;
// create array of the vars that are null
var nullVars = [];
if (compute_params == null) {
nullVars.push("compute_params");
}
if (compute_tokens == null) {
nullVars.push("compute_tokens");
}
if (compute_flops == null) {
nullVars.push("compute_flops");
}
if (compute_chips == null) {
nullVars.push("compute_chips");
}
if (compute_utilization == null) {
nullVars.push("compute_utilization");
}
if (compute_time == null) {
nullVars.push("compute_time");
}
// check if the length of the array is 1
if (nullVars.length == 1 && shouldUpdateNewField) {
// if it is, then we can calculate the missing variable
if (compute_time==null) {
if (shouldUpdateNewField) {
shouldUpdateNewField = false;
toUpdate = "time";
}
compute_time = 600*compute_params*compute_tokens / (compute_chips * compute_flops *compute_utilization);
var timeWithUnit = get_time_unit(compute_time);
time = timeWithUnit[0];
unit = timeWithUnit[1];
document.getElementById("compute-time").value = round_to_n_sig_figs(time,precision);
document.getElementById("time-unit").innerHTML = unit;
document.getElementById("compute-time").readOnly = true;
updatePowerAndCost(get_power(compute_time,compute_chips),get_cost(compute_time,compute_chips))
}
if (compute_flops==null) {
if (shouldUpdateNewField) {
shouldUpdateNewField = false;
toUpdate = "flops";
}
compute_flops = 600*compute_params*compute_tokens / (compute_time * compute_chips * compute_utilization);
document.getElementById("compute-custom-input").value = round_to_n_sig_figs(compute_flops,precision);
document.getElementById("compute-custom-input").readOnly = true;
updatePowerAndCost(get_power(compute_time,compute_chips),get_cost(compute_time,compute_chips))
}
if (compute_chips==null) {
if (shouldUpdateNewField) {
shouldUpdateNewField = false;
toUpdate = "chips";
}
compute_chips = 600*compute_params*compute_tokens / (compute_time * compute_flops * compute_utilization);
document.getElementById("compute-chips").value = round_to_n_sig_figs(compute_chips,precision);
document.getElementById("compute-chips").readOnly = true;
updatePowerAndCost(get_power(compute_time,compute_chips),get_cost(compute_time,compute_chips))
}
if (compute_utilization==null) {
if (shouldUpdateNewField) {
toUpdate = "utilization";
shouldUpdateNewField = false;
}
compute_utilization = 600*compute_params*compute_tokens / (compute_time * compute_flops * compute_chips);
document.getElementById("compute-utilization").value = round_to_n_sig_figs(compute_utilization,precision);
document.getElementById("compute-utilization").readOnly = true;
updatePowerAndCost(get_power(compute_time,compute_chips),get_cost(compute_time,compute_chips))
}
if (compute_params==null) {
if (shouldUpdateNewField) {
toUpdate = "params";
shouldUpdateNewField = false
}
compute_params = compute_tokens*compute_chips*compute_utilization*compute_time / (600*compute_tokens);
document.getElementById("params-custom").value = round_to_n_sig_figs(compute_params,precision);
document.getElementById("params-custom").readOnly = true;
updatePowerAndCost(get_power(compute_time,compute_chips),get_cost(compute_time,compute_chips))
}
if (compute_tokens==null) {
if (shouldUpdateNewField) {
toUpdate = "tokens";
shouldUpdateNewField = false
}
compute_tokens = compute_params*compute_chips*compute_utilization*compute_time / (600*compute_params);
document.getElementById("params-tokens").value = round_to_n_sig_figs(compute_tokens,precision);
document.getElementById("params-tokens").readOnly = true;
updatePowerAndCost(get_power(compute_time,compute_chips),get_cost(compute_time,compute_chips))
}
}
if (nullVars.length == 0) {
if (toUpdate == "time") {
compute_time = 600*compute_params*compute_tokens / (compute_chips * compute_flops *compute_utilization);
// pass time into the function to convert it and unpack
var timeWithUnit = get_time_unit(compute_time);
time = timeWithUnit[0];
unit = timeWithUnit[1];
console.log(time);
console.log(unit);
document.getElementById("compute-time").value = round_to_n_sig_figs(time,precision);
document.getElementById("time-unit").innerHTML = unit;
updatePowerAndCost(get_power(compute_time,compute_chips),get_cost(compute_time,compute_chips))
}
if (toUpdate == "flops") {
compute_flops = 600*compute_params*compute_tokens / (compute_time * compute_chips * compute_utilization);
document.getElementById("compute-custom-input").value = round_to_n_sig_figs(compute_flops,precision);
updatePowerAndCost(get_power(compute_time,compute_chips),get_cost(compute_time,compute_chips))
}
if (toUpdate == "chips") {
compute_chips = 600*compute_params*compute_tokens / (compute_time * compute_flops * compute_utilization);
document.getElementById("compute-chips").value = round_to_n_sig_figs(compute_chips,precision);
updatePowerAndCost(get_power(compute_time,compute_chips),get_cost(compute_time,compute_chips))
}
if (toUpdate == "utilization") {
compute_utilization = 600*compute_params*compute_tokens / (compute_time * compute_flops * compute_chips);
document.getElementById("compute-utilization").value = round_to_n_sig_figs(compute_utilization,precision);
updatePowerAndCost(get_power(compute_time,compute_chips),get_cost(compute_time,compute_chips))
}
if (toUpdate == "params") {
compute_params = compute_tokens*compute_chips*compute_utilization*compute_time / (600*compute_tokens);
document.getElementById("params-custom").value = round_to_n_sig_figs(compute_params,precision);
updatePowerAndCost(get_power(compute_time,compute_chips),get_cost(compute_time,compute_chips))
}
if (toUpdate == "tokens") {
compute_tokens = compute_params*compute_chips*compute_utilization*compute_time / (600*compute_params);
document.getElementById("params-tokens").value = round_to_n_sig_figs(compute_tokens,precision);
updatePowerAndCost(get_power(compute_time,compute_chips),get_cost(compute_time,compute_chips))
}
}
}
//function to round to n sig figs with no scientific notation (always write out number)
function round_to_n_sig_figs(x,n) {
val = Number.parseFloat(x).toPrecision(n);
// return val without scientific notation
return Number(val);
}
//function that takes a number of seconds and returns a new quantity and unit that is appropriate for the number of seconds
function get_time_unit(seconds) {
if (seconds < 60) {
return [seconds, "seconds"];
}
else if (seconds < 3600) {
return [seconds/60, "minutes"];
}
else if (seconds < 86400) {
return [seconds/3600, "hours"];
}
else if (seconds < 604800) {
return [seconds/86400, "days"];
} else if (seconds < 2628000) {
return [seconds/604800, "weeks"];
} else if (seconds < 31536000) {
return [seconds/2628000, "months"];
} else if (seconds < 315360000) {
return [seconds/31536000, "years"];
} else if (seconds < 3153600000) {
return [seconds/315360000, "decades"];
} else if (seconds < 31536000000) {
return [seconds/3153600000, "centuries"];
} else {
return [seconds/31536000000, "millenia"];
}
}
// Calculate power consumed based on time spent training and number of chips
function get_power(time, chips) {
// Replace this rate with actual power consumption details
const power_rate = 0.3; // Power consumed in kW per chip per hour
const power_consumed = compute_time * compute_chips * power_rate;
return power_consumed;
}
function get_cost(time, chips) {
// Replace this rate with actual cost details
const cost_rate = 2; // Cost in dollars per chip per hour
const total_cost = compute_time * compute_chips * cost_rate / 100;
return total_cost;
}
//
function updatePowerAndCost(power, cost) {
document.getElementById('power-value').innerText = power;
document.getElementById('cost-value').innerText = cost;
document.getElementById('power-consumed').style.display = 'block';
document.getElementById('estimated-cost').style.display = 'block';
}
document.getElementById("screenshotBtn").addEventListener("click", function() {
html2canvas(document.getElementById("table")).then(function(canvas) {
var link = document.createElement('a');
link.download = 'nice.png';
link.href = canvas.toDataURL();
link.click();
});
});