Support fp8 quantization for KV cache in Inference perf models#625
Open
devalshahamd wants to merge 5 commits into
Open
Support fp8 quantization for KV cache in Inference perf models#625devalshahamd wants to merge 5 commits into
devalshahamd wants to merge 5 commits into
Conversation
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
Adds first-class handling of KV-cache dtype to
InferenceAttentionso perf predictions are correct for the common BF16-Q / FP8-KV deployment, and adds a new perf model foraiter::paged_attention_v1.Motivation
Until now
InferenceAttention.bytes_funccharged every read/write at a singlebytes_per_element. So the bytes-moved estimate was ~2x too high for quantized KV cache. We also had no perf model at all for the leaf opaiter::paged_attention_v1.Changes
1.
InferenceAttentionbase — trackdtype_KVseparately fromdtype_Q(attention_perf_model_extensions.py)_parse_chunk_stats(event)so subclasses can reuse it without paying for the base's input-dims layout.bytes_func(...)now takes an optionalbytes_per_element_KV(defaults tobytes_per_element). Thec_sq/g_sqtokens (current chunk just produced this iteration in Q-dtype) are charged atbpe_Q; the cached remainderc_sk - c_sq/g_sk - g_sqis charged atbpe_KV. The four read/write terms are kept as separatectx_elems_q/ctx_elems_kv/gen_elems_q/gen_elems_kvintermediates. Whendtype_KV == dtype_Qthe formula reduces exactly to the previous one (verified numerically), so every existing subclass keeps its current predictions.dtype_KVis resolved with explicit priority:perf_meta.KCache_dtype→Input type[1]→dtype_Q(see "tree_perf change" below for whyperf_metais needed).2. New subclass
aiter_paged_attention_v1Input Dims[2..4](positional signature is(out, workspace, query, key_cache, value_cache, …)).dtype_Q/dtype_KVdirectly fromInput type[2..3]— noperf_metalookup needed since the leaf op's K-cache tensor already carries the true FP8 dtype.get_compute_precision()to returndtype_KV. The kernel's MFMAs run on the KV-cache dtype, so the FP8 throughput peak — not the BF16 one — is the correct denominator forPct Roofline.3. Pseudo-op wiring
pseudo_ops_perf_utils.py:"aiter::paged_attention_v1"→ new class.generate_perf_report_pytorch_inference.py: added toapply_annotationname_filtersso the leaf inherits the user-annotation chunk stats.extensions/__init__.py: re-exported.4. New Trace2Tree extension
paged_attn_perf_meta.py(and auto-registration inpseudo_ops_utils.py)This is the part that makes the FP8 numbers actually flow through. Two parent-traversal helpers are added; both write to a brand-new top-level
event["perf_meta"]dict so existingevent["args"]consumers are untouched.mark_paged_attn_v1_parents: when the trace containsaiter::paged_attention_v1, walk up its ancestor chain and setperf_meta.exclude_perf_model = Trueon everycpu_op. Why:vllm::unified_attention_with_outputis normally the parent and also has a perf model. Without this flag,collect_unified_perf_eventsstops at the parent and never reaches the more granular leaf, so we'd lose the per-kernel breakdown for paged decode. Marking the parent excluded lets the leaf win.mark_rocm_paged_attn_kvcache_dtype: when the trace contains_rocm_C::paged_attention, copyInput type[5..6](K-cache, V-cache dtypes) onto everycpu_opancestor asperf_meta.KCache_dtype/perf_meta.VCache_dtype. Why:_rocm_C::paged_attentionitself has no perf model — its parentvllm::unified_attention_with_outputdoes. But the parent op only sees a BF16 staging tensor at itsInput type[1]; the true FP8 cache dtype is buried in the ROCm leaf. Propagating it up viaperf_metaletsInferenceAttention.get_param_detailspick it up and pass FP8 bytes/sec into the parent's perf model.Both extensions are early-return no-ops on traces that don't contain the respective leaf ops, so existing inference traces are unaffected.
5. One-line guard in
tree_perf.py::_has_perf_model