[Kernel] Add KDA NVFP4 GEMM for Qwen3.x on SM120 (#36865)

Co-authored-by: Song Bian <biansonghz@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Xiaoyu Zhang
2026-09-02 08:16:54 +08:00
committed by GitHub
co-authored by Song Bian Cursor
parent 6d34a4d3ce
commit c593527f33
24 changed files with 2829 additions and 67 deletions
@@ -49,10 +49,15 @@ def _module_defines(module_path: str) -> set[str]:
Importing would pull in Triton / CuTe-DSL / FlyDSL, none of which are
installed on the CPU CI lane -- so this reads the source instead.
"""
path = _PACKAGE_DIR / (module_path.replace(".", "/") + ".py")
if not path.exists():
path = _PACKAGE_DIR / module_path.replace(".", "/") / "__init__.py"
assert path.exists(), f"{PACKAGE}.{module_path} does not exist"
if module_path.startswith("sglang."):
spec = importlib.util.find_spec(module_path)
assert spec is not None and spec.origin is not None, module_path
path = pathlib.Path(spec.origin)
else:
path = _PACKAGE_DIR / (module_path.replace(".", "/") + ".py")
if not path.exists():
path = _PACKAGE_DIR / module_path.replace(".", "/") / "__init__.py"
assert path.exists(), f"{PACKAGE}.{module_path} does not exist"
names: set[str] = set()
for node in ast.parse(path.read_text(encoding="utf-8")).body:
@@ -85,7 +90,12 @@ def _scan_root(root: str) -> tuple[frozenset[str], tuple[str, ...]]:
for path in root_dir.rglob("*.py"):
rel = path.relative_to(_REPO_ROOT).as_posix()
if rel.startswith("python/sglang/kernels/ops/diffusion/"):
if rel.startswith(
(
"python/sglang/kernels/ops/diffusion/",
"python/sglang/kernels/kda_kernels/",
)
):
continue
try:
source = path.read_text(encoding="utf-8")
@@ -43,6 +43,7 @@ EXPECTED = {
"diffusion.flux2_layernorm_modulate_fp8_quant": {"KDA"},
"diffusion.flux2_qkv_epilogue": {"KDA"},
"diffusion.flux2_token_cat_fp8": {"KDA"},
"gemm.qwen3x_nvfp4": {"KDA"},
}
_CPU = PlatformInfo(device_type="cpu")
@@ -120,6 +121,14 @@ def test_merged_diffusion_kda_provenance_backend(op, target_suffix):
assert spec.target.endswith(target_suffix)
def test_kda_backend_implementations_live_in_kda_home():
specs = [
spec for spec in K.registry.all_specs() if spec.backend is KernelBackend.KDA
]
assert specs
assert all(spec.target.startswith("sglang.kernels.kda_kernels.") for spec in specs)
def test_single_backend_resolves_without_backend():
assert (
K.select_kernel("kvcache.reshape_and_cache_flash").backend