[Perf][Qwen4Exp] Merge QSA QKVG and indexer QK projections (#59533)

Signed-off-by: Thien Tran <gau.nernst@yahoo.com.sg>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: namgyu-youn <namgyu.dev@gmail.com>
This commit is contained in:
Thien Tran
2026-10-05 07:03:29 +00:00
committed by GitHub
co-authored by Codex namgyu-youn
parent 92044241a0
commit 042ab0305c
6 changed files with 181 additions and 119 deletions
+12 -6
View File
@@ -713,8 +713,8 @@ def test_low_latency_table_capability_routing(
def test_qwen4_exp_hopper_plans_are_valid() -> None:
plans = qwen4_exp_gemm.QWEN4_EXP_SM90_GEMM_PLANS
assert len(plans) == 9
assert sum(map(len, plans.values())) == 31
assert len(plans) == 7
assert sum(map(len, plans.values())) == 24
assert (320, 10240) in plans
assert (10240, 320) not in plans
for (n, k), shape_plans in plans.items():
@@ -728,10 +728,11 @@ def test_qwen4_exp_hopper_plans_are_valid() -> None:
@pytest.mark.parametrize(
"capability,expected_plans",
[
((10, 3), qwen4_exp_gemm.QWEN4_EXP_GEMM_PLANS),
((10, 3), qwen4_exp_gemm.QWEN4_EXP_SM103_GEMM_PLANS),
((10, 0), qwen4_exp_gemm.QWEN4_EXP_SM100_GEMM_PLANS),
((9, 0), qwen4_exp_gemm.QWEN4_EXP_SM90_GEMM_PLANS),
((12, 1), qwen4_exp_gemm.QWEN4_EXP_SM121_GEMM_PLANS),
((12, 0), {}),
((8, 0), {}),
],
)
@@ -742,11 +743,16 @@ def test_qwen4_exp_gemm_capability_routing(
) -> None:
monkeypatch.setattr(
qwen4_exp_gemm.current_platform,
"is_device_capability",
lambda target: capability == target,
"get_device_capability",
lambda: capability,
)
assert qwen4_exp_gemm._gemm_plans() == expected_plans
assert (
qwen4_exp_gemm.QWEN4_EXP_GEMM_PLANS_BY_CAPABILITY.get(
qwen4_exp_gemm.current_platform.get_device_capability(), {}
)
== expected_plans
)
def test_installation_is_shape_specific_and_unquantized(
+8 -4
View File
@@ -74,13 +74,14 @@ def _make_main_inputs(num_tokens: int, fp8_cache: bool) -> dict:
slots = torch.randperm(num_blocks * MAIN_PAGE, device="cuda")[:num_tokens]
slots[-1] = -1
norm_weights = torch.randn(2, MAIN_D, dtype=torch.bfloat16, device="cuda") * 0.2
qkv_width = 2 * (MAIN_HQ + MAIN_HK) * MAIN_D
return dict(
main_qkv=torch.randn(
num_tokens,
2 * (MAIN_HQ + MAIN_HK) * MAIN_D,
qkv_width + (HQ + 1) * D,
dtype=torch.bfloat16,
device="cuda",
),
)[:, :qkv_width],
main_q_norm_weight=norm_weights[0],
main_k_norm_weight=norm_weights[1],
main_eps=EPS,
@@ -316,9 +317,12 @@ def test_qsa_fused_prepare_matches_unfused(
)
unfused_compressed = fused_compressed.clone()
# TP=4 QKVG width makes the indexer slice row-strided, as in the merged
# projection. The exact width is unimportant; the larger stride is tested.
main_qkvg_width = 3584
projected_qk = torch.randn(
num_tokens, (HQ + 1) * D, dtype=torch.bfloat16, device=device
)
num_tokens, main_qkvg_width + (HQ + 1) * D, dtype=torch.bfloat16, device=device
)[:, main_qkvg_width:]
q_weight = torch.randn(D, dtype=torch.bfloat16, device=device) * 0.2
k_weight = torch.randn(D, dtype=torch.bfloat16, device=device) * 0.2