← Back to Pull requests

vxpu/kernels: fuse GQA decode attention (FlashDecoding / split-KV) on L4 #973

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 29, 2026 22:02 UTC
Author

vxpu/kernels: add fused GQA decode attention op and L4 Triton kernel

Define the vxpu::gqa_attention custom op, its SDPA reference body, and a
lowerable Triton CUDA FlashDecoding / split-KV kernel (gpu_triton, M <= 8)
for causal grouped-query attention over static KV caches.

Standard static-cache decode attention expands KV heads across each query
group, materializes a full [1, 1, M, S_max] causal mask, and scans the
entire static cache length even when only a short prefix is populated.
The gpu_triton variant packs query heads within each KV group together
with decode tokens (M <= 8) so each KV tile loads once per KV head. It
reads cache_position on the GPU with zero host synchronization, skips
inactive KV cache tail slots, and uses balanced FlashDecoding split-KV
stages across a static grid so torch.export, AOTInductor, and CUDA graph
capture work without dynamic allocations.

Measured on NVIDIA L4 (driver 580.178.04, 23034 MiB, CUDA 13.0,
PyTorch 2.14.1+cu130, Triton 3.8.0; vxpu::read 268.4 MB in 1048.6 us,
254.8 GB/s measured vs 300 GB/s nominal):

Eager kernel-check lines on NVIDIA L4:

kernel-check vxpu::read gpu_triton 268435456 bit-identical dev=0.0e+00 PASS bytes=268.4MB us=1048.6 floor_us=894.8 fraction=0.85 floor=nominal card="NVIDIA L4" timing=warm
kernel-check vxpu::gqa_attention reference 1x1 hq=32 hkv=4 d=128 kv=64 bit-identical dev=0.0e+00 PASS bytes=0.1MB us=285.7 floor_us=0.5 fraction=0.00 floor=nominal card="NVIDIA L4" timing=warm
kernel-check vxpu::gqa_attention gpu_triton 1x1 hq=32 hkv=4 d=128 kv=64 rounding dev=4.8e-03 PASS bytes=0.1MB us=91.1 floor_us=0.5 fraction=0.01 floor=nominal card="NVIDIA L4" timing=warm
kernel-check vxpu::gqa_attention reference 1x1 hq=32 hkv=4 d=128 kv=512 bit-identical dev=0.0e+00 PASS bytes=1.1MB us=180.2 floor_us=3.5 fraction=0.02 floor=nominal card="NVIDIA L4" timing=warm
kernel-check vxpu::gqa_attention gpu_triton 1x1 hq=32 hkv=4 d=128 kv=512 rounding dev=5.7e-03 PASS bytes=1.1MB us=161.8 floor_us=3.5 fraction=0.02 floor=nominal card="NVIDIA L4" timing=warm
kernel-check vxpu::gqa_attention reference 1x1 hq=32 hkv=4 d=128 kv=2048 bit-identical dev=0.0e+00 PASS bytes=4.2MB us=245.8 floor_us=14.0 fraction=0.06 floor=nominal card="NVIDIA L4" timing=warm
kernel-check vxpu::gqa_attention gpu_triton 1x1 hq=32 hkv=4 d=128 kv=2048 rounding dev=6.0e-03 PASS bytes=4.2MB us=156.7 floor_us=14.0 fraction=0.09 floor=nominal card="NVIDIA L4" timing=warm
kernel-check vxpu::gqa_attention reference 1x4 hq=32 hkv=4 d=128 kv=64 bit-identical dev=0.0e+00 PASS bytes=0.2MB us=178.2 floor_us=0.7 fraction=0.00 floor=nominal card="NVIDIA L4" timing=warm
kernel-check vxpu::gqa_attention gpu_triton 1x4 hq=32 hkv=4 d=128 kv=64 rounding dev=4.6e-03 PASS bytes=0.2MB us=108.5 floor_us=0.7 fraction=0.01 floor=nominal card="NVIDIA L4" timing=warm
kernel-check vxpu::gqa_attention reference 1x4 hq=32 hkv=4 d=128 kv=512 bit-identical dev=0.0e+00 PASS bytes=1.1MB us=177.2 floor_us=3.7 fraction=0.02 floor=nominal card="NVIDIA L4" timing=warm
kernel-check vxpu::gqa_attention gpu_triton 1x4 hq=32 hkv=4 d=128 kv=512 rounding dev=6.1e-03 PASS bytes=1.1MB us=158.7 floor_us=3.7 fraction=0.02 floor=nominal card="NVIDIA L4" timing=warm
kernel-check vxpu::gqa_attention reference 1x4 hq=32 hkv=4 d=128 kv=2048 bit-identical dev=0.0e+00 PASS bytes=4.3MB us=238.6 floor_us=14.2 fraction=0.06 floor=nominal card="NVIDIA L4" timing=warm
kernel-check vxpu::gqa_attention gpu_triton 1x4 hq=32 hkv=4 d=128 kv=2048 rounding dev=6.7e-03 PASS bytes=4.3MB us=156.7 floor_us=14.2 fraction=0.09 floor=nominal card="NVIDIA L4" timing=warm

