Reland Cute-DSL FP4 dense GEMM (#23590)
Co-authored-by: b8zhong <b8zhong@users.noreply.github.com>
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
import argparse
|
||||
import csv
|
||||
import os
|
||||
import logging
|
||||
from functools import partial
|
||||
from typing import List, Tuple
|
||||
|
||||
import torch
|
||||
import triton
|
||||
from flashinfer import mm_fp4
|
||||
from flashinfer.autotuner import autotune
|
||||
from flashinfer.jit.core import logger as flashinfer_logger
|
||||
from flashinfer.testing import bench_gpu_time
|
||||
|
||||
flashinfer_logger.setLevel(logging.ERROR)
|
||||
|
||||
from sglang.jit_kernel.nvfp4 import cutlass_scaled_fp4_mm, scaled_fp4_quant
|
||||
from sglang.srt.utils import (
|
||||
get_device_capability,
|
||||
@@ -150,9 +154,9 @@ def _run_mm_fp4(a_fp4, b_fp4_T, a_sf, b_sf_T, alpha, dtype, res_fi, backend):
|
||||
x_log=False,
|
||||
line_arg="provider",
|
||||
line_vals=(
|
||||
["sglang_cutlass", "cutlass", "cudnn", "trtllm", "auto"]
|
||||
["sglang_cutlass", "cutlass", "cudnn", "trtllm", "cute-dsl", "auto"]
|
||||
if is_sm100_supported()
|
||||
else ["sglang_cutlass", "cutlass", "cudnn", "auto"]
|
||||
else ["sglang_cutlass", "cutlass", "cudnn", "cute-dsl", "auto"]
|
||||
),
|
||||
line_names=(
|
||||
[
|
||||
@@ -160,6 +164,7 @@ def _run_mm_fp4(a_fp4, b_fp4_T, a_sf, b_sf_T, alpha, dtype, res_fi, backend):
|
||||
"flashinfer cutlass fp4",
|
||||
"cudnn fp4",
|
||||
"trtllm fp4",
|
||||
"cute-dsl fp4",
|
||||
"auto fp4 (cudnn/cutlass)",
|
||||
]
|
||||
if is_sm100_supported()
|
||||
@@ -167,6 +172,7 @@ def _run_mm_fp4(a_fp4, b_fp4_T, a_sf, b_sf_T, alpha, dtype, res_fi, backend):
|
||||
"sglang cutlass fp4",
|
||||
"flashinfer cutlass fp4",
|
||||
"cudnn fp4",
|
||||
"cute-dsl fp4",
|
||||
"auto fp4",
|
||||
]
|
||||
),
|
||||
@@ -176,6 +182,7 @@ def _run_mm_fp4(a_fp4, b_fp4_T, a_sf, b_sf_T, alpha, dtype, res_fi, backend):
|
||||
("orange", "solid"),
|
||||
("blue", "solid"),
|
||||
("green", "solid"),
|
||||
("brown", "solid"),
|
||||
("purple", "solid"),
|
||||
]
|
||||
if is_sm100_supported()
|
||||
@@ -183,6 +190,7 @@ def _run_mm_fp4(a_fp4, b_fp4_T, a_sf, b_sf_T, alpha, dtype, res_fi, backend):
|
||||
("red", "solid"),
|
||||
("orange", "solid"),
|
||||
("blue", "solid"),
|
||||
("brown", "solid"),
|
||||
("purple", "solid"),
|
||||
]
|
||||
),
|
||||
@@ -224,6 +232,17 @@ def benchmark(batch_size, provider, N, K, dtype, correctness, csv_file):
|
||||
use_cuda_graph=True,
|
||||
)
|
||||
elif provider == "cutlass":
|
||||
with autotune():
|
||||
_run_mm_fp4(
|
||||
a_fp4,
|
||||
b_fp4_T,
|
||||
a_scale_interleaved,
|
||||
b_sf_T,
|
||||
alpha,
|
||||
dtype,
|
||||
res_fi,
|
||||
backend="cutlass",
|
||||
)
|
||||
times_ms = bench_gpu_time(
|
||||
fn=partial(_run_mm_fp4, backend="cutlass"),
|
||||
input_args=(
|
||||
@@ -238,6 +257,17 @@ def benchmark(batch_size, provider, N, K, dtype, correctness, csv_file):
|
||||
use_cuda_graph=True,
|
||||
)
|
||||
elif provider == "cudnn":
|
||||
with autotune():
|
||||
_run_mm_fp4(
|
||||
a_fp4,
|
||||
b_fp4_T,
|
||||
a_scale_interleaved,
|
||||
b_sf_T,
|
||||
alpha,
|
||||
dtype,
|
||||
res_fi,
|
||||
backend="cudnn",
|
||||
)
|
||||
times_ms = bench_gpu_time(
|
||||
fn=partial(_run_mm_fp4, backend="cudnn"),
|
||||
input_args=(
|
||||
@@ -254,12 +284,59 @@ def benchmark(batch_size, provider, N, K, dtype, correctness, csv_file):
|
||||
elif provider == "trtllm":
|
||||
a_sf_u8 = a_scale_interleaved.to(torch.uint8)
|
||||
b_sf_u8_T = b_sf_T.to(torch.uint8)
|
||||
with autotune():
|
||||
_run_mm_fp4(
|
||||
a_fp4,
|
||||
b_fp4_T,
|
||||
a_sf_u8,
|
||||
b_sf_u8_T,
|
||||
alpha,
|
||||
dtype,
|
||||
res_fi,
|
||||
backend="trtllm",
|
||||
)
|
||||
times_ms = bench_gpu_time(
|
||||
fn=partial(_run_mm_fp4, backend="trtllm"),
|
||||
input_args=(a_fp4, b_fp4_T, a_sf_u8, b_sf_u8_T, alpha, dtype, res_fi),
|
||||
use_cuda_graph=True,
|
||||
)
|
||||
elif provider == "cute-dsl":
|
||||
with autotune():
|
||||
_run_mm_fp4(
|
||||
a_fp4,
|
||||
b_fp4_T,
|
||||
a_scale_interleaved,
|
||||
b_sf_T,
|
||||
alpha,
|
||||
dtype,
|
||||
res_fi,
|
||||
backend="cute-dsl",
|
||||
)
|
||||
times_ms = bench_gpu_time(
|
||||
fn=partial(_run_mm_fp4, backend="cute-dsl"),
|
||||
input_args=(
|
||||
a_fp4,
|
||||
b_fp4_T,
|
||||
a_scale_interleaved,
|
||||
b_sf_T,
|
||||
alpha,
|
||||
dtype,
|
||||
res_fi,
|
||||
),
|
||||
use_cuda_graph=True,
|
||||
)
|
||||
elif provider == "auto":
|
||||
with autotune():
|
||||
_run_mm_fp4(
|
||||
a_fp4,
|
||||
b_fp4_T,
|
||||
a_scale_interleaved,
|
||||
b_sf_T,
|
||||
alpha,
|
||||
dtype,
|
||||
res_fi,
|
||||
backend="auto",
|
||||
)
|
||||
times_ms = bench_gpu_time(
|
||||
fn=partial(_run_mm_fp4, backend="auto"),
|
||||
input_args=(
|
||||
|
||||
Reference in New Issue
Block a user