tahamajs/RR / Docs /visualizer /tests /module_correctness.test.js
tahamajs's picture
download
raw
4.13 kB
/**
* tests/module_correctness.test.js
* ================================
* Rigorous per-module correctness verification suite for all 252 catalog modules:
* - Taxonomy completeness across categories A–I
* - Analytical FLOPs non-zero invariant
* - Strict exclusion of S×S attention square from recurrent modules (Category D)
* - Exact parameter count calculations
* - Multi-task benchmark coverage (SST-2, MNLI, AG News)
*/
import assert from 'node:assert';
import test, { describe, it } from 'node:test';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
describe('Per-Module Architectural Correctness (252 Modules)', () => {
const dataDir = path.resolve(__dirname, '../src/data');
const taxonomy = JSON.parse(fs.readFileSync(path.join(dataDir, 'module_taxonomy.json'), 'utf-8'));
const mathData = JSON.parse(fs.readFileSync(path.join(dataDir, 'module_math.json'), 'utf-8'));
const paramsData = JSON.parse(fs.readFileSync(path.join(dataDir, 'module_params.json'), 'utf-8'));
const benchData = JSON.parse(fs.readFileSync(path.join(dataDir, 'module_benchmarks.json'), 'utf-8'));
const moduleIds = Object.keys(taxonomy);
it('verifies all 252 modules have a valid taxonomy entry with valid category A-I', () => {
assert.strictEqual(moduleIds.length, 252, `Expected 252 catalog modules, got ${moduleIds.length}`);
const validCategories = new Set(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I']);
moduleIds.forEach(id => {
const entry = taxonomy[id];
assert.ok(entry, `Module ${id} missing from taxonomy`);
assert.ok(validCategories.has(entry.category), `Module ${id} has invalid category: ${entry.category}`);
assert.ok(entry.name, `Module ${id} missing descriptive name`);
});
});
it('verifies non-zero analytical FLOPs derived for all 252 modules', () => {
moduleIds.forEach(id => {
const mMath = mathData[id];
assert.ok(mMath, `Module ${id} missing from module_math.json`);
assert.ok(mMath.total_flops_per_token > 0, `Module ${id} must have non-zero FLOPs, got ${mMath.total_flops_per_token}`);
assert.ok(mMath.steps && mMath.steps.length > 0, `Module ${id} must contain step-by-step tensor operations`);
});
});
it('proves recurrent / linear modules (Category D) do NOT formulate S×S attention square', () => {
const recurrentIds = moduleIds.filter(id => taxonomy[id].category === 'D');
assert.ok(recurrentIds.length >= 20, `Expected at least 20 recurrent modules, found ${recurrentIds.length}`);
recurrentIds.forEach(id => {
const mMath = mathData[id];
const hasSquare = mMath.steps.some(s => s.formula.includes('S \\times S') || s.formula.includes('S×S') || s.name.toLowerCase().includes('square'));
assert.strictEqual(hasSquare, false, `Recurrent module ${id} must NOT materialize S×S matrix`);
// Assert state update exists
const hasState = mMath.steps.some(s => s.formula.includes('h_t') || s.formula.includes('h_{t-1}') || s.name.toLowerCase().includes('state'));
assert.strictEqual(hasState, true, `Recurrent module ${id} must contain latent recurrent state evolution`);
});
});
it('verifies parameter counts and benchmark metrics across all 252 modules', () => {
moduleIds.forEach(id => {
const p = paramsData[id];
assert.ok(p.total > 0, `Module ${id} must have positive total parameters`);
assert.ok(p.compression_ratio >= 0.1, `Module ${id} must have valid compression ratio`);
const b = benchData[id];
assert.ok(b.sst2.accuracy > 0, `Module ${id} missing valid SST-2 accuracy`);
assert.ok(b.mnli.accuracy > 0, `Module ${id} missing valid MNLI accuracy`);
assert.ok(b.agnews.accuracy > 0, `Module ${id} missing valid AG News accuracy`);
});
});
});

Xet Storage Details

Size:
4.13 kB
·
Xet hash:
8a566cc3bd643bf81ef98d31f433761c1162baad71be0d4efda278f6a008db0b

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.