Repository navigation
[FlyDSL] [Perf] Fuse Engram TP gate/residual and tune WKV GEMMs on gfx950 - #6994
junhaha666 wants to merge 6 commits into
Conversation
Add gfx950 K6144 native FP8 32x32 configurations for N10240 and N15360 used by TP4 and TP2 gate-only all-gather. Include tuned full N25600 baseline configurations at larger token counts through M16384.
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
DeepSeek-V4.1 Engram's sharded WKV can spend more time launching separate gate, all-gather and residual kernels than it saves in the GEMM at small M. Add a gfx950 FlyDSL kernel and HIP IPC workspace that combine normalized weighted dot, signed sqrt, sigmoid, gate exchange and the complete residual update in one launch. The companion ATOM integration selects it for 13..128 token rows.
FusedEngramPost(group)supports TP2/TP4/TP8 with BF16 H/KV and FP32 gate weights. It uses two sequence-tagged IPC message slots, bounds peer polling and exposes.check()for tests/debug outside graph capture. Initialize eagerly, warm each shape before capture, keep the workspace alive with its graphs, and invoke matching shapes in the same serialized order on all ranks. TP8 first combines half-Key statistics across paired ranks. The wrapper supports at most 128 rows; larger shapes use the companion composed path.The tuning CSV retains the existing sparse TP2/TP4 and full-WKV configurations:
Companion ATOM integration: ROCm/ATOM#2748
All ranks must hold complete H. ATOM consults mono's token-parallel policy before selecting the weight layout: TP2 mono keeps replicated H, while a deployment configured for TP4 mono token partitioning retains full WKV. The TP4 results below use replicated H.
Two weight-sharding routes, one stored WKV weight/scale pair
Mcounts all physical token rows, including graph padding. The diagrams show TP2/TP4 (P=2 or 4) with replicated input on every rank: embeddingX=[M,6144], residualH=[M,4,5120], both BF16. The FP32 gate weight is[4,5120].1. M <= 12: shard Keys and Value, then gather KV
flowchart TD X["X: BF16 [M,6144]"] --> Q["Input quantization: FP8 1x32"] W["Stored WKV: FP8 [20480/P+5120,6144]<br/>local Keys + rotated complete V"] --> PREFIX["Prefix view: [25600/P,6144]<br/>same weight and scale storage"] Q --> GEMM["Tuned FP8 GEMM"] PREFIX --> GEMM GEMM --> KV["Local KV: BF16 [M,25600/P]"] KV --> AG["aiter custom all-gather, dim=1"] AG --> FULL["Gathered KV: BF16 [M,25600]<br/>rank-grouped K0,V0,K1,V1,..."] FULL --> POST["Triton post: normalized weighted dot<br/>signed sqrt, sigmoid, residual update"] H["Replicated H: BF16 [M,4,5120]"] --> POST POST --> O["Complete H_new on every rank<br/>BF16 [M,4,5120]"]2. M > 12: shard Keys, compute complete V locally, exchange gates
flowchart TD X["X: BF16 [M,6144]"] --> Q["Input quantization: FP8 1x32"] W["Same stored WKV: FP8 [20480/P+5120,6144]"] --> GEMM["Tuned FP8 GEMM"] Q --> GEMM GEMM --> KV["Local KV: BF16 [M,20480/P+5120]<br/>Keys [M,4/P,5120], complete V [M,5120]"] KV --> SELECT{"Physical token rows M"} SELECT -->|13..128| FUSED["One aiter FlyDSL kernel<br/>local normalized dot, signed sqrt, sigmoid<br/>IPC exchange of FP32 gates, then H + gate * V<br/>logical gates [M,4/P] to [M,4]"] SELECT -->|greater than 128| GATE["Local gate kernel<br/>FP32 [M,4/P]"] GATE --> AG["aiter custom all-gather, dim=0<br/>physical [P*M,4/P], logical [P,M,4/P]"] AG --> RES["Residual kernel: H + gate * V<br/>read rotated V columns directly"] KV --> RES H["Replicated H: BF16 [M,4,5120]"] --> FUSED H --> GATE H --> RES FUSED --> O["Complete H_new on every rank<br/>BF16 [M,4,5120]"] RES --> OKey selection, V rotation, scale selection and preshuffling happen at load time. The short prefix is a view of the only stored weight/scale pair. Neither route adds a runtime V packing/copy or V all-gather in the complete-V path.
Full WKV is
[25600,6144], or 150 MiB per rank/layer, excluding scales. For TP2/TP4, the small-M KV contribution is51200/Pbytes per token/rank; the gate contribution is16/Pbytes. These are logical payload sizes, not measured link traffic.TP8 functionality is retained, but no dedicated TP8 GEMM tuning entries or TP8 performance claim are included. Each TP8 rank owns half a Key (
2560elements). The fused kernel first exchanges FP32sum(H^2),sum(K^2)and weighted-dot statistics withrank ^ 1, then exchanges the four completed gates within the same-parity ranks. The composed TP8 fallback gathers[M,3]statistics per rank before the residual update. TP8 GEMMs use the existing fallback selection after removing the experimental N=7680/3200 configurations.The unified upper fusion cutoff is 128. Boundary measurements found TP2's benefit ended at 128, while TP4 could extend to 256; the shared rule keeps dispatch simple and avoids the measured TP2 regression above 128. M<=12 keeps the KV-prefix route. If the FlyDSL path is unavailable, the composed post path remains in use.
Performance: full WKV, previous PR remeasured, and current dispatch
The following 2026-10-28 measurements replace the previous published tables. All three columns use the same AITER graph/profiler method; the previous PR column is a fresh remeasurement, not its historical event-timed value. These are combined ATOM + aiter WKV results, not the isolated gain from GEMM tuning.
jun_atom2. TP2 used GPUs 4/5, then TP4 used GPUs 0-3 sequentially. Host KFD monitoring at 0.5-second intervals found no foreign GPU allocation during either run (351/415 samples).aiter.test_common.run_perftest(testGraph=True), five rounds and 129 calls per round; CUDA-event timing is disabled. Choose the slowest rank in each round, then the median round. Per-op values use the same selected rank/round as their total.EngramOp.forward: M<=12 KV gather, 13..128 fused post, M>128 composed gate/gather/residual. The relevant 157 TP2/TP4 tuning rows are byte-identical between previous and current, and actual GEMM configuration matches at every measured shape.100 * (reference - current) / reference; positive means less GPU time. Times below are microseconds.The fused interval M=13..128 reduces time versus the previous PR by 8.33%-16.50% at TP2 and 4.66%-14.62% at TP4. Outside that interval the route is unchanged; differences remain within +/-0.94% in this run and are not attributed to a new algorithmic improvement.
TP2
TP4
Per-op GPU times for the current dispatch (microseconds)
Gate/post is the full post-WKV kernel for the KV-gather route, and the local gate kernel for the composed route. The FlyDSL column includes gate computation, peer exchange and residual update. A zero means no separate kernel is launched. Rounding can affect the sum of displayed values.
Validation
test_wkv_tp.py,test_gate.py,test_import_boundary.py, mono dispatch and V4.1 compilation tests. These cover loading, single-weight storage, prefix dispatch, masks, fallbacks and choosing the mono-compatible layout before loading. Native TP8 projection checks also passed after removing the TP8 tuning entries.1.8203815e-5, maximum absolute difference0.015625, zero outliers beyond the per-element rtol=atol=0.01 criterion. An additional 7,680 full-baseline self-checks are excluded from that comparison count.1.53193e-5(TP2/4) and1.41677e-5(TP8); no IPC timeout flags. Kernel source is unchanged since those runs.git diff --checkpassed for the changed code. The tested production source hashes match the committed implementation.The aiter multi-GPU regression can be run on an idle gfx950 node with
torchrun --standalone --nproc_per_node=2 op_tests/multigpu_tests/test_flydsl_engram_post_wkv.py; use 4 or 8 processes for the other TP sizes.Source provenance
05efed0f180c3edae5455d0267048f506eefcffd, aiter6f5897e4ff44b13bbc6d18f9ecf835bacd58185c. The Engram layer/gate were loaded from those ATOM git objects; only the test-local gate import was redirected. Both versions use the same common linear/GEMM/communication backend.e26bcd28b0a213437aa6bf6d496fe2e90967f00b, aiter67a0f379dbabb32b2b379637e068d50ffd5c8497.7dc75b0672b81fd126ce235a65f6a97a4697bc8c34ebf9189e175d88db2ea9c7, byte-identical to the previous aiter PR head. Removing 14 experimental TP8 configurations does not alter any TP2/TP4 measurement above.