Repository navigation
[Perf] mla: Use masked K concatenation for padded head counts - #47743
Conversation
|
@Fridge003 Ready for review. Could an authorized maintainer enable CI with The current red workflow results stopped at At head Focused CI coverage: This runs the existing regression cases together with the new model-dispatch coverage. The PR is independent of #47742 and #47744. |
BBuf
left a comment
There was a problem hiding this comment.
[BBuf Review Agent] LGTM. Please wait for the registered concat CUDA tests to pass.
|
/tag-and-rerun-ci |
|
@BBuf The registered concat CUDA suite has already passed in upstream CI for the current head H100 CI job: jit-kernel-unit-test-1-gpu-large (1) checked out merge commit There were no failures or skips. The log explicitly includes all 14 new model-helper cases, including repeated CUDA Graph replay and the FA3 FP8 output-dtype case, along with the existing JIT/AOT regressions. The job is green, so the concat validation requested in your review is complete. The overall Base result is red because CPU shard 16 hits the existing DCP fixture error ( Could you re-review for merge with this upstream test evidence? The production change is still the same dispatch guard removal; no new commit or performance claim has been added. |
|
[BBuf Review Agent] @Codoge The code is unchanged and the registered suite covers the affected dispatch, so I’m fine dropping the extra validation condition. |
…oject#47743) Co-authored-by: Jeff D. Chen <12482210+Codoge@users.noreply.github.com>
Motivation
Kimi-K3 has 12 local MLA heads at TP8.
_concat_and_cast_mha_kcurrently requires a power-of-two head count before calling the Triton helper, even though that helper already handles padded head counts. These shapes fall back to two separate tensor copies.Modifications
Remove the redundant head-count restriction at the shared model dispatch point. Reuse the existing masked concat kernel and keep the feature-dimension guards and the 128-head specialized path.
For FA3 with FP8 KV storage, these head counts now follow the same output-dtype rule as the existing power-of-two Triton path. Other covered backends retain the input dtype.
Accuracy Tests
Upstream
b146a8576de930cf3adc104e601feb2790cdf3f6plus this PR only, NVIDIA B30Z (B300), PyTorch 2.14.1+cu130 and Triton 3.8.0:python -m pytest test/registered/kernels/ops/attention/test_concat_mla.py -k model_mha_k_concat -q # 14 passed, 94 deselectedThe tests call the actual model helper and Triton implementation. Coverage includes BF16 / FP16, empty and 64K-token inputs, 12 / 24 heads, an 8-head control, strided inputs, and repeated CUDA Graph replay with changed inputs. Outputs match the reference exactly. The FA3 dtype case compares raw FP8 bytes for finite random inputs against the reference cast.
Full-model accuracy and serving throughput have not been rerun on this branch; the results below are isolated operator timings.
Upstream CUDA validation
The complete registered
test/registered/kernels/ops/attention/test_concat_mla.pypassed on the upstream H100 CI runner for head81955274f6363c91979dd12d05e2662621bc4346: 108 passed, 0 skipped, including all 14 new model-helper cases and the existing JIT/AOT regressions. Passing CI job.Speed Tests and Profiling
Isolated concat operator on one NVIDIA B30Z, 12 heads,
nope_dim=128,rope_dim=64, BF16 output and strided KV / latent views. Baseline is the exact two-copy fallback at the base commit; patched runs the model helper. Both allocate their output. Eager execution, no profiler and no CUDA Graph;triton.testing.do_bench, 25 ms warmup and 100 ms measurement, median CUDA-event latency, L2 flush per sample. Baseline / patched order alternates across five rounds.These are operator timings, not an end-to-end throughput result. No full-model speedup is inferred from the percentages.
Checklist
CI States
Latest PR Test (Base): ❌ Run #41299322000
Latest PR Test (Extra): ❌ Run #41299322057
Latest PR Test (AMD ROCm 10): ❌ Run #41299322005
Tip
Base CI only covers the core cases, and its workload may not exercise your change. Use
/rerun-testto run the tests your change touches, or copy this prompt for an agent: