23f7624596
ADR-166 MCP Bridge Security Lock / Static-source security lock (push) Failing after 0s
ADR-166 MCP Bridge Security Lock / Compose default binds loopback + Mongo has auth (push) Failing after 2s
CodeQL Advanced / Analyze (rust) (push) Failing after 0s
ADR-166 MCP Bridge Security Lock / plugin-agent-federation bindHost default (push) Failing after 1s
ADR-166 MCP Bridge Security Lock / Runtime behavior — 401 + terminal gate + fail-closed (push) Failing after 4s
business-pods-smoke / smoke (push) Failing after 1s
all-plugins-smoke / smoke-all (push) Failing after 2s
CI/CD Pipeline / Security & Code Quality (push) Failing after 1s
CI/CD Pipeline / Test Suite (ubuntu-latest) (push) Failing after 1s
CI/CD Pipeline / Build & Package (macos-latest) (push) Has been skipped
CI/CD Pipeline / Build & Package (ubuntu-latest) (push) Has been skipped
CI/CD Pipeline / Build & Package (windows-latest) (push) Has been skipped
CI/CD Pipeline / Documentation & Examples (push) Failing after 1s
Clone Tracker (14-day rolling) / Snapshot clones for ruflo ecosystem (push) Failing after 1s
CodeQL Advanced / Analyze (actions) (push) Failing after 1s
CodeQL Advanced / Analyze (javascript-typescript) (push) Failing after 1s
federation-peer-rust / stable-noop (push) Failing after 1s
metaharness-ci / score (push) Failing after 1s
metaharness-ci / router-compat (push) Failing after 0s
metaharness-ci / similarity-tests (push) Failing after 0s
no-agentbbs-smoke / smoke-without-agentbbs (push) Failing after 1s
V3 CI/CD Pipeline / Build V3 (windows-latest) (push) Has been skipped
codex-integration-audit / Codex integration audit (push) Failing after 1s
helpers-manifest-guard / guard (push) Failing after 1s
🔗 Cross-Agent Integration Tests / 🤝 Agent Coordination Tests (push) Has been skipped
🔗 Cross-Agent Integration Tests / 🧠 Memory Sharing Integration (push) Has been skipped
🔗 Cross-Agent Integration Tests / 🛡️ Fault Tolerance Tests (push) Has been skipped
🔗 Cross-Agent Integration Tests / ⚡ Performance Integration Tests (push) Has been skipped
metaharness-ci / mcp-scan (push) Failing after 1s
metaharness-ci / eject-dryrun (push) Failing after 1s
metaharness-ci / metaharness-real-data (push) Failing after 0s
no-cli-optdep-bloat-2561 / guard (push) Failing after 1s
no-metaharness-smoke / smoke-without-metaharness (push) Failing after 1s
no-phantom-agentic-flow-subpath / guard (push) Failing after 1s
🔄 Automated Rollback Manager / 🚨 Failure Detection (push) Failing after 1s
V3 CI/CD Pipeline / Plugin hooks smoke / ubuntu-latest / Node 22 (push) Failing after 1s
V3 CI/CD Pipeline / ruflo-graph-intelligence build + test smoke (#2044, ADR-123) (push) Failing after 1s
CVE Audit Gate / Audit root (critical-blocking) (push) Failing after 2s
cost-tracker-smoke / smoke (push) Failing after 3s
oia-audit-weekly / audit (push) Failing after 2s
ruflo-agent-smoke / ruflo-agent structural smoke (push) Failing after 1s
📊 Status Badges Update / 📊 Update Status Badges (push) Failing after 1s
V3 CI/CD Pipeline / Static regression guards (#2267 YAML + (push) Failing after 1s
V3 CI/CD Pipeline / Test V3 Packages (push) Failing after 0s
V3 CI/CD Pipeline / agent_execute provider routing smoke (#2042) (push) Failing after 0s
CVE Audit Gate / Audit v3 (critical-blocking) (push) Failing after 1s
federation-peer-rust / stable-native (push) Failing after 2s
🔗 Cross-Agent Integration Tests / 🚀 Integration Test Setup (push) Failing after 2s
neural-trader-smoke / runtime-smoke (push) Failing after 1s
V3 CI/CD Pipeline / Build V3 (macos-latest) (push) Has been skipped
V3 CI/CD Pipeline / Build V3 (ubuntu-latest) (push) Has been skipped
V3 CI/CD Pipeline / Type Check V3 (push) Failing after 1s
V3 CI/CD Pipeline / Smoke (no better-sqlite3) / ubuntu-latest / Node 24 (push) Failing after 1s
V3 CI/CD Pipeline / Smoke (no better-sqlite3) / ubuntu-latest / Node 22 (push) Failing after 2s
V3 CI/CD Pipeline / browser rvf create flag smoke (#2015) (push) Failing after 0s
V3 CI/CD Pipeline / Dependency review (#2046) (push) Has been skipped
V3 CI/CD Pipeline / Supply-chain audit (#2046) (push) Failing after 0s
V3 CI/CD Pipeline / witness marker drift smoke (#2021) (push) Failing after 1s
V3 CI/CD Pipeline / neural-trader portfolio CG smoke (#2068, ADR-126 Phase 3) (push) Failing after 1s
V3 CI/CD Pipeline / neural-trader backtest signing smoke (#2068, ADR-126 Phase 4) (push) Failing after 1s
V3 CI/CD Pipeline / kg-extract type-import classification smoke (#2049) (push) Failing after 0s
V3 CI/CD Pipeline / witness verify precondition smoke (#1880) (push) Failing after 2s
V3 CI/CD Pipeline / neural-trader pipeline risk-gate smoke (#2068, ADR-126 Phase 5) (push) Failing after 0s
V3 CI/CD Pipeline / neural-trader feature attribution smoke (#2068, ADR-126 Phase 6) (push) Failing after 0s
V3 CI/CD Pipeline / plugin-registry signature verification smoke (#1922, CWE-347) (push) Failing after 4s
V3 CI/CD Pipeline / memory stats legacy-DB smoke (#2120) (push) Failing after 4s
V3 CI/CD Pipeline / github deprecated actions smoke (#2089, ADR-127 Phase 3) (push) Failing after 1s
V3 CI/CD Pipeline / graph query + pathfinder smoke (ADR-130 P2+P5) (push) Has been skipped
V3 CI/CD Pipeline / graph trajectory hooks smoke (ADR-130 P3) (push) Has been skipped
V3 CI/CD Pipeline / graph plugin adapter smoke (ADR-130 P4) (push) Has been skipped
V3 CI/CD Pipeline / graph benchmark (ADR-130 P6) (push) Has been skipped
V3 CI/CD Pipeline / statusline generator delegation smoke (#2195) (push) Failing after 1s
V3 CI/CD Pipeline / wizard init regression guard (#2206 (push) Failing after 1s
V3 CI/CD Pipeline / memory no-stray-db smoke (ADR-125 P7) (push) Failing after 1s
V3 CI/CD Pipeline / github-safe injection smoke (#2089, ADR-127 Phase 1) (push) Failing after 1s
V3 CI/CD Pipeline / github actions pin smoke (#2089, ADR-127 Phase 1) (push) Failing after 1s
V3 CI/CD Pipeline / github attribution opt-in smoke (#2089, ADR-127 Phase 4) (push) Failing after 1s
V3 CI/CD Pipeline / pre-bash hook safety smoke (#2017) (push) Failing after 1s
V3 CI/CD Pipeline / Memory import smoke / ubuntu-latest (push) Failing after 0s
V3 CI/CD Pipeline / MCP protocol smoke / ubuntu-latest (push) Failing after 2s
V3 CI/CD Pipeline / ruvllm WASM auto-init smoke (#2086) (push) Failing after 4s
V3 CI/CD Pipeline / MCP paired-tool round-trip smoke (#1889) (push) Failing after 1s
V3 CI/CD Pipeline / Plugin package install-safety (#1902/#1903/#1904) (push) Failing after 1s
V3 CI/CD Pipeline / Tool description discoverability (ADR-112) (push) Failing after 3s
V3 CI/CD Pipeline / CLI npx-install smoke (#1147 / (22) (push) Failing after 1s
V3 CI/CD Pipeline / CLI npx-install smoke (#1147 / (24) (push) Failing after 1s
V3 CI/CD Pipeline / Windows hook shim smoke (#2132) / ubuntu-latest (push) Failing after 2s
V3 CI/CD Pipeline / Windows hook execution smoke (#2132) / ubuntu-latest (push) Failing after 1s
V3 CI/CD Pipeline / Windows init hooks smoke (#2132) / ubuntu-latest (push) Failing after 1s
V3 CI/CD Pipeline / Vector-index dimension audit (#1947) (push) Failing after 0s
V3 CI/CD Pipeline / Hook-command install safety (#1921) (push) Failing after 1s
V3 CI/CD Pipeline / ToolOutputGuardrail smoke (ADR-131, (push) Failing after 1s
V3 CI/CD Pipeline / init-bundle invariants smoke (#2095, ADR-128 Phase 5) (push) Failing after 1s
V3 CI/CD Pipeline / wasm provider bridge smoke (ADR-129 P1) (push) Failing after 2s
V3 CI/CD Pipeline / wasm gallery CRUD smoke (ADR-129 P3) (push) Failing after 1s
V3 CI/CD Pipeline / wasm plugin bridge smoke (ADR-129 P4) (push) Failing after 0s
V3 CI/CD Pipeline / wasm compose smoke (ADR-129 P2) (push) Failing after 4s
V3 CI/CD Pipeline / graph schema smoke (ADR-130 P1) (push) Failing after 0s
Validate Marketplace / validate (push) Failing after 1s
🔍 Verification Pipeline / 🚀 Setup Verification (push) Failing after 1s
🔍 Verification Pipeline / 🛡️ Security Verification (push) Has been skipped
🔍 Verification Pipeline / 📝 Code Quality (push) Has been skipped
🔍 Verification Pipeline / 🧪 Test Verification (${{ matrix.os }}, Node ${{ matrix.node }}) (push) Has been skipped
🔍 Verification Pipeline / 🏗️ Build Verification (push) Has been skipped
🔍 Verification Pipeline / 📚 Documentation Verification (push) Has been skipped
CVE Audit Gate / High-severity report (warn only) (push) Has been cancelled
🔄 Automated Rollback Manager / 🔄 Execute Rollback (push) Has been cancelled
🔄 Automated Rollback Manager / ✅ Post-Rollback Verification (push) Has been cancelled
🔄 Automated Rollback Manager / 📊 Rollback Monitoring (push) Has been cancelled
V3 CI/CD Pipeline / Windows init hooks smoke (#2132) / windows-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook execution smoke (#2132) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook execution smoke (#2132) / windows-latest (push) Has been cancelled
🔄 Automated Rollback Manager / ⏳ Manual Rollback Approval (push) Has been cancelled
V3 CI/CD Pipeline / MCP protocol smoke / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Memory import smoke / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook shim smoke (#2132) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook shim smoke (#2132) / windows-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows init hooks smoke (#2132) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Witness verify (signed manifest) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Witness verify (signed manifest) / ubuntu-latest (push) Has been cancelled
V3 CI/CD Pipeline / Witness verify (signed manifest) / windows-latest (push) Has been cancelled
V3 CI/CD Pipeline / Publish to npm (alpha) (push) Has been cancelled
V3 CI/CD Pipeline / Smoke (no better-sqlite3) / macos-latest / Node 22 (push) Has been cancelled
V3 CI/CD Pipeline / Plugin hooks smoke / macos-latest / Node 22 (push) Has been cancelled
CI/CD Pipeline / Deploy & Release (push) Has been cancelled
CI/CD Pipeline / CI Status (push) Has been cancelled
🔗 Cross-Agent Integration Tests / 📊 Integration Test Report (push) Has been cancelled
🔄 Automated Rollback Manager / 🔍 Pre-Rollback Validation (push) Has been cancelled
🔍 Verification Pipeline / ⚡ Performance Verification (push) Has been cancelled
🔍 Verification Pipeline / 📊 Verification Report (push) Has been cancelled
516 lines
16 KiB
TypeScript
516 lines
16 KiB
TypeScript
/**
|
|
* AttentionBenchmarkRunner Test Suite
|
|
*
|
|
* Comprehensive tests for benchmark runner, suite execution, memory profiling,
|
|
* and V3 performance target validation (2.49x-7.47x speedup).
|
|
*/
|
|
|
|
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
import {
|
|
AttentionBenchmarkRunner,
|
|
quickValidation,
|
|
formatBenchmarkTable,
|
|
formatSuiteReport,
|
|
formatMemoryProfile,
|
|
type ComparisonBenchmark,
|
|
type SuiteResult,
|
|
type MemoryProfile,
|
|
} from '../src/attention-benchmarks.js';
|
|
|
|
describe('AttentionBenchmarkRunner', () => {
|
|
let runner: AttentionBenchmarkRunner;
|
|
|
|
beforeEach(() => {
|
|
runner = new AttentionBenchmarkRunner();
|
|
});
|
|
|
|
describe('runComparison()', () => {
|
|
it('should run comparison benchmark with default parameters', () => {
|
|
const result = runner.runComparison(256, 50, 100);
|
|
|
|
expect(result).toBeDefined();
|
|
expect(result.name).toContain('Flash Attention');
|
|
expect(result.name).toContain('256D');
|
|
expect(result.dimension).toBe(256);
|
|
expect(result.numKeys).toBe(50);
|
|
expect(result.iterations).toBe(100);
|
|
});
|
|
|
|
it('should measure Flash Attention performance', () => {
|
|
const result = runner.runComparison(256, 50, 100);
|
|
|
|
expect(result.results.flash).toBeDefined();
|
|
expect(result.results.flash.averageTimeMs).toBeGreaterThan(0);
|
|
expect(result.results.flash.opsPerSecond).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('should measure baseline performance', () => {
|
|
const result = runner.runComparison(256, 50, 100);
|
|
|
|
expect(result.results.baseline).toBeDefined();
|
|
expect(result.results.baseline.averageTimeMs).toBeGreaterThan(0);
|
|
expect(result.results.baseline.opsPerSecond).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('should calculate speedup correctly', () => {
|
|
const result = runner.runComparison(256, 50, 100);
|
|
|
|
const expectedSpeedup =
|
|
result.results.baseline.averageTimeMs / result.results.flash.averageTimeMs;
|
|
|
|
expect(result.results.speedup).toBeCloseTo(expectedSpeedup, 2);
|
|
expect(result.results.speedup).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('should validate against target (2.49x minimum)', () => {
|
|
const result = runner.runComparison(512, 100, 1000);
|
|
|
|
expect(result.meetsTarget).toBe(result.results.speedup >= 2.49);
|
|
});
|
|
|
|
it('should include timestamp', () => {
|
|
const result = runner.runComparison(256, 50, 100);
|
|
|
|
expect(result.timestamp).toBeInstanceOf(Date);
|
|
});
|
|
|
|
it('should handle different dimensions', () => {
|
|
const dimensions = [128, 256, 512, 1024];
|
|
|
|
for (const dim of dimensions) {
|
|
const result = runner.runComparison(dim, 50, 100);
|
|
expect(result.dimension).toBe(dim);
|
|
expect(result.results.speedup).toBeGreaterThan(0);
|
|
}
|
|
});
|
|
|
|
it('should handle varying number of keys', () => {
|
|
const keysCounts = [10, 50, 100, 200];
|
|
|
|
for (const numKeys of keysCounts) {
|
|
const result = runner.runComparison(256, numKeys, 100);
|
|
expect(result.numKeys).toBe(numKeys);
|
|
expect(result.results.speedup).toBeGreaterThan(0);
|
|
}
|
|
});
|
|
|
|
it('should complete in reasonable time', () => {
|
|
const startTime = performance.now();
|
|
runner.runComparison(128, 20, 50); // Small benchmark
|
|
const endTime = performance.now();
|
|
|
|
const duration = endTime - startTime;
|
|
expect(duration).toBeLessThan(10000); // <10s for small benchmark
|
|
});
|
|
});
|
|
|
|
describe('runComprehensiveSuite()', () => {
|
|
it('should run comprehensive benchmark suite', () => {
|
|
const suite = runner.runComprehensiveSuite();
|
|
|
|
expect(suite).toBeDefined();
|
|
expect(suite.suiteName).toContain('Comprehensive');
|
|
expect(suite.benchmarks).toBeDefined();
|
|
expect(suite.benchmarks.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('should test multiple dimensions', () => {
|
|
const suite = runner.runComprehensiveSuite();
|
|
|
|
// Should test at least 128, 256, 512, 768, 1024
|
|
expect(suite.benchmarks.length).toBeGreaterThanOrEqual(5);
|
|
|
|
const dimensions = suite.benchmarks.map(b => b.dimension);
|
|
expect(dimensions).toContain(128);
|
|
expect(dimensions).toContain(256);
|
|
expect(dimensions).toContain(512);
|
|
});
|
|
|
|
it('should include summary statistics', () => {
|
|
const suite = runner.runComprehensiveSuite();
|
|
|
|
expect(suite.summary).toBeDefined();
|
|
expect(suite.summary.averageSpeedup).toBeGreaterThan(0);
|
|
expect(suite.summary.minSpeedup).toBeGreaterThan(0);
|
|
expect(suite.summary.maxSpeedup).toBeGreaterThanOrEqual(suite.summary.minSpeedup);
|
|
expect(suite.summary.totalBenchmarks).toBe(suite.benchmarks.length);
|
|
});
|
|
|
|
it('should calculate success rate', () => {
|
|
const suite = runner.runComprehensiveSuite();
|
|
|
|
expect(suite.summary.successRate).toBeGreaterThanOrEqual(0);
|
|
expect(suite.summary.successRate).toBeLessThanOrEqual(100);
|
|
|
|
const expectedSuccessRate =
|
|
(suite.summary.targetsMet / suite.summary.totalBenchmarks) * 100;
|
|
expect(suite.summary.successRate).toBeCloseTo(expectedSuccessRate, 2);
|
|
});
|
|
|
|
it('should track targets met', () => {
|
|
const suite = runner.runComprehensiveSuite();
|
|
|
|
const manualCount = suite.benchmarks.filter(b => b.meetsTarget).length;
|
|
expect(suite.summary.targetsMet).toBe(manualCount);
|
|
});
|
|
|
|
it('should include timestamp', () => {
|
|
const suite = runner.runComprehensiveSuite();
|
|
|
|
expect(suite.timestamp).toBeInstanceOf(Date);
|
|
});
|
|
});
|
|
|
|
describe('runMemoryProfile()', () => {
|
|
it('should run memory profile with default dimensions', () => {
|
|
const profiles = runner.runMemoryProfile();
|
|
|
|
expect(profiles).toBeDefined();
|
|
expect(profiles.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('should profile multiple dimensions', () => {
|
|
const dimensions = [128, 256, 512];
|
|
const profiles = runner.runMemoryProfile(dimensions);
|
|
|
|
expect(profiles.length).toBe(dimensions.length);
|
|
|
|
for (let i = 0; i < dimensions.length; i++) {
|
|
expect(profiles[i].dimension).toBe(dimensions[i]);
|
|
}
|
|
});
|
|
|
|
it('should measure Flash Attention memory', () => {
|
|
const profiles = runner.runMemoryProfile([256]);
|
|
|
|
expect(profiles[0].flashMemoryBytes).toBeGreaterThanOrEqual(0);
|
|
});
|
|
|
|
it('should measure baseline memory', () => {
|
|
const profiles = runner.runMemoryProfile([256]);
|
|
|
|
expect(profiles[0].baselineMemoryBytes).toBeGreaterThanOrEqual(0);
|
|
});
|
|
|
|
it('should calculate memory reduction', () => {
|
|
const profiles = runner.runMemoryProfile([256]);
|
|
|
|
expect(profiles[0].reduction).toBeGreaterThanOrEqual(0);
|
|
expect(profiles[0].reductionBytes).toBeGreaterThanOrEqual(0);
|
|
});
|
|
|
|
it('should include number of keys', () => {
|
|
const profiles = runner.runMemoryProfile([512]);
|
|
|
|
expect(profiles[0].numKeys).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('should handle custom dimension arrays', () => {
|
|
const customDims = [64, 128, 256, 512, 1024];
|
|
const profiles = runner.runMemoryProfile(customDims);
|
|
|
|
expect(profiles.length).toBe(customDims.length);
|
|
});
|
|
});
|
|
|
|
describe('runStressTest()', () => {
|
|
it('should run stress test successfully', () => {
|
|
const results = runner.runStressTest();
|
|
|
|
expect(results).toBeDefined();
|
|
expect(results.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('should test increasing loads', () => {
|
|
const results = runner.runStressTest();
|
|
|
|
// Should test progressively larger key counts
|
|
const keyCounts = results.map(r => r.numKeys);
|
|
|
|
for (let i = 1; i < keyCounts.length; i++) {
|
|
expect(keyCounts[i]).toBeGreaterThanOrEqual(keyCounts[i - 1]);
|
|
}
|
|
});
|
|
|
|
it('should maintain same dimension', () => {
|
|
const results = runner.runStressTest();
|
|
|
|
const dimensions = results.map(r => r.dimension);
|
|
const uniqueDims = new Set(dimensions);
|
|
|
|
// All stress tests should use same dimension (512)
|
|
expect(uniqueDims.size).toBe(1);
|
|
});
|
|
|
|
it('should handle high key counts', () => {
|
|
const results = runner.runStressTest();
|
|
|
|
// Should test up to 5000 keys
|
|
const maxKeys = Math.max(...results.map(r => r.numKeys));
|
|
expect(maxKeys).toBeGreaterThan(1000);
|
|
});
|
|
|
|
it('should not throw on stress conditions', () => {
|
|
expect(() => runner.runStressTest()).not.toThrow();
|
|
});
|
|
});
|
|
|
|
describe('validateV3Targets()', () => {
|
|
it('should validate V3 performance targets', () => {
|
|
const validation = runner.validateV3Targets();
|
|
|
|
expect(validation).toBeDefined();
|
|
expect(validation.meetsMinimum).toBeDefined();
|
|
expect(validation.meetsMaximum).toBeDefined();
|
|
expect(validation.actualSpeedup).toBeDefined();
|
|
expect(validation.target).toBeDefined();
|
|
});
|
|
|
|
it('should check minimum target (2.49x)', () => {
|
|
const validation = runner.validateV3Targets();
|
|
|
|
expect(validation.target.min).toBe(2.49);
|
|
expect(validation.meetsMinimum).toBe(validation.actualSpeedup >= 2.49);
|
|
});
|
|
|
|
it('should check maximum target (7.47x)', () => {
|
|
const validation = runner.validateV3Targets();
|
|
|
|
expect(validation.target.max).toBe(7.47);
|
|
expect(validation.meetsMaximum).toBe(validation.actualSpeedup <= 7.47);
|
|
});
|
|
|
|
it('should return valid speedup value', () => {
|
|
const validation = runner.validateV3Targets();
|
|
|
|
expect(validation.actualSpeedup).toBeGreaterThan(0);
|
|
expect(validation.actualSpeedup).toBeLessThan(1000); // Sanity check
|
|
});
|
|
|
|
it('should use 512 dimension for validation', () => {
|
|
// Default dimension for V3 validation should be 512
|
|
const validation = runner.validateV3Targets();
|
|
|
|
expect(validation.actualSpeedup).toBeGreaterThan(0);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('Formatting Functions', () => {
|
|
describe('formatBenchmarkTable()', () => {
|
|
it('should format benchmark as table', () => {
|
|
const runner = new AttentionBenchmarkRunner();
|
|
const benchmark = runner.runComparison(256, 50, 100);
|
|
|
|
const table = formatBenchmarkTable(benchmark);
|
|
|
|
expect(table).toBeDefined();
|
|
expect(typeof table).toBe('string');
|
|
expect(table).toContain('Flash Attention');
|
|
expect(table).toContain('Baseline');
|
|
expect(table).toContain('Speedup');
|
|
});
|
|
|
|
it('should include target status', () => {
|
|
const runner = new AttentionBenchmarkRunner();
|
|
const benchmark = runner.runComparison(256, 50, 100);
|
|
|
|
const table = formatBenchmarkTable(benchmark);
|
|
|
|
expect(table).toContain('Target Met');
|
|
expect(table).toMatch(/YES|NO/);
|
|
});
|
|
|
|
it('should show checkmark for met targets', () => {
|
|
const runner = new AttentionBenchmarkRunner();
|
|
const benchmark = runner.runComparison(512, 100, 1000);
|
|
|
|
const table = formatBenchmarkTable(benchmark);
|
|
|
|
if (benchmark.meetsTarget) {
|
|
expect(table).toContain('✓');
|
|
} else {
|
|
expect(table).toContain('✗');
|
|
}
|
|
});
|
|
});
|
|
|
|
describe('formatSuiteReport()', () => {
|
|
it('should format suite as report', () => {
|
|
const runner = new AttentionBenchmarkRunner();
|
|
const suite = runner.runComprehensiveSuite();
|
|
|
|
const report = formatSuiteReport(suite);
|
|
|
|
expect(report).toBeDefined();
|
|
expect(typeof report).toBe('string');
|
|
expect(report).toContain('Summary');
|
|
expect(report).toContain('Average Speedup');
|
|
});
|
|
|
|
it('should include all benchmarks', () => {
|
|
const runner = new AttentionBenchmarkRunner();
|
|
const suite = runner.runComprehensiveSuite();
|
|
|
|
const report = formatSuiteReport(suite);
|
|
|
|
for (const benchmark of suite.benchmarks) {
|
|
expect(report).toContain(benchmark.name);
|
|
}
|
|
});
|
|
|
|
it('should show summary statistics', () => {
|
|
const runner = new AttentionBenchmarkRunner();
|
|
const suite = runner.runComprehensiveSuite();
|
|
|
|
const report = formatSuiteReport(suite);
|
|
|
|
expect(report).toContain('Min Speedup');
|
|
expect(report).toContain('Max Speedup');
|
|
expect(report).toContain('Targets Met');
|
|
});
|
|
});
|
|
|
|
describe('formatMemoryProfile()', () => {
|
|
it('should format memory profile as table', () => {
|
|
const runner = new AttentionBenchmarkRunner();
|
|
const profiles = runner.runMemoryProfile([256, 512]);
|
|
|
|
const table = formatMemoryProfile(profiles);
|
|
|
|
expect(table).toBeDefined();
|
|
expect(typeof table).toBe('string');
|
|
expect(table).toContain('Memory Profile');
|
|
expect(table).toContain('Flash');
|
|
expect(table).toContain('Baseline');
|
|
expect(table).toContain('Reduction');
|
|
});
|
|
|
|
it('should include all dimensions', () => {
|
|
const dimensions = [128, 256, 512];
|
|
const runner = new AttentionBenchmarkRunner();
|
|
const profiles = runner.runMemoryProfile(dimensions);
|
|
|
|
const table = formatMemoryProfile(profiles);
|
|
|
|
for (const dim of dimensions) {
|
|
expect(table).toContain(dim.toString());
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('quickValidation()', () => {
|
|
it('should run quick validation', () => {
|
|
const result = quickValidation();
|
|
|
|
expect(typeof result).toBe('boolean');
|
|
});
|
|
|
|
it('should return true if meets targets', () => {
|
|
const runner = new AttentionBenchmarkRunner();
|
|
const validation = runner.validateV3Targets();
|
|
|
|
const result = quickValidation();
|
|
|
|
const expected = validation.meetsMinimum && validation.meetsMaximum;
|
|
expect(result).toBe(expected);
|
|
});
|
|
});
|
|
|
|
describe('Performance Validation', () => {
|
|
it('should demonstrate consistent speedup', () => {
|
|
const runner = new AttentionBenchmarkRunner();
|
|
|
|
const result1 = runner.runComparison(256, 50, 100);
|
|
const result2 = runner.runComparison(256, 50, 100);
|
|
|
|
// Speedup should be relatively consistent (within 50% variance)
|
|
const ratio = result1.results.speedup / result2.results.speedup;
|
|
expect(ratio).toBeGreaterThan(0.5);
|
|
expect(ratio).toBeLessThan(2.0);
|
|
});
|
|
|
|
it('should show improved performance with Flash Attention', () => {
|
|
const runner = new AttentionBenchmarkRunner();
|
|
const result = runner.runComparison(512, 100, 1000);
|
|
|
|
// Flash should generally be faster, but allow small variance
|
|
// Due to timing precision and JIT warmup, we check speedup is positive
|
|
expect(result.results.speedup).toBeGreaterThan(0.5); // At least some speedup
|
|
});
|
|
|
|
it('should validate across all test dimensions', () => {
|
|
const runner = new AttentionBenchmarkRunner();
|
|
const suite = runner.runComprehensiveSuite();
|
|
|
|
// All benchmarks should have positive speedup
|
|
for (const benchmark of suite.benchmarks) {
|
|
expect(benchmark.results.speedup).toBeGreaterThan(0);
|
|
}
|
|
});
|
|
|
|
it('should track operations per second correctly', () => {
|
|
const runner = new AttentionBenchmarkRunner();
|
|
const result = runner.runComparison(256, 50, 100);
|
|
|
|
// Ops/sec should be inverse of average time
|
|
const expectedFlashOps = 1000 / result.results.flash.averageTimeMs;
|
|
const expectedBaselineOps = 1000 / result.results.baseline.averageTimeMs;
|
|
|
|
expect(result.results.flash.opsPerSecond).toBeCloseTo(expectedFlashOps, 1);
|
|
expect(result.results.baseline.opsPerSecond).toBeCloseTo(expectedBaselineOps, 1);
|
|
});
|
|
});
|
|
|
|
describe('Edge Cases', () => {
|
|
it('should handle very small dimensions', () => {
|
|
const runner = new AttentionBenchmarkRunner();
|
|
const result = runner.runComparison(32, 10, 50);
|
|
|
|
expect(result).toBeDefined();
|
|
expect(result.results.speedup).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('should handle very large dimensions', () => {
|
|
const runner = new AttentionBenchmarkRunner();
|
|
const result = runner.runComparison(2048, 50, 50);
|
|
|
|
expect(result).toBeDefined();
|
|
expect(result.results.speedup).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('should handle minimal iterations', () => {
|
|
const runner = new AttentionBenchmarkRunner();
|
|
const result = runner.runComparison(256, 50, 10);
|
|
|
|
expect(result).toBeDefined();
|
|
expect(result.iterations).toBe(10);
|
|
});
|
|
|
|
it('should handle many iterations', () => {
|
|
const runner = new AttentionBenchmarkRunner();
|
|
const result = runner.runComparison(128, 20, 5000);
|
|
|
|
expect(result).toBeDefined();
|
|
expect(result.iterations).toBe(5000);
|
|
});
|
|
|
|
it('should handle empty dimension array for memory profile', () => {
|
|
const runner = new AttentionBenchmarkRunner();
|
|
const profiles = runner.runMemoryProfile([]);
|
|
|
|
expect(profiles).toBeDefined();
|
|
expect(profiles.length).toBe(0);
|
|
});
|
|
|
|
it('should handle single dimension for memory profile', () => {
|
|
const runner = new AttentionBenchmarkRunner();
|
|
const profiles = runner.runMemoryProfile([512]);
|
|
|
|
expect(profiles).toBeDefined();
|
|
expect(profiles.length).toBe(1);
|
|
expect(profiles[0].dimension).toBe(512);
|
|
});
|
|
});
|