hiaripc commited on
Commit
a447006
·
1 Parent(s): d5bbae7

Improvements

Browse files
Files changed (2) hide show
  1. app.js +186 -31
  2. index.html +1 -1
app.js CHANGED
@@ -10,30 +10,44 @@ const THETA3 = 5.550e-10;
10
  const THETA4 = 2.045e-7;
11
 
12
 
13
- function computeEnergy(d,L,nq,nkv,nin,nout)
14
  {
15
 
16
  const ratio = nkv/nq;
17
 
18
- let total=[];
 
 
 
 
19
 
20
- for (let n of nout)
 
21
  {
22
- let value =
23
- THETA0
24
- +
25
- d*L*(
26
- THETA1*d*(nin/n)
27
- +
28
- ratio*(THETA2*nin + THETA3*n)
29
- +
30
- THETA4
31
- );
32
-
33
- total.push(value);
 
 
 
 
 
 
34
  }
35
 
36
- return total;
 
 
 
37
  }
38
 
39
 
@@ -76,35 +90,175 @@ function draw()
76
 
77
 
78
  let nout =
79
- logspace2(1,4096,300);
80
 
81
 
82
- let energy =
83
- computeEnergy(
84
  d,L,nq,nkv,nin,nout
85
  );
86
 
87
 
88
- let trace = {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  x:nout,
90
- y:energy,
 
 
91
  mode:"lines",
92
- name:"Total E_tok"
93
- };
 
 
 
 
 
 
 
 
94
 
95
 
96
  let layout={
97
 
 
 
 
 
 
 
98
  title:
99
- `d=${d}, L=${L}, nq=${nq}, nkv=${nkv}, nin=${nin}`,
 
100
 
101
  xaxis:{
102
- title:"Output tokens",
103
- type:"log"
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  },
105
 
 
106
  yaxis:{
107
- title:"Energy per token (J)"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  }
109
 
110
  };
@@ -112,14 +266,15 @@ function draw()
112
 
113
  Plotly.newPlot(
114
  "plot",
115
- [trace],
116
- layout
 
 
 
117
  );
118
 
119
  }
120
 
121
-
122
-
123
  async function loadModel()
124
  {
125
 
 
10
  const THETA4 = 2.045e-7;
11
 
12
 
13
+ function computeComponents(d,L,nq,nkv,nin,nout)
14
  {
15
 
16
  const ratio = nkv/nq;
17
 
18
+ let c0=[];
19
+ let c1=[];
20
+ let c2=[];
21
+ let c3=[];
22
+ let c4=[];
23
 
24
+
25
+ for(let n of nout)
26
  {
27
+
28
+ c0.push(THETA0);
29
+
30
+ c1.push(
31
+ d*L*THETA1*d*(nin/n)
32
+ );
33
+
34
+ c2.push(
35
+ d*L*ratio*THETA2*nin
36
+ );
37
+
38
+ c3.push(
39
+ d*L*ratio*THETA3*n
40
+ );
41
+
42
+ c4.push(
43
+ d*L*THETA4
44
+ );
45
  }
46
 
47
+
48
+ return [
49
+ c0,c1,c2,c3,c4
50
+ ];
51
  }
52
 
53
 
 
90
 
91
 
92
  let nout =
93
+ logspace2(1,4096,400);
94
 
95
 
96
+ let components =
97
+ computeComponents(
98
  d,L,nq,nkv,nin,nout
99
  );
100
 
101
 
102
+ let total =
103
+ nout.map(
104
+ (_,i)=>
105
+ components.reduce(
106
+ (a,b)=>a+b[i],
107
+ 0
108
+ )
109
+ );
110
+
111
+
112
+ let names =
113
+ [
114
+ "θ₀",
115
+ "θ₁ d²L nin/nout",
116
+ "θ₂ dL(nkv/nq)nin",
117
+ "θ₃ dL(nkv/nq)nout",
118
+ "θ₄ dL"
119
+ ];
120
+
121
+
122
+ let colors =
123
+ [
124
+ "#8c8c8c",
125
+ "#55A868",
126
+ "#C44E52",
127
+ "#E2C044",
128
+ "#4C72B0"
129
+ ];
130
+
131
+
132
+ let traces=[];
133
+
134
+
135
+ for(let i=0;i<5;i++)
136
+ {
137
+
138
+ traces.push({
139
+
140
+ x:nout,
141
+
142
+ y:components[i],
143
+
144
+ mode:"lines",
145
+
146
+ name:names[i],
147
+
148
+ stackgroup:"one",
149
+
150
+ line:{
151
+ width:0
152
+ },
153
+
154
+ fillcolor:colors[i],
155
+
156
+ opacity:0.88
157
+
158
+ });
159
+
160
+ }
161
+
162
+
163
+ traces.push({
164
+
165
  x:nout,
166
+
167
+ y:total,
168
+
169
  mode:"lines",
170
+
171
+ name:"Total E_tok",
172
+
173
+ line:{
174
+ color:"black",
175
+ width:2
176
+ }
177
+
178
+ });
179
+
180
 
181
 
182
  let layout={
183
 
184
+
185
+ width:700,
186
+
187
+ height:450,
188
+
189
+
190
  title:
191
+ `Component breakdown (nᵢₙ=${nin})`,
192
+
193
 
194
  xaxis:{
195
+
196
+ title:
197
+ "Output tokens n_out (log₂)",
198
+
199
+ type:"log",
200
+
201
+ tickmode:"array",
202
+
203
+ tickvals:
204
+ [
205
+ 1,2,4,8,16,32,
206
+ 64,128,256,
207
+ 512,1024,2048,4096
208
+ ]
209
+
210
  },
211
 
212
+
213
  yaxis:{
214
+
215
+
216
+ title:
217
+ "Energy per token E_tok (J)",
218
+
219
+
220
+ type:"log",
221
+
222
+
223
+ tickmode:"array",
224
+
225
+ tickvals:
226
+ [
227
+ 0.0001,
228
+ 0.001,
229
+ 0.01,
230
+ 0.1,
231
+ 1
232
+ ],
233
+
234
+ ticktext:
235
+ [
236
+ "1e-4",
237
+ "1e-3",
238
+ "1e-2",
239
+ "1e-1",
240
+ "1"
241
+ ]
242
+
243
+ },
244
+
245
+
246
+ legend:{
247
+
248
+ x:1,
249
+
250
+ y:1,
251
+
252
+ bgcolor:"rgba(255,255,255,0)"
253
+
254
+ },
255
+
256
+
257
+ margin:{
258
+ l:70,
259
+ r:20,
260
+ t:50,
261
+ b:60
262
  }
263
 
264
  };
 
266
 
267
  Plotly.newPlot(
268
  "plot",
269
+ traces,
270
+ layout,
271
+ {
272
+ responsive:true
273
+ }
274
  );
275
 
276
  }
277
 
 
 
278
  async function loadModel()
279
  {
280
 
index.html CHANGED
@@ -2,7 +2,7 @@
2
  <html>
3
  <head>
4
  <meta charset="UTF-8">
5
- <title>SweetSpot v2 — energy-per-token demo</title>
6
 
7
  <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
8
 
 
2
  <html>
3
  <head>
4
  <meta charset="UTF-8">
5
+ <title>SweetSpot v2 — Energy-per-Token demo</title>
6
 
7
  <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
8