Files
turboquant/tests/test_turboquant.py
Alexander Whitestone f60604ddcc
All checks were successful
Smoke Test / smoke (pull_request) Successful in 12s
Fix #679: Generate GENOME.md for turboquant
- Created comprehensive GENOME.md with full codebase analysis
- Added architecture diagram (Mermaid)
- Documented entry points and data flow
- Identified key abstractions
- Mapped API surface (C, Metal, CLI)
- Identified test coverage gaps
- Documented security considerations
- Added basic test suite (9 tests passing)

Key findings:
- 73.4% KV memory savings (turbo4 vs f16)
- ~1% prompt overhead, ~11% generation overhead
- PolarQuant + QJL = 3.5 bits/channel
- Metal shaders exist on feature branch
- CPU reference incompatible with Metal dequant
- QJL infrastructure present but disabled

Test coverage gaps:
- No unit tests for encode/decode
- No integration tests
- No perplexity runner (corpus exists)
- No Metal vs CPU parity tests

Security considerations:
- Buffer overflow risk in bit packing
- No constant-time implementation
- No safety wrapper for C/C++ code
2026-04-14 19:03:21 -04:00

142 lines
5.3 KiB
Python

#!/usr/bin/env python3
"""
TurboQuant Test Suite
Tests for critical paths in KV cache compression.
Issue #679: Codebase Genome: turboquant — Full Analysis
"""
import unittest
import subprocess
import json
import os
import sys
class TestTurboQuant(unittest.TestCase):
"""Test TurboQuant implementation."""
def test_repo_structure(self):
"""Verify expected files exist."""
required_files = [
"llama-turbo.h",
"llama-turbo.cpp",
"ggml-metal-turbo.metal",
"README.md",
"GENOME.md"
]
for filename in required_files:
filepath = os.path.join(os.path.dirname(__file__), "..", filename)
self.assertTrue(os.path.exists(filepath), f"Missing required file: {filename}")
def test_benchmarks_exist(self):
"""Verify benchmark scripts exist."""
benchmark_files = [
"benchmarks/run_benchmarks.py",
"benchmarks/run_perplexity.py",
"benchmarks/run_long_session.py"
]
for filename in benchmark_files:
filepath = os.path.join(os.path.dirname(__file__), "..", filename)
self.assertTrue(os.path.exists(filepath), f"Missing benchmark file: {filename}")
def test_docs_complete(self):
"""Verify documentation exists."""
doc_files = [
"docs/PROJECT_STATUS.md",
"profiles/README.md"
]
for filename in doc_files:
filepath = os.path.join(os.path.dirname(__file__), "..", filename)
self.assertTrue(os.path.exists(filepath), f"Missing doc file: {filename}")
def test_genome_generated(self):
"""Verify GENOME.md was generated."""
genome_path = os.path.join(os.path.dirname(__file__), "..", "GENOME.md")
self.assertTrue(os.path.exists(genome_path), "GENOME.md not found")
# Check it has required sections
with open(genome_path, 'r') as f:
content = f.read()
required_sections = [
"## Project Overview",
"## Architecture",
"## Entry Points",
"## Data Flow",
"## Key Abstractions",
"## API Surface",
"## Test Coverage Gaps",
"## Security Considerations"
]
for section in required_sections:
self.assertIn(section, content, f"GENOME.md missing section: {section}")
def test_metal_shader_syntax(self):
"""Basic syntax check for Metal shader."""
shader_path = os.path.join(os.path.dirname(__file__), "..", "ggml-metal-turbo.metal")
with open(shader_path, 'r') as f:
content = f.read()
# Check for key functions
self.assertIn("kernel_fwht_128", content, "Missing kernel_fwht_128 function")
self.assertIn("kernel_turbo4_dequant", content, "Missing kernel_turbo4_dequant function")
self.assertIn("turbo4_centroids", content, "Missing turbo4_centroids array")
def test_cpp_header(self):
"""Verify C++ header has correct declarations."""
header_path = os.path.join(os.path.dirname(__file__), "..", "llama-turbo.h")
with open(header_path, 'r') as f:
content = f.read()
# Check for function declarations
self.assertIn("polar_quant_encode_turbo4", content, "Missing encode function")
self.assertIn("polar_quant_decode_turbo4", content, "Missing decode function")
self.assertIn('extern "C"', content, "Missing C linkage")
class TestBenchmarks(unittest.TestCase):
"""Test benchmark infrastructure."""
def test_benchmark_imports(self):
"""Verify benchmark script can be imported."""
benchmark_path = os.path.join(os.path.dirname(__file__), "..", "benchmarks", "run_benchmarks.py")
# Check file exists
self.assertTrue(os.path.exists(benchmark_path), "Benchmark script not found")
# Check it has main function
with open(benchmark_path, 'r') as f:
content = f.read()
self.assertIn("def main():", content, "Benchmark script missing main function")
self.assertIn("argparse", content, "Benchmark script missing argparse")
class TestDocumentation(unittest.TestCase):
"""Test documentation completeness."""
def test_readme_sections(self):
"""Verify README has required sections."""
readme_path = os.path.join(os.path.dirname(__file__), "..", "README.md")
with open(readme_path, 'r') as f:
content = f.read()
required_sections = ["## What", "## Why", "## Status", "## Roles"]
for section in required_sections:
self.assertIn(section, content, f"README missing section: {section}")
def test_project_status_sections(self):
"""Verify PROJECT_STATUS.md has required sections."""
status_path = os.path.join(os.path.dirname(__file__), "..", "docs", "PROJECT_STATUS.md")
with open(status_path, 'r') as f:
content = f.read()
# Check for key findings
self.assertIn("73%", content, "Missing 73% savings metric")
self.assertIn("PolarQuant", content, "Missing PolarQuant references")
self.assertIn("Metal", content, "Missing Metal shader references")
if __name__ == "__main__":
unittest.main()