Compare commits
1 Commits
step35/63-
...
step35/98-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e20439b544 |
19
ansible/README.md
Normal file
19
ansible/README.md
Normal file
@@ -0,0 +1,19 @@
|
||||
# TurboQuant Ansible Deployment
|
||||
|
||||
Deploy TurboQuant-compressed Gemma 4 inference across fleet nodes.
|
||||
|
||||
## Quick Start
|
||||
|
||||
```bash
|
||||
# Copy and edit inventory
|
||||
cp ansible/inventory.ini.example ansible/inventory.ini
|
||||
|
||||
# Deploy to all nodes
|
||||
ansible-playbook -i ansible/inventory.ini ansible/deploy_turboquant.yml
|
||||
|
||||
# Run health check
|
||||
ansible -i ansible/inventory.ini all -m shell -a "sudo /opt/turboquant/health_check.sh"
|
||||
|
||||
# Run integration test
|
||||
ansible -i ansible/inventory.ini all -m shell -a "curl -s http://localhost:8081/v1/chat/completions -d '{\"model\":\"gemma-4\",\"messages\":[{\"role\":\"user\",\"content\":\"Hello\"}]}'"
|
||||
```
|
||||
69
ansible/deploy_turboquant.yml
Normal file
69
ansible/deploy_turboquant.yml
Normal file
@@ -0,0 +1,69 @@
|
||||
---
|
||||
# deploy_turboquant.yml — Deploy TurboQuant across fleet nodes
|
||||
# Usage: ansible-playbook -i ansible/inventory.ini ansible/deploy_turboquant.yml
|
||||
|
||||
- name: Deploy TurboQuant to Mac (local)
|
||||
hosts: mac
|
||||
become: yes
|
||||
gather_facts: yes
|
||||
|
||||
vars:
|
||||
turboquant_user: "turboquant"
|
||||
turboquant_install_dir: "/opt/turboquant"
|
||||
turboquant_service_name: "turboquant"
|
||||
turboquant_port: 8081
|
||||
turboquant_host: "0.0.0.0"
|
||||
turboquant_context: 131072
|
||||
turboquant_model: "gemma-4"
|
||||
turboquant_model_file: "gemma-4-26B-A4B.gguf"
|
||||
turboquant_kv_type: "turbo4"
|
||||
turboquant_layer_adaptive: 7
|
||||
node_preset: "turboquant_k8v4"
|
||||
node_hardware: "M1-16GB"
|
||||
|
||||
roles:
|
||||
- turboquant-deploy
|
||||
|
||||
- name: Deploy TurboQuant to Allegro VPS
|
||||
hosts: allegro
|
||||
become: yes
|
||||
gather_facts: yes
|
||||
|
||||
vars:
|
||||
turboquant_user: "turboquant"
|
||||
turboquant_install_dir: "/opt/turboquant"
|
||||
turboquant_service_name: "turboquant"
|
||||
turboquant_port: 8081
|
||||
turboquant_host: "0.0.0.0"
|
||||
turboquant_context: 65536
|
||||
turboquant_model: "gemma-4-E4B"
|
||||
turboquant_model_file: "gemma-4-E4B.gguf"
|
||||
turboquant_kv_type: "q4_0"
|
||||
turboquant_layer_adaptive: 0
|
||||
node_preset: "turboquant_4bit_nc"
|
||||
node_hardware: "VPS-2c8g"
|
||||
|
||||
roles:
|
||||
- turboquant-deploy
|
||||
|
||||
- name: Deploy TurboQuant to Ezra VPS
|
||||
hosts: ezra
|
||||
become: yes
|
||||
gather_facts: yes
|
||||
|
||||
vars:
|
||||
turboquant_user: "turboquant"
|
||||
turboquant_install_dir: "/opt/turboquant"
|
||||
turboquant_service_name: "turboquant"
|
||||
turboquant_port: 8081
|
||||
turboquant_host: "0.0.0.0"
|
||||
turboquant_context: 65536
|
||||
turboquant_model: "gemma-4-E4B"
|
||||
turboquant_model_file: "gemma-4-E4B.gguf"
|
||||
turboquant_kv_type: "q4_0"
|
||||
turboquant_layer_adaptive: 0
|
||||
node_preset: "turboquant_4bit_nc"
|
||||
node_hardware: "VPS-2c8g"
|
||||
|
||||
roles:
|
||||
- turboquant-deploy
|
||||
23
ansible/health_check.sh
Executable file
23
ansible/health_check.sh
Executable file
@@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
# Health check for TurboQuant llama-server / vLLM deployment
|
||||
|
||||
set -e
|
||||
|
||||
PORT="${TURBOQUANT_PORT:-8081}"
|
||||
ENDPOINT="${TURBOQUANT_ENDPOINT:-http://localhost:${PORT}/v1/models}"
|
||||
|
||||
echo "Checking TurboQuant server health at ${ENDPOINT}..."
|
||||
|
||||
if command -v curl &> /dev/null; then
|
||||
response=$(curl -s -o /dev/null -w "%{http_code}" "${ENDPOINT}" --max-time 10)
|
||||
if [ "${response}" = "200" ]; then
|
||||
echo "✅ Server healthy — HTTP ${response}"
|
||||
exit 0
|
||||
else
|
||||
echo "❌ Server unhealthy — HTTP ${response}"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "curl not found; cannot perform health check"
|
||||
exit 2
|
||||
fi
|
||||
22
ansible/inventory.ini.example
Normal file
22
ansible/inventory.ini.example
Normal file
@@ -0,0 +1,22 @@
|
||||
# Ansible inventory for TurboQuant fleet deployment
|
||||
# Edit this file and save as ansible/inventory.ini before running
|
||||
|
||||
[mac]
|
||||
# Local MacBook — runs llama-server with Metal + TurboQuant
|
||||
timmy-mac ansible_host=localhost ansible_connection=local
|
||||
|
||||
[allegro]
|
||||
# Allegro VPS — Debian, runs llama-server or vLLM with GGUF q4_0
|
||||
allegro-primary ansible_host=167.99.126.228 ansible_user=root
|
||||
|
||||
[ezra]
|
||||
# Ezra VPS — Ubuntu, runs llama-server or vLLM
|
||||
ezra-primary ansible_host=143.198.27.163 ansible_user=root ansible_connection=local
|
||||
|
||||
[turbonodes:children]
|
||||
mac
|
||||
allegro
|
||||
ezra
|
||||
|
||||
[turbonodes:vars]
|
||||
ansible_python_interpreter=/usr/bin/python3
|
||||
68
ansible/roles/turboquant-deploy/tasks/darwin.yml
Normal file
68
ansible/roles/turboquant-deploy/tasks/darwin.yml
Normal file
@@ -0,0 +1,68 @@
|
||||
---
|
||||
# macOS deployment — builds llama.cpp with Metal + TurboQuant
|
||||
|
||||
- name: Ensure Xcode command line tools are installed
|
||||
command: xcode-select -p
|
||||
register: xcode_check
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
when: ansible_os_family == "Darwin"
|
||||
tags: [turboquant, darwin]
|
||||
|
||||
- name: Install Xcode CLI tools if missing (macOS)
|
||||
shell: xcode-select --install
|
||||
when: ansible_os_family == "Darwin" and xcode_check.rc != 0
|
||||
tags: [turboquant, darwin]
|
||||
|
||||
- name: Check for Git
|
||||
command: which git
|
||||
register: git_check
|
||||
when: ansible_os_family == "Darwin"
|
||||
tags: [turboquant, deps]
|
||||
|
||||
- name: Clone llama.cpp TurboQuant fork
|
||||
git:
|
||||
repo: "https://github.com/TheTom/llama-cpp-turboquant.git"
|
||||
dest: "{{ turboquant_install_dir }}/llama.cpp"
|
||||
version: "feature/turboquant-kv-cache"
|
||||
force: yes
|
||||
when: ansible_os_family == "Darwin"
|
||||
tags: [turboquant, source]
|
||||
|
||||
- name: Build llama.cpp with Metal + TurboQuant
|
||||
shell: |
|
||||
cd {{ turboquant_install_dir }}/llama.cpp
|
||||
cmake -B build -DCMAKE_BUILD_TYPE=Release -DGGML_METAL=ON
|
||||
cmake --build build -j$(sysctl -n hw.ncpu)
|
||||
args:
|
||||
creates: "{{ turboquant_install_dir }}/llama.cpp/build/bin/llama-server"
|
||||
when: ansible_os_family == "Darwin"
|
||||
tags: [turboquant, build]
|
||||
|
||||
- name: Create models directory
|
||||
file:
|
||||
path: "{{ turboquant_install_dir }}/models"
|
||||
state: directory
|
||||
mode: '0755'
|
||||
when: ansible_os_family == "Darwin"
|
||||
tags: [turboquant, deploy]
|
||||
|
||||
- name: Deploy health check script
|
||||
copy:
|
||||
src: "../../health_check.sh"
|
||||
dest: "{{ turboquant_install_dir }}/health_check.sh"
|
||||
mode: '0755'
|
||||
when: ansible_os_family == "Darwin"
|
||||
tags: [turboquant, deploy]
|
||||
|
||||
- name: Print macOS manual start instructions
|
||||
debug:
|
||||
msg: |
|
||||
Mac deployment complete. To start the server manually:
|
||||
export TURBO_LAYER_ADAPTIVE={{ turboquant_layer_adaptive }}
|
||||
sudo -u {{ turboquant_user }} {{ turboquant_install_dir }}/llama.cpp/build/bin/llama-server \
|
||||
-m {{ turboquant_install_dir }}/models/{{ turboquant_model_file }} \
|
||||
--host {{ turboquant_host }} --port {{ turboquant_port }} \
|
||||
-c {{ turboquant_context }} -ctk {{ turboquant_kv_type }} -ctv {{ turboquant_kv_type }}
|
||||
when: ansible_os_family == "Darwin"
|
||||
tags: [turboquant, deploy]
|
||||
92
ansible/roles/turboquant-deploy/tasks/debian.yml
Normal file
92
ansible/roles/turboquant-deploy/tasks/debian.yml
Normal file
@@ -0,0 +1,92 @@
|
||||
---
|
||||
# Debian/Ubuntu deployment — installs llama.cpp with TurboQuant, uses systemd
|
||||
|
||||
- name: Update apt cache
|
||||
apt:
|
||||
update_cache: yes
|
||||
cache_valid_time: 3600
|
||||
tags: [turboquant, deps]
|
||||
|
||||
- name: Install build dependencies
|
||||
apt:
|
||||
name:
|
||||
- build-essential
|
||||
- cmake
|
||||
- git
|
||||
- curl
|
||||
- python3
|
||||
- python3-pip
|
||||
- python3-venv
|
||||
state: present
|
||||
tags: [turboquant, deps]
|
||||
|
||||
- name: Create turboquant user
|
||||
user:
|
||||
name: "{{ turboquant_user }}"
|
||||
system: yes
|
||||
shell: /usr/sbin/nologin
|
||||
create_home: no
|
||||
tags: [turboquant, prereq]
|
||||
|
||||
- name: Create install directory
|
||||
file:
|
||||
path: "{{ turboquant_install_dir }}"
|
||||
state: directory
|
||||
mode: '0755'
|
||||
owner: "{{ turboquant_user }}"
|
||||
group: "{{ turboquant_user }}"
|
||||
tags: [turboquant, prereq]
|
||||
|
||||
- name: Clone llama.cpp TurboQuant fork
|
||||
git:
|
||||
repo: "https://github.com/TheTom/llama-cpp-turboquant.git"
|
||||
dest: "{{ turboquant_install_dir }}/llama.cpp"
|
||||
version: "feature/turboquant-kv-cache"
|
||||
force: yes
|
||||
tags: [turboquant, source]
|
||||
|
||||
- name: Build llama.cpp with TurboQuant
|
||||
shell: |
|
||||
cd {{ turboquant_install_dir }}/llama.cpp
|
||||
cmake -B build -DCMAKE_BUILD_TYPE=Release
|
||||
cmake --build build -j$(nproc)
|
||||
args:
|
||||
creates: "{{ turboquant_install_dir }}/llama.cpp/build/bin/llama-server"
|
||||
tags: [turboquant, build]
|
||||
|
||||
- name: Create models directory
|
||||
file:
|
||||
path: "{{ turboquant_install_dir }}/models"
|
||||
state: directory
|
||||
mode: '0755'
|
||||
owner: "{{ turboquant_user }}"
|
||||
group: "{{ turboquant_user }}"
|
||||
tags: [turboquant, deploy]
|
||||
|
||||
- name: Deploy systemd service unit
|
||||
template:
|
||||
src: turboquant.service.j2
|
||||
dest: /etc/systemd/system/{{ turboquant_service_name }}.service
|
||||
mode: '0644'
|
||||
tags: [turboquant, service]
|
||||
|
||||
- name: Reload systemd daemon
|
||||
systemd:
|
||||
daemon_reload: yes
|
||||
tags: [turboquant, service]
|
||||
|
||||
- name: Enable and start TurboQuant service
|
||||
systemd:
|
||||
name: "{{ turboquant_service_name }}"
|
||||
state: started
|
||||
enabled: yes
|
||||
tags: [turboquant, service]
|
||||
|
||||
- name: Deploy health check script
|
||||
copy:
|
||||
src: "../../health_check.sh"
|
||||
dest: "{{ turboquant_install_dir }}/health_check.sh"
|
||||
mode: '0755'
|
||||
owner: "{{ turboquant_user }}"
|
||||
group: "{{ turboquant_user }}"
|
||||
tags: [turboquant, deploy]
|
||||
45
ansible/roles/turboquant-deploy/tasks/integration_test.yml
Normal file
45
ansible/roles/turboquant-deploy/tasks/integration_test.yml
Normal file
@@ -0,0 +1,45 @@
|
||||
---
|
||||
# Integration test — verify server responds to a simple query
|
||||
|
||||
- name: Wait for service to be ready (HTTP 200 on /v1/models)
|
||||
uri:
|
||||
url: "http://localhost:{{ turboquant_port }}/v1/models"
|
||||
method: GET
|
||||
status_code: 200
|
||||
register: svc_ready
|
||||
retries: 12
|
||||
delay: 5
|
||||
until: svc_ready.status == 200
|
||||
when: ansible_os_family != "Darwin" # skip on mac for now; service starts manually
|
||||
tags: [turboquant, healthcheck]
|
||||
|
||||
- name: Run integration test — simple query
|
||||
uri:
|
||||
url: "http://localhost:{{ turboquant_port }}/v1/chat/completions"
|
||||
method: POST
|
||||
body_format: json
|
||||
body:
|
||||
model: "{{ turboquant_model }}"
|
||||
messages:
|
||||
- role: "user"
|
||||
content: "Test: 2+2 equals what? Answer with only the number."
|
||||
max_tokens: 5
|
||||
temperature: 0.0
|
||||
return_content: yes
|
||||
register: completion
|
||||
when: ansible_os_family != "Darwin"
|
||||
tags: [turboquant, test]
|
||||
|
||||
- name: Verify response contains expected answer
|
||||
assert:
|
||||
that:
|
||||
- "'4' in (completion.content | default(''))"
|
||||
- completion.status == 200
|
||||
when: ansible_os_family != "Darwin"
|
||||
tags: [turboquant, test]
|
||||
|
||||
- name: Log integration result
|
||||
debug:
|
||||
msg: "Integration test passed — TurboQuant server responded correctly"
|
||||
when: ansible_os_family != "Darwin"
|
||||
tags: [turboquant, test]
|
||||
17
ansible/roles/turboquant-deploy/tasks/main.yml
Normal file
17
ansible/roles/turboquant-deploy/tasks/main.yml
Normal file
@@ -0,0 +1,17 @@
|
||||
---
|
||||
# Main entry point — common setup followed by OS-specific tasks
|
||||
|
||||
- name: Ensure install directory exists (common)
|
||||
file:
|
||||
path: "{{ turboquant_install_dir }}"
|
||||
state: directory
|
||||
mode: '0755'
|
||||
tags: [turboquant, prereq]
|
||||
|
||||
- name: Include OS-specific tasks
|
||||
include_tasks: "{{ ansible_os_family | lower }}.yml"
|
||||
tags: [turboquant, deploy]
|
||||
|
||||
- name: Run post-deploy integration tests
|
||||
include_tasks: integration_test.yml
|
||||
tags: [turboquant, test]
|
||||
@@ -0,0 +1,25 @@
|
||||
---
|
||||
# TurboQuant Server Configuration
|
||||
# Auto-generated by Ansible — node: {{ ansible_host | default('localhost') }}
|
||||
|
||||
server:
|
||||
host: "{{ turboquant_host }}"
|
||||
port: {{ turboquant_port }}
|
||||
model: "{{ turboquant_model }}"
|
||||
model_file: "{{ turboquant_model_file }}"
|
||||
base_url: "http://localhost:{{ turboquant_port }}/v1"
|
||||
|
||||
turboquant:
|
||||
enabled: true
|
||||
preset: "{{ node_preset }}"
|
||||
kv_type: "{{ turboquant_kv_type }}"
|
||||
layer_adaptive_mode: {{ turboquant_layer_adaptive }}
|
||||
|
||||
performance:
|
||||
max_context: {{ turboquant_context }}
|
||||
threads: {{ ansible_processor_vcpus | default(2) }}
|
||||
|
||||
deployment:
|
||||
install_dir: "{{ turboquant_install_dir }}"
|
||||
service_name: "{{ turboquant_service_name }}"
|
||||
node_hardware: "{{ node_hardware }}"
|
||||
@@ -0,0 +1,25 @@
|
||||
[Unit]
|
||||
Description=TurboQuant {{ turboquant_model }} Inference Server
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User={{ turboquant_user }}
|
||||
Group={{ turboquant_user }}
|
||||
WorkingDirectory={{ turboquant_install_dir }}
|
||||
Environment="TURBO_LAYER_ADAPTIVE={{ turboquant_layer_adaptive }}"
|
||||
ExecStart={{ turboquant_install_dir }}/llama-server \
|
||||
-m {{ turboquant_install_dir }}/models/{{ turboquant_model_file }} \
|
||||
--host {{ turboquant_host }} \
|
||||
--port {{ turboquant_port }} \
|
||||
-c {{ turboquant_context }} \
|
||||
-ctk {{ turboquant_kv_type }} -ctv {{ turboquant_kv_type }} \
|
||||
--threads {{ ansible_processor_vcpus | default(2) }}
|
||||
|
||||
Restart=always
|
||||
RestartSec=5
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -1,26 +1,17 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
TurboQuant Benchmarking Suite — Multi-Backend (Issue #29, #63)
|
||||
TurboQuant Benchmarking Suite — Multi-Backend (Issue #29)
|
||||
|
||||
Supports Ollama and llama-server backends with KV cache type configuration.
|
||||
Measures: TTFT, tokens/sec, latency, peak memory.
|
||||
|
||||
Perplexity (quality) is NOT measured here tokens/sec is a throughput proxy.
|
||||
For actual quality (logprob-based PPL), use --quality flag which delegates to
|
||||
llama-perplexity binary, since Ollama lacks logprob support (issue #63).
|
||||
|
||||
Usage:
|
||||
# Ollama (efficiency only)
|
||||
# Ollama (default)
|
||||
python3 benchmarks/run_benchmarks.py --backend ollama --model llama3
|
||||
|
||||
# llama-server with turbo4 KV + quality gate in one shot
|
||||
# llama-server with turbo4 KV
|
||||
python3 benchmarks/run_benchmarks.py --backend llama-server \
|
||||
--url http://localhost:11434 --model qwen3.5 --kv-type turbo4 --quality
|
||||
|
||||
# Quality gate only (separate tool)
|
||||
python3 benchmarks/run_perplexity.py --model ~/models/qwen3.5-27b.gguf \
|
||||
--llama-cpp ~/turboquant/llama.cpp-fork/build/bin/llama-perplexity \
|
||||
--corpus corpora/wiki.test.raw --context 2048
|
||||
--url http://localhost:11434 --model qwen3.5 --kv-type turbo4
|
||||
"""
|
||||
|
||||
import argparse
|
||||
@@ -117,7 +108,9 @@ def run_llama_server(prompt: str, model: str, url: str, kv_type: str = "f16",
|
||||
completion_tokens = usage.get("completion_tokens", 0)
|
||||
prompt_tokens = usage.get("prompt_tokens", 0)
|
||||
|
||||
# llama-server includes timing in x_* headers or we estimate
|
||||
if elapsed > 0 and completion_tokens > 0:
|
||||
# Subtract estimated prompt eval time (rough)
|
||||
tokens_per_sec = completion_tokens / max(elapsed - 0.1, 0.01)
|
||||
|
||||
return {
|
||||
@@ -135,10 +128,8 @@ def run_llama_server(prompt: str, model: str, url: str, kv_type: str = "f16",
|
||||
|
||||
|
||||
def run_benchmark_suite(backend: str, model: str, url: str, kv_type: str,
|
||||
prompts_file: str, output_file: str, timeout: int = 120,
|
||||
measure_quality: bool = False, quality_corpus: str = None,
|
||||
llama_cpp_bin: str = None, context: int = 2048, threads: int = 4):
|
||||
"""Run the full benchmark suite, optionally measuring perplexity in parallel."""
|
||||
prompts_file: str, output_file: str, timeout: int = 120):
|
||||
"""Run the full benchmark suite."""
|
||||
if not os.path.exists(prompts_file):
|
||||
print(f"ERROR: {prompts_file} not found")
|
||||
sys.exit(1)
|
||||
@@ -200,76 +191,15 @@ def run_benchmark_suite(backend: str, model: str, url: str, kv_type: str,
|
||||
}
|
||||
}
|
||||
|
||||
# Issue #63: Optional quality measurement via llama-perplexity (Ollama lacks logprob)
|
||||
if measure_quality:
|
||||
print("\n" + "="*60)
|
||||
print("Quality measurement requested — invoking llama-perplexity binary...")
|
||||
llama_cpp_bin = llama_cpp_bin or "llama.cpp-fork/build/bin/llama-perplexity"
|
||||
quality_corpus = quality_corpus or "corpora/wiki.test.raw"
|
||||
|
||||
if not os.path.exists(quality_corpus):
|
||||
print(f"WARNING: quality corpus not found: {quality_corpus}")
|
||||
suite["quality"] = {"perplexity": None, "passed": False, "error": f"Corpus missing: {quality_corpus}"}
|
||||
elif not os.path.exists(llama_cpp_bin):
|
||||
print(f"WARNING: llama-perplexity binary not found: {llama_cpp_bin}")
|
||||
suite["quality"] = {"perplexity": None, "passed": False, "error": f"Binary missing: {llama_cpp_bin}"}
|
||||
else:
|
||||
cmd = [
|
||||
llama_cpp_bin,
|
||||
"-m", model,
|
||||
"-f", quality_corpus,
|
||||
"-c", str(context),
|
||||
"-t", str(threads),
|
||||
"--kv-type", kv_type,
|
||||
]
|
||||
try:
|
||||
start = time.time()
|
||||
result = subprocess.run(cmd, capture_output=True, text=True, timeout=3600)
|
||||
elapsed = time.time() - start
|
||||
output = result.stdout + "\n" + result.stderr
|
||||
|
||||
ppl_match = re.search(r"perplexity[:\s]+(\d+\.?\d*)", output, re.IGNORECASE)
|
||||
ppl = float(ppl_match.group(1)) if ppl_match else None
|
||||
token_match = re.search(r"(\d+) tokens", output)
|
||||
tokens = int(token_match.group(1)) if token_match else None
|
||||
|
||||
ppl_result = {
|
||||
"kv_type": kv_type,
|
||||
"perplexity": ppl,
|
||||
"tokens": tokens,
|
||||
"elapsed_seconds": round(elapsed, 1),
|
||||
"exit_code": result.returncode,
|
||||
"passed": result.returncode == 0,
|
||||
"output_tail": output.strip()[-500:] if output else "",
|
||||
}
|
||||
suite["quality"] = ppl_result
|
||||
if ppl is not None:
|
||||
print(f" Perplexity ({kv_type}): {ppl:.4f}")
|
||||
else:
|
||||
print(f" Perplexity: FAILED — could not parse output")
|
||||
except subprocess.TimeoutExpired:
|
||||
suite["quality"] = {"perplexity": None, "passed": False, "error": "Timeout after 3600s"}
|
||||
print(" Perplexity: FAILED — timeout after 3600s")
|
||||
except Exception as e:
|
||||
suite["quality"] = {"perplexity": None, "passed": False, "error": str(e)}
|
||||
print(f" Perplexity: FAILED — {e}")
|
||||
print("="*60)
|
||||
|
||||
os.makedirs(os.path.dirname(output_file) or ".", exist_ok=True)
|
||||
with open(output_file, "w") as fh:
|
||||
json.dump(suite, fh, indent=2)
|
||||
with open(output_file, "w") as f:
|
||||
json.dump(suite, f, indent=2)
|
||||
|
||||
s = suite["summary"]
|
||||
print(f"\n{'='*60}")
|
||||
print(f"RESULTS: {s['success']}/{s['total']} success | "
|
||||
f"Avg {s['avg_tok_per_sec']:.1f} tok/s | "
|
||||
f"Avg {s['avg_latency_s']:.2f}s latency")
|
||||
if "quality" in suite:
|
||||
q = suite["quality"]
|
||||
if q.get("perplexity") is not None:
|
||||
print(f"Quality: PPL = {q['perplexity']:.4f}")
|
||||
else:
|
||||
print(f"Quality: not available — {q.get('error','unknown')}")
|
||||
print(f"{'='*60}")
|
||||
print(f"Saved to {output_file}")
|
||||
|
||||
@@ -277,45 +207,20 @@ def run_benchmark_suite(backend: str, model: str, url: str, kv_type: str,
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="TurboQuant Benchmark Suite")
|
||||
parser.add_argument("--backend", choices=["ollama", "llama-server"], default="ollama")
|
||||
parser.add_argument("--model", required=True, help="Model name or path")
|
||||
parser.add_argument("--model", required=True, help="Model name")
|
||||
parser.add_argument("--url", default="http://localhost:11434", help="Backend URL")
|
||||
parser.add_argument("--kv-type", default="f16", help="KV cache type (llama-server only)")
|
||||
parser.add_argument("--prompts", default="benchmarks/prompts.json", help="Prompts file")
|
||||
parser.add_argument("--output", default=None, help="Output file (auto-generated if omitted)")
|
||||
parser.add_argument("--timeout", type=int, default=120, help="Per-prompt timeout (s)")
|
||||
|
||||
# Issue #63: Quality measurement (Ollama lacks logprob → use llama-perplexity binary)
|
||||
parser.add_argument("--quality", action="store_true", default=False,
|
||||
help="Also run quality measurement via llama-perplexity binary")
|
||||
parser.add_argument("--llama-cpp", default="llama.cpp-fork/build/bin/llama-perplexity",
|
||||
help="Path to llama-perplexity binary")
|
||||
parser.add_argument("--quality-corpus", default="corpora/wiki.test.raw",
|
||||
help="Test corpus for perplexity measurement")
|
||||
parser.add_argument("--context", type=int, default=2048,
|
||||
help="Context length for quality measurement")
|
||||
parser.add_argument("--threads", type=int, default=4,
|
||||
help="Thread count for quality measurement")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.output is None:
|
||||
ts = int(time.time())
|
||||
args.output = f"benchmarks/results_{args.backend}_{args.kv_type}_{ts}.json"
|
||||
|
||||
run_benchmark_suite(
|
||||
backend=args.backend,
|
||||
model=args.model,
|
||||
url=args.url,
|
||||
kv_type=args.kv_type,
|
||||
prompts_file=args.prompts,
|
||||
output_file=args.output,
|
||||
timeout=args.timeout,
|
||||
measure_quality=args.quality,
|
||||
quality_corpus=args.quality_corpus,
|
||||
llama_cpp_bin=args.llama_cpp,
|
||||
context=args.context,
|
||||
threads=args.threads,
|
||||
)
|
||||
run_benchmark_suite(args.backend, args.model, args.url, args.kv_type,
|
||||
args.prompts, args.output, args.timeout)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
TurboQuant Perplexity Quality Gate (Issues #21, #63)
|
||||
TurboQuant Perplexity Quality Gate (Issue #21)
|
||||
|
||||
Measures true perplexity via llama-perplexity binary (logprob-based).
|
||||
Ollama cannot provide perplexity due to missing logprob API (issue #63).
|
||||
Compares text generation quality between f16 KV and turbo4 KV cache
|
||||
configurations using llama.cpp's perplexity tool on the wikitext-2 corpus.
|
||||
|
||||
Usage:
|
||||
|
||||
Reference in New Issue
Block a user