Fix examples and pytest, run ruff (#3230)
Mark inactive issues and pull requests / mark-inactive-30d (push) Has been cancelled
Mark inactive issues and pull requests / mark-inactive-90d (push) Has been cancelled

Co-authored-by: dePaul Miller <23461061+depaulmillz@users.noreply.github.com>
This commit is contained in:
dePaul Miller
2026-05-21 11:05:38 +08:00
committed by GitHub
co-authored by dePaul Miller
parent 982cb9e718
commit 546c3efa89
11 changed files with 342 additions and 159 deletions
+114 -52
View File
@@ -59,7 +59,7 @@ os.environ.setdefault("GROUPED_GEMM_FORCE_CUTE_COPY", "0")
import pytest
import cutlass
import cutlass.utils as utils
from hopper.grouped_gemm import run
from hopper.kernel.grouped_gemm.grouped_gemm import run
# ---------------------------------------------------------------------------
@@ -203,8 +203,8 @@ def _run_case(
[
pytest.param((128, 256), [(128, 256, 64, 1)], id="tile128x256"),
pytest.param((128, 128), [(128, 128, 64, 1)], id="tile128x128"),
pytest.param((128, 64), [(128, 64, 64, 1)], id="tile128x64"),
pytest.param((64, 64), [(64, 64, 64, 1)], id="tile64x64"),
pytest.param((128, 64), [(128, 64, 64, 1)], id="tile128x64"),
pytest.param((64, 64), [(64, 64, 64, 1)], id="tile64x64"),
],
)
def test_l0_tile_shapes(tile_shape_mn, problem_sizes_mnkl, tmap_mode):
@@ -222,15 +222,20 @@ def test_l0_tile_shapes(tile_shape_mn, problem_sizes_mnkl, tmap_mode):
@pytest.mark.parametrize(
"num_groups, problem_sizes_mnkl",
[
pytest.param(2, [(128, 256, 64, 1)] * 2, id="2g-uniform"),
pytest.param(4, [(128, 256, 64, 1), (64, 128, 64, 1),
(256, 128, 64, 1), (192, 256, 64, 1)], id="4g-mixed"),
pytest.param(8, [(128, 256, 64, 1)] * 8, id="8g-uniform"),
pytest.param(2, [(128, 256, 64, 1)] * 2, id="2g-uniform"),
pytest.param(
4,
[(128, 256, 64, 1), (64, 128, 64, 1), (256, 128, 64, 1), (192, 256, 64, 1)],
id="4g-mixed",
),
pytest.param(8, [(128, 256, 64, 1)] * 8, id="8g-uniform"),
],
)
def test_l0_group_counts(num_groups, problem_sizes_mnkl, tmap_mode):
"""Various group counts compile for tile (128,256) fp16."""
_run_compile(num_groups, problem_sizes_mnkl, (128, 256), tensormap_update_mode=tmap_mode)
_run_compile(
num_groups, problem_sizes_mnkl, (128, 256), tensormap_update_mode=tmap_mode
)
# ---------------------------------------------------------------------------
@@ -244,28 +249,43 @@ def test_l0_group_counts(num_groups, problem_sizes_mnkl, tmap_mode):
"a_dtype, b_dtype, c_dtype, acc_dtype, problem_sizes_mnkl",
[
# fp16 → fp16 output
pytest.param(F16, F16, F16, F32, [(128, 256, 64, 1)], id="fp16-fp16-fp16-fp32"),
pytest.param(F16, F16, F16, F32, [(128, 256, 64, 1)], id="fp16-fp16-fp16-fp32"),
# fp16 → fp32 output
pytest.param(F16, F16, F32, F32, [(128, 256, 64, 1)], id="fp16-fp16-fp32-fp32"),
pytest.param(F16, F16, F32, F32, [(128, 256, 64, 1)], id="fp16-fp16-fp32-fp32"),
# fp16 with fp16 accumulator
pytest.param(F16, F16, F16, F16, [(128, 256, 64, 1)], id="fp16-fp16-fp16-fp16"),
pytest.param(F16, F16, F16, F16, [(128, 256, 64, 1)], id="fp16-fp16-fp16-fp16"),
# fp8 E4M3 → fp16 output (K must be multiple of 16 for fp8 alignment)
pytest.param(F8E4, F8E4, F16, F32, [(128, 256, 128, 1)], id="fp8e4-fp8e4-fp16-fp32"),
pytest.param(
F8E4, F8E4, F16, F32, [(128, 256, 128, 1)], id="fp8e4-fp8e4-fp16-fp32"
),
# fp8 E5M2 → fp16 output
pytest.param(F8E5, F8E5, F16, F32, [(128, 256, 128, 1)], id="fp8e5-fp8e5-fp16-fp32"),
pytest.param(
F8E5, F8E5, F16, F32, [(128, 256, 128, 1)], id="fp8e5-fp8e5-fp16-fp32"
),
# mixed fp8: E4M3 × E5M2
pytest.param(F8E4, F8E5, F16, F32, [(128, 256, 128, 1)], id="fp8e4-fp8e5-fp16-fp32"),
pytest.param(
F8E4, F8E5, F16, F32, [(128, 256, 128, 1)], id="fp8e4-fp8e5-fp16-fp32"
),
# int8 → int32 output (K must be multiple of 16)
pytest.param(I8, I8, I32, I32, [(128, 256, 128, 1)], id="int8-int8-int32-int32"),
pytest.param(
I8, I8, I32, I32, [(128, 256, 128, 1)], id="int8-int8-int32-int32"
),
# uint8 → int32 output
pytest.param(U8, U8, I32, I32, [(128, 256, 128, 1)], id="uint8-uint8-int32-int32"),
pytest.param(
U8, U8, I32, I32, [(128, 256, 128, 1)], id="uint8-uint8-int32-int32"
),
],
)
def test_l0_dtypes(a_dtype, b_dtype, c_dtype, acc_dtype, problem_sizes_mnkl, tmap_mode):
"""Data type combinations compile for tile (128,256)."""
_run_compile(
1, problem_sizes_mnkl, (128, 256),
a_dtype=a_dtype, b_dtype=b_dtype, c_dtype=c_dtype, acc_dtype=acc_dtype,
1,
problem_sizes_mnkl,
(128, 256),
a_dtype=a_dtype,
b_dtype=b_dtype,
c_dtype=c_dtype,
acc_dtype=acc_dtype,
tensormap_update_mode=tmap_mode,
)
@@ -289,14 +309,22 @@ def test_l0_dtypes(a_dtype, b_dtype, c_dtype, acc_dtype, problem_sizes_mnkl, tma
# m-major C output (M must be multiple of 8)
pytest.param("k", "k", "m", [(128, 256, 64, 1)], (128, 256), id="akm-bkm-cmaj"),
# m-major A + n-major B
pytest.param("m", "n", "n", [(128, 128, 64, 1)], (128, 128), id="amaj-bnmaj-cn"),
pytest.param(
"m", "n", "n", [(128, 128, 64, 1)], (128, 128), id="amaj-bnmaj-cn"
),
],
)
def test_l0_major_modes(a_major, b_major, c_major, problem_sizes_mnkl, tile_shape_mn, tmap_mode):
def test_l0_major_modes(
a_major, b_major, c_major, problem_sizes_mnkl, tile_shape_mn, tmap_mode
):
"""Matrix major mode combinations compile."""
_run_compile(
1, problem_sizes_mnkl, tile_shape_mn,
a_major=a_major, b_major=b_major, c_major=c_major,
1,
problem_sizes_mnkl,
tile_shape_mn,
a_major=a_major,
b_major=b_major,
c_major=c_major,
tensormap_update_mode=tmap_mode,
)
@@ -321,10 +349,14 @@ def test_l0_major_modes(a_major, b_major, c_major, problem_sizes_mnkl, tile_shap
pytest.param((2, 2), [(256, 512, 64, 1)], (128, 256), id="cluster2x2"),
],
)
def test_l0_cluster_shapes(cluster_shape_mn, problem_sizes_mnkl, tile_shape_mn, tmap_mode):
def test_l0_cluster_shapes(
cluster_shape_mn, problem_sizes_mnkl, tile_shape_mn, tmap_mode
):
"""Cluster shapes including multicast paths compile."""
_run_compile(
1, problem_sizes_mnkl, tile_shape_mn,
1,
problem_sizes_mnkl,
tile_shape_mn,
cluster_shape_mn=cluster_shape_mn,
tensormap_update_mode=tmap_mode,
)
@@ -341,18 +373,20 @@ def test_l0_cluster_shapes(cluster_shape_mn, problem_sizes_mnkl, tile_shape_mn,
"num_groups, problem_sizes_mnkl",
[
# groups with very different shapes
pytest.param(4, [(64, 64, 64, 1),
(128, 128, 64, 1),
(256, 128, 64, 1),
(128, 256, 64, 1)], id="4g-all-tiles"),
pytest.param(
4,
[(64, 64, 64, 1), (128, 128, 64, 1), (256, 128, 64, 1), (128, 256, 64, 1)],
id="4g-all-tiles",
),
# tiny vs large
pytest.param(2, [(64, 64, 64, 1),
(512, 512, 64, 1)], id="2g-tiny-large"),
pytest.param(2, [(64, 64, 64, 1), (512, 512, 64, 1)], id="2g-tiny-large"),
],
)
def test_l0_mixed_problem_sizes(num_groups, problem_sizes_mnkl, tmap_mode):
"""Heterogeneous per-group problem sizes compile."""
_run_compile(num_groups, problem_sizes_mnkl, (128, 256), tensormap_update_mode=tmap_mode)
_run_compile(
num_groups, problem_sizes_mnkl, (128, 256), tensormap_update_mode=tmap_mode
)
# ---------------------------------------------------------------------------
@@ -386,13 +420,15 @@ def test_l1_fp16_4g_mixed(tmap_mode):
[
pytest.param((128, 256), [(128, 256, 64, 1)], id="tile128x256"),
pytest.param((128, 128), [(128, 128, 64, 1)], id="tile128x128"),
pytest.param((128, 64), [(128, 64, 64, 1)], id="tile128x64"),
pytest.param((64, 64), [(64, 64, 64, 1)], id="tile64x64"),
pytest.param((128, 64), [(128, 64, 64, 1)], id="tile128x64"),
pytest.param((64, 64), [(64, 64, 64, 1)], id="tile64x64"),
],
)
def test_l1_tile_shapes_fp16(tile_shape_mn, problem_sizes_mnkl, tmap_mode):
"""All tile shapes produce correct results."""
_run_correctness(1, problem_sizes_mnkl, tile_shape_mn, tensormap_update_mode=tmap_mode)
_run_correctness(
1, problem_sizes_mnkl, tile_shape_mn, tensormap_update_mode=tmap_mode
)
# ---------------------------------------------------------------------------
@@ -429,8 +465,11 @@ def test_l1_group_count_scaling(num_groups, tmap_mode):
def test_l1_fp16_c_fp32(tmap_mode):
"""fp16 inputs with fp32 output are numerically correct."""
_run_correctness(
1, [(128, 256, 64, 1)], (128, 256),
c_dtype=F32, acc_dtype=F32,
1,
[(128, 256, 64, 1)],
(128, 256),
c_dtype=F32,
acc_dtype=F32,
tensormap_update_mode=tmap_mode,
)
@@ -441,8 +480,13 @@ def test_l1_fp16_c_fp32(tmap_mode):
def test_l1_fp8_e4m3(tmap_mode):
"""fp8 E4M3FN inputs are numerically correct (K=128 for 16B alignment)."""
_run_correctness(
1, [(128, 256, 128, 1)], (128, 256),
a_dtype=F8E4, b_dtype=F8E4, c_dtype=F16, acc_dtype=F32,
1,
[(128, 256, 128, 1)],
(128, 256),
a_dtype=F8E4,
b_dtype=F8E4,
c_dtype=F16,
acc_dtype=F32,
tensormap_update_mode=tmap_mode,
tolerance=0.5,
)
@@ -454,8 +498,13 @@ def test_l1_fp8_e4m3(tmap_mode):
def test_l1_fp8_mixed(tmap_mode):
"""Mixed fp8 inputs (E4M3 × E5M2) are numerically correct."""
_run_correctness(
1, [(128, 256, 128, 1)], (128, 256),
a_dtype=F8E4, b_dtype=F8E5, c_dtype=F16, acc_dtype=F32,
1,
[(128, 256, 128, 1)],
(128, 256),
a_dtype=F8E4,
b_dtype=F8E5,
c_dtype=F16,
acc_dtype=F32,
tensormap_update_mode=tmap_mode,
tolerance=0.5,
)
@@ -467,8 +516,13 @@ def test_l1_fp8_mixed(tmap_mode):
def test_l1_int8(tmap_mode):
"""int8 inputs with int32 accumulator are correct."""
_run_correctness(
1, [(128, 256, 128, 1)], (128, 256),
a_dtype=I8, b_dtype=I8, c_dtype=I32, acc_dtype=I32,
1,
[(128, 256, 128, 1)],
(128, 256),
a_dtype=I8,
b_dtype=I8,
c_dtype=I32,
acc_dtype=I32,
tensormap_update_mode=tmap_mode,
tolerance=0,
)
@@ -485,7 +539,9 @@ def test_l1_int8(tmap_mode):
def test_l1_c_m_major(tmap_mode):
"""m-major C output is correct."""
_run_correctness(
1, [(128, 256, 64, 1)], (128, 256),
1,
[(128, 256, 64, 1)],
(128, 256),
c_major="m",
tensormap_update_mode=tmap_mode,
)
@@ -498,8 +554,12 @@ def test_l1_c_m_major(tmap_mode):
def test_l1_all_non_default_majors(tmap_mode):
"""m-major A, n-major B, m-major C together are correct."""
_run_correctness(
1, [(64, 64, 64, 1)], (128, 128),
a_major="m", b_major="n", c_major="m",
1,
[(64, 64, 64, 1)],
(128, 128),
a_major="m",
b_major="n",
c_major="m",
tensormap_update_mode=tmap_mode,
)
@@ -521,7 +581,9 @@ def test_l1_all_non_default_majors(tmap_mode):
def test_l1_cluster_shapes(cluster_shape_mn, problem_sizes_mnkl, tmap_mode):
"""Multicast cluster shapes produce correct results."""
_run_correctness(
1, problem_sizes_mnkl, (128, 256),
1,
problem_sizes_mnkl,
(128, 256),
cluster_shape_mn=cluster_shape_mn,
tensormap_update_mode=tmap_mode,
)
@@ -540,14 +602,14 @@ def test_l1_8g_mixed_sizes(tmap_mode):
_run_correctness(
8,
[
(128, 256, 64, 1),
(64, 128, 64, 1),
(256, 128, 64, 1),
(128, 256, 64, 1),
(64, 128, 64, 1),
(256, 128, 64, 1),
(128, 128, 128, 1),
(192, 256, 64, 1),
(64, 64, 64, 1),
(192, 256, 64, 1),
(64, 64, 64, 1),
(128, 256, 128, 1),
(256, 256, 64, 1),
(256, 256, 64, 1),
],
(128, 256),
tensormap_update_mode=tmap_mode,