← Back to Pull requests

perf(k3.1): fuse decode AttnRes mixes into the collectives on gfx950 #3493

Closed
unknown closed this pull request without merging on Nov 18, 2026 01:08 UTC
View on GitHub
unknown unknown commented on Nov 16, 2026 10:49 UTC
Author

Summary

Three changes to Kimi-K3.1 decode on gfx950, up to 32 rows. Each removes a launch or a wait between a layer's attention, its MoE and the next layer's input, and all keep the outputs bit-exact.

  • All-reduce + AttnRes epilogue. attnres_combine reduced the attention partial with a Lamport all-reduce and ran the row epilogue in a second launch. One Lamport two-shot now does both: seven programs per row exchange the row's column tiles, and one more waits for the gathered row and runs the epilogue.

  • Next mix in the MoE gather tail. From 5 to 32 rows, the next layer's attnres_combine read the MoE tail's output back to mix its attention input. The tail now gathers each row, writes it, and runs the single-term merge and out-norm in attnres_combine's order, so the next layer skips its combine. Layers whose tail declines the mix, or that run the fused AttnRes graph, are unchanged.

  • Self-sorted routing. Through 32 rows, the sorted routing launch's row programs place their routes in the block-aligned expert sort instead of handing them to a sorting program that reloads every route. Two arrival-mask buffers alternate between launches, so no launch waits to zero its masks.
  • Results

    Kernel times at Kimi K3.1 TP8 shapes, CUDA graph, µs per call:

    | Change | 8 rows | 16 rows | 32 rows |
    |---|---:|---:|---:|
    | All-reduce + AttnRes epilogue (8x MI350X) | 9.07 → 7.20 | 9.44 → 7.44 | 10.45 → 8.29 |
    | Next mix in the MoE gather tail (8x MI350X) | 14.66 → 11.69 | 14.83 → 12.25 | 15.40 → 13.16 |
    | Self-sorted routing, with the shared down (one gfx950 GPU) | 9.58 → 7.77 | 9.69 → 7.96 | 10.01 → 8.47 |

    InferenceX AgentX at concurrency 1 on 8x MI355X, each change against its parent, averaged over same-node pairs (each pair runs both builds for an hour on one node):

    | Change | Pairs | Throughput | Interactivity |
    |---|---:|---:|---:|
    | All-reduce + AttnRes epilogue | 2 | +0.6% | +1.1% |
    | Next mix in the MoE gather tail | 2 | +0.8% | +1.6% |
    | Self-sorted routing | 1 | +1.1% | +0.9% |

    Runs of one build agree within about 0.6% in interactivity.

    At concurrency 4 the next mix in the MoE gather tail raised interactivity by 2.8% and lowered throughput by 3.6% on average over two pairs, inside that concurrency's run-to-run throughput spread of up to 7%.

    Test Plan

    On gfx950:

  • Iris tests on 8 GPUs: test_iris_communication.py checks the fused two-shot against the Lamport all-reduce plus epilogue and the push one-shot, and test_iris_moe_gather_tail.py checks the tail's rows and mixed rows against the tail without a mix and attnres_combine, all bit for bit.

  • test_kimi3_sorted_routing_gfx950.py adds 8, 13 and 33 rows and checks that each launch leaves the next launch's arrival masks zeroed.

  • Kernel, Iris and K3.1 runtime suites on one MI355X node, including test_kimi_k3_attn_res.py for handing the mix to the tail. Ten FlashInfer sampling cases fail on main as well; FlashInfer has no ROCm kernels.

  • The AgentX runs above.

  • Not run on NVIDIA; these paths are gfx950 only, and the all-reduce and gather tail also need the Iris backend.
  • Diff: 390 lines (+292 / -98) across 4 files Reviewer: Yu-Zhewen Review duration: 2299m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 390 lines diff across 4 files
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    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.357
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #3493"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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: 43.1% (MEDIUM) · Higher = larger blast radius
    43.1%
    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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 17% · Safe to merge
    17%