codelion commited on
Commit
d64ca39
·
verified ·
1 Parent(s): 231175a

KV-cache single-graph model (prefill once + k=2 decode internally)

Browse files
Files changed (2) hide show
  1. dit_fp16.onnx → genframe_fp16.onnx +2 -2
  2. index.html +13 -18
dit_fp16.onnx → genframe_fp16.onnx RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:e993ef405d2dee38f3e4538fef8f32dc3183d36adc7260ba7574632afeb7c95a
3
- size 261701703
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3fbbf2313f60065aaa83253bf91e8cd0b003903199326f2faa416b1488cacfef
3
+ size 261743145
index.html CHANGED
@@ -194,7 +194,7 @@ async function boot_(){
194
 
195
  setBar(.05);
196
  setStatus("downloading dynamics model…");
197
- const ditBuf=await fetchProgress("dit_fp16.onnx","dynamics"); setBar(.7);
198
  setStatus("compiling dynamics on "+DEV+"…");
199
  dit=await ort.InferenceSession.create(ditBuf,{executionProviders:eps, graphOptimizationLevel:"all"}); setBar(.85);
200
  setStatus("downloading decoder…");
@@ -227,23 +227,18 @@ function curAction(){
227
  }
228
 
229
  async function genFrame(act){
230
- const zbuf=new Float32Array(8*N);
231
- for(let f=0;f<7;f++) zbuf.set(ctx[f], f*N);
232
- const abuf=new Float32Array(8*ROW);
233
- for(let f=0;f<7;f++) abuf.set(acts[f], f*ROW);
234
- abuf.set(act, 7*ROW);
235
- const aT=new ort.Tensor("float32",abuf,[1,8,ROW]);
236
- let cur=randn(N);
237
- for(let st=0; st<K; st++){
238
- zbuf.set(cur, 7*N);
239
- const zT=new ort.Tensor("float32",zbuf,[1,8,META.z_ch,META.hz,META.wz]);
240
- const tb=new Float32Array(8).fill(1); tb[7]=st/K;
241
- const tT=new ort.Tensor("float32",tb,[1,8]);
242
- const out=await dit.run({z:zT,t:tT,a:aT});
243
- const v=out.v.data; const base=7*N;
244
- for(let j=0;j<N;j++) cur[j]+=(1/K)*v[base+j];
245
- }
246
- return cur;
247
  }
248
 
249
  const oc=$("screen").getContext("2d"); const IMG=oc.createImageData(384,192);
 
194
 
195
  setBar(.05);
196
  setStatus("downloading dynamics model…");
197
+ const ditBuf=await fetchProgress("genframe_fp16.onnx","dynamics"); setBar(.7);
198
  setStatus("compiling dynamics on "+DEV+"…");
199
  dit=await ort.InferenceSession.create(ditBuf,{executionProviders:eps, graphOptimizationLevel:"all"}); setBar(.85);
200
  setStatus("downloading decoder…");
 
227
  }
228
 
229
  async function genFrame(act){
230
+ // single graph does prefill(7 ctx frames) once + k decode steps internally (KV-cache)
231
+ const czbuf=new Float32Array(7*N);
232
+ for(let f=0;f<7;f++) czbuf.set(ctx[f], f*N);
233
+ const cabuf=new Float32Array(7*ROW);
234
+ for(let f=0;f<7;f++) cabuf.set(acts[f], f*ROW);
235
+ const out=await dit.run({
236
+ ctx_z:new ort.Tensor("float32",czbuf,[1,7,META.z_ch,META.hz,META.wz]),
237
+ ctx_a:new ort.Tensor("float32",cabuf,[1,7,ROW]),
238
+ cur_a:new ort.Tensor("float32",act,[1,ROW]),
239
+ noise:new ort.Tensor("float32",randn(N),[1,META.z_ch,META.hz,META.wz])
240
+ });
241
+ return out.cur.data;
 
 
 
 
 
242
  }
243
 
244
  const oc=$("screen").getContext("2d"); const IMG=oc.createImageData(384,192);