homunculus / code /falcon_demo /test2.mjs
LiteMind's picture
Add homunculus papers, code, results and model cards
8246b15 verified
Raw History Blame Contribute Delete
915 Bytes
import fs from 'fs';
import { parseSafetensors, buildModel, widen, newState, step, argmax } from './engine.js';
const cfg = JSON.parse(fs.readFileSync('config.json')), ref = JSON.parse(fs.readFileSync('ref.json'));
const base = buildModel(parseSafetensors(fs.readFileSync('../model.safetensors').buffer.slice(0)), cfg);
const axes = process.argv[2].split('+'), k = +process.argv[3], np = +process.argv[4];
const M = widen(base, axes, k); let mx = 0, am = 0;
for (let p = 0; p < np; p++) {
const A = newState(base), B = newState(M); let la, lb;
for (const t of ref.ids[p]) { la = step(base, A, t); lb = step(M, B, t); }
let m = 0; for (let i = 0; i < la.length; i++) m = Math.max(m, Math.abs(la[i] - lb[i])); mx = Math.max(mx, m); if (argmax(la) === argmax(lb)) am++;
}
console.log(`JS orig vs JS widened ${process.argv[2]} k=${k}: ${np} prompts, max|dlogit| ${mx.toExponential(2)}, argmax same ${am}/${np}`);