feat(inference): ADR-064 Phase-0 decode slope measurement harness#184
Merged
Conversation
Add `scripts/bench_decode_slope.sh` that runs decode at multiple context lengths (64-1024), fits a linear model (per_tok_ms = slope*ctx + intercept), and outputs JSON with slope_ms, intercept_ms, r_squared, tok_per_sec_64. Add `make bench-decode` Makefile target for convenient invocation. Add debug-only runtime assertion in MetalKvCache::new verifying buffer sizes match expected f32 layout (will need updating when #154 migrates to f16). Implements #168 (decode slope harness) and #170 (KV layout assertion). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The ENVIRON[] lookup requires variables to be in the environment, not positional shell args. Prefix the awk invocation with the variable assignments so they appear in ENVIRON. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The model may hit EOS before generating the requested token count (Qwen3.5-0.8B caps at ~346 tokens). Previously used the requested count as the denominator, giving incorrect per-token times. Now extracts actual completion count from bench_decode_ab RESULT output. Also fixed macOS awk compatibility (no match() with capture groups). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Fixes from PR #184 review (round 1): 1. [Major] Input validation: reject contexts <= N1, reject duplicates, validate RUNS is positive integer, guard bc output, guard awk denom=0. Script now exits 1 with JSON error for all invalid inputs. 2. [Medium] KV assertion safety: skip when num_full_layers == 0, verify ALL K and V buffers (not just k_bufs[0]). 3. Use `set -euo pipefail` (was `set -uo pipefail`). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Owner
Author
Codex Review — Round 1Verdict: REQUEST CHANGES → Fixed (all findings addressed in commit 5085d21) Findings Addressed
VerificationReady for re-review. |
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
scripts/bench_decode_slope.sh— runs decode at multiple context lengths (64-1024), fits linear modelper_tok_ms = slope*ctx + intercept, outputs JSON with slope_ms, intercept_ms, r_squared, tok_per_sec_64make bench-decodeMakefile target for convenient invocationMetalKvCache::newverifying buffer sizes match expected f32 layout (gates feat(inference): wire f16 KV cache into default Metal decode path #154 f16 migration)Implements #168 (decode slope harness) and #170 (KV layout assertion).
Bench output (validated on M2 Max)
{"slope_ms":0.003771,"intercept_ms":6.1545,"r_squared":0.918216,"tok_per_sec_64":156.4,"n_points":3,"contexts":[64,128,256],"per_tok_ms":[6.4791,6.5125,7.1616]}Test plan
RUNS=3 CONTEXTS="64 256" make bench-decodeproduces valid JSON on stdoutcargo build --release --features "metal-gpu,f16" -p lattice-inferencesucceeds🤖 Generated with Claude Code