Repository navigation
Description
name: "🟡 Test & Validate Phase 2 Features"
about: Validate Phase 2 LLM optimizations (Speculative Decoding, Continuous Batching)
title: "[P1] Test & Validate Phase 2 Features (Speculative Decoding, Continuous Batching)"
labels: ["priority: high", "type: testing", "component: llm", "phase-2"]
assignees: []
Priority
🟡 HIGH - P1 (After Phase 1 testing)
Overview
Phase 2 features are already implemented and provide the most significant performance improvements (5-10x). After Phase 1 validation, we need to test these advanced features.
Phase 2 Features:
- ✅ Speculative Decoding (2-3x speedup)
- ✅ Continuous Batching (8x throughput)
Combined Impact: 50-100x system improvement when used with Phase 1
Depends On
⚠️ Blocked by Issue Fix target_link_libraries indentation for OpenSSL dependencies #1 (Fix Compilation)⚠️ Blocked by Issue [WIP] Fix CMake alias target error by ensuring proper find_package and target_link_libraries #2 (Phase 1 Testing)
Test Plan
1. Speculative Decoding Testing
Functional Tests
- Draft model loads correctly
- Target model loads correctly
- Draft-target validation loop works
- Acceptance/rejection logic correct
- Automatic fallback on errors
- KV cache synchronization works
- Statistics tracking accurate
Performance Tests
# Test configuration
optimizations:
use_flash_attn: true # Phase 1
speculative_decoding:
enabled: true
draft_model_path: "/models/llama-2-1b-q4.gguf"
draft_n_gpu_layers: 16
speculative_tokens: 5
acceptance_threshold: 0.8
# Benchmark
Target Model: Mistral-7B-Instruct-Q4_K_M
Draft Model: Llama-2-1B-Q4_K_M
Prompt: "Write a detailed explanation of neural networks"
Iterations: 100Expected Results:
- 2-3x faster inference
- 60-70% acceptance rate
- Zero quality loss
- +1.4 GB VRAM overhead acceptable
Baseline (No Speculative):
- Tokens/sec: ~42.3 (or ~51.7 with Flash Attention)
- Latency (100 tokens): ~2400ms (or ~1900ms with Flash)
- VRAM: 4.5 GB (target model only)
Target (With Speculative):
- Tokens/sec: 97-127 (2.3x faster than Flash Attention baseline)
- Latency (100 tokens): ~900ms
- Acceptance rate: 65-72%
- VRAM: 5.9 GB (+1.4 GB for draft model)
Quality Validation
# Generate same prompt with/without speculative decoding
prompt = "Explain the theory of relativity"
response_normal = generate(prompt, speculative=False)
response_spec = generate(prompt, speculative=True)
# Outputs should be semantically equivalent
# (may differ slightly due to sampling, but quality equal)
assert semantic_similarity(response_normal, response_spec) > 0.85Statistics Validation
// Check speculative decoding statistics
auto stats = llama_wrapper->getSpeculativeStats();
assert(stats.has_value());
assert(stats->avg_acceptance_rate >= 0.60);
assert(stats->avg_acceptance_rate <= 0.75);
assert(stats->avg_speedup >= 2.0);
assert(stats->avg_speedup <= 3.0);2. Continuous Batching Testing
Functional Tests
- Batch scheduler initializes
- Request queue works (FIFO, Priority, SJF)
- Dynamic batch composition (add/remove mid-batch)
- Per-request KV cache management
- Request preemption for high-priority
- Chunked prefill for large prompts
- Statistics tracking accurate
- Proper cleanup on shutdown
Performance Tests
# Test configuration
optimizations:
use_flash_attn: true # Phase 1
continuous_batching:
enabled: true
max_batch_size: 32
max_concurrent_requests: 128
max_tokens_per_batch: 8192
scheduler_policy: "priority"
enable_preemption: true
enable_chunked_prefill: true
prefill_chunk_size: 512
# Benchmark: High-load scenario
Concurrent Requests: 32
Request Rate: 10 req/sec
Duration: 60 seconds
Model: Mistral-7B-Instruct-Q4_K_MExpected Results:
- 8x higher throughput
- 3-4x faster P50 latency
- 90%+ GPU utilization
- Handles 32-64 concurrent requests
Baseline (No Batching):
- Throughput: 12 req/sec
- P50 latency: 1650ms
- P95 latency: 2800ms
- GPU utilization: 45%
Target (With Batching):
- Throughput: 96-104 req/sec (8x improvement)
- P50 latency: 400-450ms (3.9x faster)
- P95 latency: 850ms
- GPU utilization: 90-95%
Load Testing
# Run load test
./scripts/load_test_continuous_batching.sh \
--concurrent 32 \
--duration 300 \
--request-rate 10
# Monitor metrics
watch -n 1 "curl -s localhost:8080/metrics | grep batch_scheduler"Scheduler Policy Testing
Test all three scheduler policies:
# Test 1: FIFO
scheduler_policy: "fifo"
# Expected: Fair ordering, simple
# Test 2: Priority
scheduler_policy: "priority"
# Expected: High-priority requests processed first
# Test 3: Shortest-Job-First
scheduler_policy: "sjf"
# Expected: Short requests complete quicklyValidation:
- FIFO: Requests processed in order
- Priority: High-priority requests < 500ms P95
- SJF: Short requests complete in < 200ms
Integration Testing
Phase 1 + Phase 2 Combined
Test all features together for maximum performance:
optimizations:
# Phase 1
use_flash_attn: true
use_kv_cache_reuse: true
# Phase 2
speculative_decoding:
enabled: true
draft_model_path: "/models/llama-2-1b-q4.gguf"
speculative_tokens: 5
continuous_batching:
enabled: true
max_batch_size: 32
scheduler_policy: "priority"
# Expected combined improvementExpected Results:
- Per-request: 2.76x faster (Flash + Speculative)
- First-token (RAG): 10-20x faster (KV-Cache Reuse)
- Throughput: 8x higher (Continuous Batching)
- Combined: 50-100x improvement 🚀
Stress Testing
Long-Running Stability
# Run for 24 hours
./scripts/stress_test_phase2.sh --duration 86400
# Monitor for:
# - Memory leaks
# - Performance degradation
# - Crash recoveryAcceptance:
- No memory leaks over 24 hours
- Performance stable (< 5% degradation)
- Zero crashes
- Graceful error handling
Edge Cases
- Draft model unavailable (fallback works)
- Batch queue overflow (rejects gracefully)
- Out of memory (recovers)
- Mixed request lengths (chunked prefill works)
- Priority inversion (preemption works)
Acceptance Criteria
Functional
- All features activate via config
- No crashes or errors
- Proper cleanup and resource management
- Statistics accurate
Performance
- Speculative Decoding: 2-3x speedup ✅
- Continuous Batching: 8x throughput ✅
- Combined with Phase 1: 50-100x ✅
- GPU utilization: >90% ✅
Quality
- Speculative: Zero quality loss
- Batching: No request starvation
- Stable under load
- Graceful degradation
Deliverables
- Test scripts in
scripts/test_phase2/ - Load testing scripts
- Benchmark results in
results/phase2_benchmarks.json - Performance report with graphs
- Stress test report (24h run)
- Production configuration guide
- Monitoring dashboard config (Grafana)
Estimated Effort
Time: 3-5 days
Complexity: High (complex features, load testing)
Dependencies: Issue #1, #2
Related Issues
- Depends on: Fix target_link_libraries indentation for OpenSSL dependencies #1 (Fix Compilation)
- Depends on: [WIP] Fix CMake alias target error by ensuring proper find_package and target_link_libraries #2 (Test Phase 1)
- Blocks: Production deployment of Phase 2
- Enables: 50-100x performance improvement
References
- Implementation: PR #XXX (Phase 2 Implementation)
- Docs:
docs/en/llm/SPECULATIVE_DECODING_IMPLEMENTATION.md - Docs:
docs/en/llm/CONTINUOUS_BATCHING_IMPLEMENTATION.md - Config:
config/llm_config.production.yaml
Success Metrics
| Feature | Baseline | Target | Actual | Status |
|---|---|---|---|---|
| Speculative Speedup | 51.7 tok/s | 119-155 tok/s | TBD | ⏳ |
| Speculative Accept Rate | N/A | 65-72% | TBD | ⏳ |
| Batch Throughput | 12 req/s | 96-104 req/s | TBD | ⏳ |
| Batch P50 Latency | 1650ms | 400-450ms | TBD | ⏳ |
| GPU Utilization | 45% | 90-95% | TBD | ⏳ |
| Combined Improvement | 1x | 50-100x | TBD | ⏳ |
Target: ALL metrics in expected range = ✅ Success
Notes
Phase 2 features provide the most significant performance gains (50-100x when combined with Phase 1). Successful validation of these features will make ThemisDB competitive with industry-leading LLM servers like vLLM.
Activity
resolve stubs #79, #201, #210, #225: postgres EXCLUDE parser, index_a…