Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Misc][Kernel]: Add GPTQAllSpark Quantization #12931

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,22 @@ if(VLLM_GPU_LANG STREQUAL "CUDA")
" in CUDA target architectures")
endif()

# AllSpark kernels
cuda_archs_loose_intersection(ALLSPARK_ARCHS "8.0;8.6;8.7;8.9;9.0" "${CUDA_ARCHS}")
if (ALLSPARK_ARCHS)
set(ALLSPARK_SRCS
"csrc/quantization/gptq_allspark/allspark_reorder.cu"
"csrc/quantization/gptq_allspark/allspark_qgemm_a16w8.cu")
set_gencode_flags_for_srcs(
SRCS "${ALLSPARK_SRCS}"
CUDA_ARCHS "${ALLSPARK_ARCHS}")
list(APPEND VLLM_EXT_SRC "${ALLSPARK_SRCS}")
message(STATUS "Building AllSpark kernels for archs: ${ALLSPARK_ARCHS}")
else()
message(STATUS "Not building AllSpark kernels as no compatible archs found"
" in CUDA target architectures")
endif()

# The cutlass_scaled_mm kernels for Hopper (c3x, i.e. CUTLASS 3.x) require
# CUDA 12.0 or later (and only work on Hopper, 9.0a for now).
cuda_archs_loose_intersection(SCALED_MM_3X_ARCHS "9.0a" "${CUDA_ARCHS}")
Expand Down
49 changes: 46 additions & 3 deletions benchmarks/kernels/benchmark_marlin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
from vllm.model_executor.layers.quantization.utils.marlin_utils_test_24 import (
marlin_24_quantize)
from vllm.model_executor.layers.quantization.utils.quant_utils import (
gptq_pack, gptq_quantize_weights, sort_weights)
from vllm.scalar_type import ScalarType
gptq_pack, gptq_quantize_weights, quantize_weights, sort_weights)
from vllm.scalar_type import ScalarType, scalar_types
from vllm.utils import FlexibleArgumentParser

DEFAULT_MODELS = ["meta-llama/Llama-2-7b-hf/TP1"]
DEFAULT_BATCH_SIZES = [1, 16, 32, 64, 128, 256, 512]
DEFAULT_BATCH_SIZES = [1, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192]

ACT_ORDER_OPTS = [False, True]
K_FULL_OPTS = [False, True]
Expand Down Expand Up @@ -81,6 +81,27 @@
GPTQ_MARLIN_24_MAX_PARALLEL)
marlin_zp = torch.zeros_like(marlin_s, dtype=torch.int)

# AllSpark A16W8 quant
as_supported_case = (quant_type == scalar_types.uint8b128
and group_size == -1 and act_order == False

Check failure on line 86 in benchmarks/kernels/benchmark_marlin.py

View workflow job for this annotation

GitHub Actions / pre-commit

Ruff (E712)

benchmarks/kernels/benchmark_marlin.py:86:51: E712 Avoid equality comparisons to `False`; use `if not act_order:` for false checks
and is_k_full == True)

Check failure on line 87 in benchmarks/kernels/benchmark_marlin.py

View workflow job for this annotation

GitHub Actions / pre-commit

Ruff (E712)

benchmarks/kernels/benchmark_marlin.py:87:30: E712 Avoid equality comparisons to `True`; use `if is_k_full:` for truth checks
if as_supported_case:
properties = torch.cuda.get_device_properties(b.device.index)
sm_count = properties.multi_processor_count
sm_version = properties.major * 10 + properties.minor

supported_arch = (sm_version >= 80 and sm_version < 90)
as_supported_case = as_supported_case and supported_arch
if supported_arch:
has_zp = False
w_ref, qw, s, zp = quantize_weights(b, scalar_types.uint8b128,
group_size, has_zp)
qw = qw.to(torch.uint8)

qw_reorder, s_reorder, zp_reorder = ops.gptq_allspark_rearrange_weight(

Check failure on line 101 in benchmarks/kernels/benchmark_marlin.py

View workflow job for this annotation

GitHub Actions / pre-commit

Ruff (E501)

benchmarks/kernels/benchmark_marlin.py:101:81: E501 Line too long (83 > 80)
qw, s, zp, has_zp)
CUBLAS_M_THRESHOLD = 1024

globals = {
# Gen params
"quant_type": quant_type,
Expand Down Expand Up @@ -109,10 +130,21 @@
# GPTQ params
"q_w_gptq": q_w_gptq,
"repack_sort_indices": repack_sort_indices,
# AllSpark A16W8 params
"qw_reorder": qw_reorder if as_supported_case else None,
"s_reorder": s_reorder if as_supported_case else None,
"zp_reorder": zp_reorder if as_supported_case else None,
"sm_count": sm_count if as_supported_case else None,
"sm_version": sm_version if as_supported_case else None,
"CUBLAS_M_THRESHOLD":
CUBLAS_M_THRESHOLD if as_supported_case else None,
"weight_name_pattern":
f'model.layers.k{size_k}.m{size_m}.n{size_n}.qweight',
# Kernels
"gptq_marlin_gemm": ops.gptq_marlin_gemm,
"gptq_marlin_24_gemm": ops.gptq_marlin_24_gemm,
"gptq_marlin_repack": ops.gptq_marlin_repack,
"allspark_a16w8_gemm": ops.allspark_a16w8_gemm,
}

min_run_time = 1
Expand Down Expand Up @@ -172,6 +204,17 @@
description="gptq_marlin_repack",
).blocked_autorange(min_run_time=min_run_time))

if as_supported_case:
results.append(
benchmark.Timer(
stmt=
"output = allspark_a16w8_gemm(a, qw_reorder, s_reorder, zp_reorder, size_n, group_size, sm_count, sm_version, CUBLAS_M_THRESHOLD, False, True, weight_name_pattern)", # noqa: E501
globals=globals,
label=label,
sub_label=sub_label,
description="allspark_a16w8_gemm_fp32",
).blocked_autorange(min_run_time=min_run_time))


def main(args):
print("Benchmarking models:")
Expand Down
Loading