import * as path from "path"; import { Engine } from "./engine"; async function main(): Promise { const engine = Engine.load(path.resolve("sandbox/ck-titans-test")); // Check Titans memory const titansMem = (engine as any).titansMem; console.log("=== TITANS MEMORY CHECK ==="); console.log("Slots:", titansMem.cfg.slots); console.log("Occupancy:", titansMem.occupancy().toFixed(2)); console.log("Total writes (from log):", titansMem._writeCount || "unknown"); // Check first few chars const nonEmpty = titansMem.chars.filter((c: string) => c && c !== "").slice(0, 20); console.log("Non-empty chars sample:", nonEmpty); // Test with prompt const promptIds = engine.tokenizer.encode("小明"); const ctxWin = promptIds.slice(-engine.model.cfg.ctx); console.log("ctxWin:", ctxWin); // Test Titans read 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 length:", cache.weights.length); console.log("weights[0..9]:", Array.from(cache.weights.slice(0, 10)).map((w, i) => ({ slot: i, weight: w.toFixed(4) }))); // Find best slot 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].toFixed(4)); console.log("chars[best]:", JSON.stringify(titansMem.chars[best])); console.log("chars[best % slots]:", JSON.stringify(titansMem.chars[best % titansMem.cfg.slots])); // Test generate console.log("\n=== GENERATION TEST ==="); const res = await engine.generate({ prompt: "小明", maxLen: 20, budget: 3, temperature: 0.85, topK: 5 }); console.log("Output:", res.text); console.log("Routes:", res.routes.map((r, i) => `${i}:${r.char}(L${r.depth})`).join(" ")); console.log("MemHits:", res.routes.filter(r => r.memoryHit).length); } main().catch(err => console.error(err));