[bench] vit_attention: model-matching V stride + controllable cache-eviction (--flush-mib) - #1070
Open
parthash0804 wants to merge 2 commits into
Open
[bench] vit_attention: model-matching V stride + controllable cache-eviction (--flush-mib)#1070parthash0804 wants to merge 2 commits into
parthash0804 wants to merge 2 commits into
Conversation
added 2 commits
July 30, 2026 02:03
Add --v-stride-mult (default 3) so V is a non-contiguous slice of a packed (B,S,mult,H,D) tensor with token stride mult*H*D, matching a real fused-QKV projection (mult=1 restores the old contiguous layout). Add --no-flush to measure with a warm cache instead of do_bench's cold-cache L2 flush. Emit v_stride_mult / v_token_stride / flush in the JSON config. Co-authored-by: Cursor <cursoragent@cursor.com> Signed-off-by: Parth Ashwin Jain <parthash@amd.com>
Add --flush-mib N to model a controllable amount of cache eviction by zeroing an N-MiB device buffer before each timed rep (N=0 warm, N~LLC serving-like partial, N>=2x LLC cold), generalizing the binary --no-flush. Also emit flush_mode/flush_mib and v_contiguous in the JSON config. Co-authored-by: Cursor <cursoragent@cursor.com> Signed-off-by: Parth Ashwin Jain <parthash@amd.com>
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
Extends the ViT attention microbenchmark (
benchmarks/vit_attention/bench.py) so it can faithfully reproduce full-model serving conditions for the ViT-encoder attention path. Two knobs are added:--v-stride-mult N(default 3) — model the real operand memory layout.In serving, V is a non-contiguous slice of the fused QKV projection
(token stride =
N*H*D, i.e. 3072 for the real model), while Q/K are madecontiguous by the serving wrappers.
--v-stride-mult 3reproduces this;1restores the old fully-contiguous V.--flush-mib N— model a controllable amount of cache eviction betweentimed reps, generalizing the previous binary warm/cold behavior:
do_benchfull-cold L2 flush--no-flush(==--flush-mib 0) → fully warm (q/k/v stay resident)--flush-mib N→ zero an N-MiB device buffer before each rep;N ~ LLCmodels serving-like partial eviction,
N >= 2x LLCis fully coldWhy
The single-op microbench and the in-serving profiler were not measuring the same thing, which made per-call ViT attention latencies look inconsistent. Root-cause showed the gap is fully explained by measurable effects — dominant one being cache working-set state (
do_benchis fully cold; serving is only partially evicted between attention calls), plus the non-contiguousfused-QKV V operand layout. These flags let the microbench match serving:
--flush-mib 32(≈ LLC size) reproduces serving to ~1% across fp16 and AWQ.--v-stride-mult 3) + cold flush lands within a few % of serving.Changes
--v-stride-multbuilds V as a non-contiguous slice of a packed(B,S,mult,H,D)tensor (token stridemult*H*D);mult=1= contiguous._do_bench_flush(fn, warmup, rep, flush_mib)— do_bench-style event-timed loop that zeroes an N-MiB buffer before each rep (flush_mib=0= warm).--no-flushretained as an alias for--flush-mib 0.confignow reportsv_stride_mult,v_token_stride,v_contiguous,flush,flush_mode(cold/warm/flush_mib), andflush_mib.Results