Repository navigation
fix(kv-cache): audit KV phase policy & multi-turn prefix reuse metrics (#135, #137) - #138
Merged
Merged
Conversation
#135, #137) - Fix portable CPU KV-phase evaluation in phase_policy.rs: measure causal prefill (seq_q > 1) separately from single-token decode (seq_q = 1) with 3 untimed warmup runs + median of 5 timed repetitions (bench_portable_op_us). - Add explicit provenance/fidelity metadata to KvPhasePointMetrics: phase_aware_used_fp8, decode_speedup_is_native (true on CUDA, false on portable CPU where FP8 E4M3 dequantizes to F32), analytic_kv_bytes_ratio (2.0), measured_bf16_kv_alloc_bytes, measured_fp8_kv_plus_scale_bytes, and measured_kv_alloc_bytes_ratio (including scale tensors & 256B CUDA allocator rounding). - Extend CPU CI gate in tests/hybrid_prefix_and_kv_phase_eval.rs to contexts &[256, 512, 2048] so PhaseAware (min_fp8_decode_ctx=2048) exercises the active FP8 decode path and verifies cosine >= 0.999. - Upgrade evaluate_multiturn_hybrid_prefix_reuse with 1 full untimed warmup sequence + configurable repetitions (10 on CUDA, 3 on CPU gate), SummaryStats (median, mean, sample SD, 95% Student-t CI), and explicit is_synthetic_microbench = true tagging. Fixes #137 Addresses #135
This was referenced Nov 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary (
2026-11-22)Fixes #137
Addresses #135
Implements the measurement methodology, portable CPU active-FP8 coverage, and statistical confidence-interval fixes identified in the
v1.7.109evidence audits (#135, #137):hanzo-engine/src/kv_cache/phase_policy.rs):evaluate_single_kv_phase_point_portablesobf16_prefill_us,fp8_always_prefill_us, andphase_aware_prefill_ustime genuine causal prefill (seq_q = prefill_seq_len > 1with explicit causal masking) instead of copying single-token decode timings.bench_portable_op_uswith3untimed warmup passes + median of5timed repetitions (matching CUDA's warmed median methodology).decode_speedup_is_native: bool(trueon CUDA native FP8 E4M3 paged decode kernel;falseon portable CPU where FP8 E4M3 dequantizes to F32) so non-CUDA timing ratios are never conflated with native FP8 bandwidth speedup.hanzo-engine/tests/hybrid_prefix_and_kv_phase_eval.rs, Sci: CPU KV-phase gate never tests the FP8-active regime; CPU decode_speedup is a timing artifact #137):hybrid_prefix_and_kv_phase_cpu_gatecontext grid from&[256, 512]to&[256, 512, 2048](min_fp8_decode_ctx = 2048).phase_aware_used_fp8: booltoKvPhasePointMetricsand assertsphase_aware_used_fp8 == falsebelow2048andphase_aware_used_fp8 == trueatctx = 2048withfp8_decode_cosine_vs_f32 >= 0.999anddecode_speedup_is_native == false.analytic_kv_bytes_ratio: f64(2.0) frommeasured_bf16_kv_alloc_bytes: usize,measured_fp8_kv_plus_scale_bytes: usize, andmeasured_kv_alloc_bytes_ratio: f64(summing actual BF16 K/V tensor storage vs FP8 E4M3 K/V + per-layer K/V scale tensors including 256-byte CUDA allocator alignment across 36 layers).v1.7.109release notes and release(engine): hanzo-engine 1.7.109 (hanzo-ml 0.11.124, Bonsai-2 ternary/AFQ/DFlash2/GDN, Vulkan 27B fix, ReplayGDN, PhasePolicy, ENGINE_* env) #134 summary to explicitly label the2.0xKV memory figure as analytic tensor payload savings.repetitions: usizetoHybridEvalConfig(10default for CUDA benchmark runs;3in the fast CPU gate) and1full untimed multi-turn warmup pass before timed repetitions.SummaryStats(n,median,mean,std_dev,ci95_low,ci95_highusing exact two-sided 95% Student-$t$ critical values) and per-repetition sample vectors (cold_ms_samples,warm_ms_samples,cumulative_cold_ms_stats,cumulative_warm_ms_stats,cumulative_ttft_speedup_stats), plusis_synthetic_microbench: true.Verification (
2026-11-22,dgxNVIDIA GB10sm_121CUDA 13.4)1. CPU Gate (
cargo test -p hanzo-engine --test hybrid_prefix_and_kv_phase_eval&--lib kv_cache::phase_policy::tests)hybrid_prefix_and_kv_phase_cpu_gate ... ok(ctx = [256, 512, 2048],phase_aware_used_fp8 = trueat2048,fp8_decode_cosine_vs_f32 >= 0.999,decode_speedup_is_native = false)kv_cache::phase_policy::tests::kv_phase_policy_parsing_and_phase_selection ... okkv_cache::phase_policy::tests::cpu_hybrid_prefix_isolation_and_multiturn_parity ... ok2. 10-Repetition Warmed CUDA Evaluation on GB10 (
--release --features cuda)owner_hit = 80,cross_tenant = 0,cross_model = 0,cross_adapter = 0,boundary = 0,post_mutation_max_rel = 0.01warmup sequence +10timed sequences):median_cold = 2588.48 ms(95% CI [2446.54, 2816.26] ms),median_warm = 383.43 ms(95% CI [304.60, 429.54] ms),median_speedup = 6.73x(mean = 7.88x,SD = 3.52x,95% CI [5.36x, 10.40x]),gdn_state_max_rel = 0.0,conv_state_max_rel = 0.0.median_cold = 3026.50 ms(95% CI [2767.91, 3148.61] ms),median_warm = 385.40 ms(95% CI [320.11, 443.81] ms),median_speedup = 7.55x(mean = 8.13x,SD = 2.07x,95% CI [6.66x, 9.61x]),attn/gdn/conv max_rel <= 4.73e-6.head_dim in {64, 128, 256}xctx in {4096, 8192, 16384, 32768}, 36 layers):phase_aware_used_fp8 = true,decode_speedup_is_native = true,fp8_decode_cosine_vs_f32 in [0.999571, 0.999687].ctx = 32768, d = 128:analytic_kv_bytes_ratio = 2.0,measured_bf16_kv_alloc_bytes = 1,208,549,376 B,measured_fp8_kv_plus_scale_bytes = 604,275,264 B,measured_kv_alloc_bytes_ratio = 1.999998x,decode_speedup = 1.15x(1.75x-2.38xat4K-16K).