fkl.flash_attention: FA-2 forward with fused epilogue + compressed int8 KV cache - #6
Merged
morousg merged 1 commit intoJun 11, 2026
Conversation
…t8 KV cache
Python API over FusedKernelLibrary's new attention DPPs (FKL PR #256):
out = fkl.flash_attention(q, k, v, causal=True)
# FKL-only powers:
kc, vc = fkl.compress_kv(k), fkl.compress_kv(v) # 4x smaller cache
out = fkl.flash_attention(q, kc, vc, causal=True,
epilogue=[fkl.Mul(2.0), fkl.Add(0.5)])
- epilogue=[ops]: any fkl compute ops run IN-REGISTER on the attention
output inside the same kernel (codegen chains them with .then()); with
handmade FA that is a second kernel + DRAM round-trip. Epilogue VALUES
travel in params via the IOp's build() args -> changing them never
recompiles (chain shape is part of the cache signature).
- compress_kv(): GPU-side per-token int8 quantization (one fp32 scale per
token; standalone JIT-compiled kernel). flash_attention() dequantizes
in-register inside the fused kernel; the cache is never inflated.
- FlashAttention class for explicit shape control; flash_attention()
one-shot API with per-(head_dim, layout, epilogue-shape) kernel cache.
tests/test_flash_attention.py (8 checks, fp64 numpy oracle): dense
causal/ragged/cross, compression ratio >3.5x verified, int8-KV EXACT vs
dequantized oracle (1e-7), end-to-end quant error bounded (4e-3), fused
epilogue == host-applied (0 error), epilogue value changes without
recompile, decode step (seq_q=1 vs 256-token compressed cache).
Vendored headers refreshed from the feat/attention-dpps branch.
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
Python API for the new FKL attention DPPs (FusedKernelLibrary#256): FlashAttention-2 forward with the two FKL-only capabilities — fused epilogues and a compressed int8 KV cache.
.then()). Epilogue values travel through build() params — changing them never recompiles; only the chain shape is part of the kernel cache signature.FlashAttentionclass for explicit control +flash_attention()one-shot API with a per-(head_dim, layout, epilogue-shape) compiled-kernel cache.(batch*heads, seq, head_dim), fp32 accumulation, head_dim multiple of 32.Verification (8 checks, fp64 numpy oracle, RTX PRO 6000 sm_120)
Note: requires the headers from FusedKernelLibrary#256 (the vendoring script picks them up once that lands; until then
FKL_INCLUDEpointing at the feat/attention-dpps branch works).