File size: 1,657 Bytes
db7bc06
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import * as path from "path";
import { Engine } from "./engine";

async function main(): Promise<void> {
  const engine = Engine.load(path.resolve("sandbox/ck-full-multi"));
  
  // 直接测试 Titans 记忆
  const titansMem = (engine as any).titansMem;
  console.log("TitansMem slots:", titansMem.cfg.slots);
  console.log("TitansMem chars (first 10):", titansMem.chars.slice(0, 10));
  console.log("TitansMem occupancy:", titansMem.occupancy().toFixed(2));
  
  // 测试 recallAt
  const promptIds = engine.tokenizer.encode("小明");
  const ctxWin = promptIds.slice(-engine.model.cfg.ctx);
  console.log("ctxWin:", ctxWin);
  
  const q = Float64Array.from(engine.model.embedAvg(ctxWin));
  const cache = { query: new Float64Array(0), keys: new Float64Array(0), values: new Float64Array(0), weights: new Float64Array(0) };
  const mem = titansMem.read(q, cache);
  
  console.log("hitSlots:", mem.hitSlots);
  console.log("weights (first 10):", cache.weights.slice(0, 10));
  
  // 找到权重最大的槽位
  let best = 0;
  for (let i = 1; i < cache.weights.length; i++) {
    if (cache.weights[i] > cache.weights[best]) best = i;
  }
  console.log("best slot:", best, "weight:", cache.weights[best]);
  console.log("chars[best]:", titansMem.chars[best]);
  console.log("chars[best % slots]:", titansMem.chars[best % titansMem.cfg.slots]);
  
  // 测试生成
  const res = await engine.generate({ prompt: "小明", maxLen: 20, budget: 3, temperature: 0.85, topK: 5 });
  console.log("\n生成结果:", res.text);
  console.log("路由统计:", res.routes.map(r => `L${r.depth}:${r.char}`).join(""));
}

main().catch(err => console.error(err));