CUDA-graph captured microbenchmark on NVIDIA L4 (Hq=32, Hkv=4, D=128,
bf16, p20 per call; cold-L2 streams across distinct layer KV caches
exceeding L4's 48 MB L2):

1x1 kv=64          : ref= 13.46 us  tri= 2.86 us  ( 4.7x, 17.2% nom / 20.2% meas floor)
1x1 kv=512         : ref= 33.73 us  tri= 5.99 us  ( 5.6x, 59.2% nom / 69.7% meas floor)
1x1 kv=2048        : ref=104.45 us  tri=20.43 us  ( 5.1x, 68.7% nom / 80.9% meas floor)
1x1 kv=8192        : ref=383.10 us  tri=68.61 us  ( 5.6x, 81.6% nom / 96.1% meas floor)
1x1 kv=2048 pos=64 : ref=104.69 us  tri= 4.39 us  (23.9x, active=0.15 MB)
1x1 kv=2048 pos=512: ref=104.84 us  tri= 4.92 us  (21.3x, 72.1% nom / 84.9% meas floor)
1x4 kv=64          : ref= 13.93 us  tri= 3.54 us  ( 3.9x, 18.5% nom / 21.8% meas floor)
1x4 kv=512         : ref= 34.75 us  tri= 8.11 us  ( 4.3x, 45.8% nom / 53.9% meas floor)
1x4 kv=2048        : ref=105.96 us  tri=21.55 us  ( 4.9x, 65.9% nom / 77.6% meas floor)
1x4 kv=8192        : ref=388.35 us  tri=70.02 us  ( 5.5x, 80.2% nom / 94.4% meas floor)
1x4 kv=2048 pos=64 : ref=106.01 us  tri= 5.02 us  (21.1x, active=0.20 MB)
1x4 kv=2048 pos=512: ref=106.01 us  tri= 6.44 us  (16.5x, 57.7% nom / 67.9% meas floor)

vxpu/planner: wire vxpu::gqa_attention into Qwen3-MoE, planner, and L4 GPU tests

Dispatch Qwen3MoeAttention through vxpu::gqa_attention, remove the
per-step static causal_mask materialization from Qwen3MoeModel, add
vxpu::gqa_attention to the Go kernel catalog and segment shape extractor,
and verify end-to-end equivalence on NVIDIA L4.

1-layer Qwen3-30B-A3B INT4 (hidden=2048, Hq=32, Hkv=4, D=128,
moe_intermediate=768, 128 experts, top_k=8, max_cache_len=2048
,
int4_linear + int4_moe on gpu_triton, CUDA graph captured) on NVIDIA L4:

Greedy tokens (16 generated tokens): exact match (before == after)
M=1, pos=  64: 359.4 us -> 265.2 us (-94.2 us, 1.36x, -26.2%)
M=1, pos= 512: 360.4 us -> 268.3 us (-92.2 us, 1.34x, -25.6%)
M=1, pos=2048: 360.4 us -> 270.3 us (-90.1 us, 1.33x, -25.0%)
M=4, pos=  64: 448.5 us -> 353.3 us (-95.2 us, 1.27x, -21.2%)
M=4, pos= 512: 452.6 us -> 361.5 us (-91.1 us, 1.25x, -20.1%)
M=4, pos=2048: 450.6 us -> 360.4 us (-90.1 us, 1.25x, -20.0%)

Go-driven L4 GPU equivalence verified:

  • TestMultiShardInt4PlanAndExecute (awq_multishard, gptq_sym_multishard, awq_prestacked_multishard): PASS with exact token match

  • TestVerifyPlanEquivalence_GPU_GQAAttention: PASS (reference vs gpu_triton through Go planner → PlanFile → executor gRPC, exact greedy token match across both prompts)

  • TestVerifyPlanEquivalence_GPU_FullPlan: PASS (exact greedy token match)

  • python -m vxpu.hero_int4_moe --tiny: PASS (speedup=42.34x, tokens_match=True, explain planned=12 differing=0 unmatched=0)
  • Fixes #969

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: justinsb Review duration: 1232m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #973"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 27.7% · Safe to merge
    27.7%