94057c3d3e
PR Test (NPU) / check-changes (push) Has been cancelled
PR Test (NPU) / pr-gate (push) Has been cancelled
PR Test (NPU) / set-image-config (push) Has been cancelled
PR Test (NPU) / stage-b-test-1-npu-a2 (0) (push) Has been cancelled
PR Test (NPU) / stage-b-test-1-npu-a2 (1) (push) Has been cancelled
PR Test (NPU) / stage-b-test-2-npu-a2 (0) (push) Has been cancelled
PR Test (NPU) / stage-b-test-2-npu-a2 (1) (push) Has been cancelled
PR Test (NPU) / stage-b-test-4-npu-a3 (push) Has been cancelled
PR Test (NPU) / stage-b-test-16-npu-a3 (push) Has been cancelled
PR Test (NPU) / multimodal-gen-test-1-npu-a3 (push) Has been cancelled
PR Test (NPU) / multimodal-gen-test-2-npu-a3 (push) Has been cancelled
PR Test (Arm64) / pr-gate (push) Has been cancelled
PR Test (Arm64) / check-changes (push) Has been cancelled
PR Test (Arm64) / build-test (push) Has been cancelled
PR Test (sgl-router) / gate (push) Has been cancelled
PR Test (sgl-router) / tier-1 — lint (push) Has been cancelled
PR Test (sgl-router) / tier-2 — build + test (push) Has been cancelled
PR Test (sgl-router) / tier-3 — docker (placeholder) (push) Has been cancelled
PR Test (sgl-router) / tier-3 — k8s integration (push) Has been cancelled
PR Test (sgl-router) / tier-3 — e2e (push) Has been cancelled
PR Test (sgl-router) / finish (push) Has been cancelled
PR Test (NPU) / single-node-poc (map[name:qwen3_6_27b_w8a8_1p_in64k_out1k_50ms runner:linux-aarch64-a3-2 test_case:test/registered/ascend/performance/qwen3_6_27b/test_npu_qwen3_6_27b_w8a8_1p_in64k_out1k_50ms.py test_type:perf]) (push) Has been cancelled
PR Test (NPU) / pr-test-npu-finish (push) Has been cancelled
PR Test (Xeon) / pr-gate (push) Has been cancelled
PR Test (Xeon) / check-changes (push) Has been cancelled
PR Test (Xeon) / build-test (, xeon-gnr, base-b-test-cpu) (push) Has been cancelled
PR Test (XPU) / check-changes (push) Has been cancelled
PR Test (XPU) / pr-gate (push) Has been cancelled
PR Test (XPU) / stage-a-test-1-gpu-xpu (push) Has been cancelled
PR Test (XPU) / wait-for-stage-a (push) Has been cancelled
PR Test (XPU) / stage-b-test-1-gpu-xpu (push) Has been cancelled
PR Test (XPU) / finish (push) Has been cancelled
CI Model Inventory / build-inventory (push) Has been cancelled
Lint / lint (push) Has been cancelled
PR Benchmark (SMG Components) / Benchmark Compilation Check (push) Has been cancelled
PR Benchmark (SMG Components) / Benchmark - Manual Policy (push) Has been cancelled
PR Benchmark (SMG Components) / Benchmark - Request Processing (push) Has been cancelled
PR Benchmark (SMG Components) / Benchmark Summary (push) Has been cancelled
PR Test (SMG) / build-wheel (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on windows (x86_64 - auto) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on macos (x86_64 - auto) (push) Has been cancelled
PR Test (SMG) / python-unit-tests (push) Has been cancelled
PR Test (SMG) / unit-tests (push) Has been cancelled
PR Test (SMG) / benchmarks (push) Has been cancelled
PR Test (SMG) / chat-completions (push) Has been cancelled
PR Test (SMG) / chat-completions-4gpu (push) Has been cancelled
PR Test (SMG) / e2e (push) Has been cancelled
PR Test (SMG) / docker-build-test (push) Has been cancelled
PR Test (SMG) / k8s-integration (push) Has been cancelled
PR Test (SMG) / finish (push) Has been cancelled
PR Test (SMG) / summarize-benchmarks (push) Has been cancelled
Release SGLang Model Gateway Docker Image / publish (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on macos (aarch64 - auto) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on linux (aarch64 - auto) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on linux (x86_64 - auto) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on linux (aarch64 - musllinux_1_1) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on linux (x86_64 - musllinux_1_1) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / Build SDist (push) Has been cancelled
Release SGLang Model Gateway to PyPI / Upload to PyPI (push) Has been cancelled
Release SGLang Kernels / build-cu129-matrix (aarch64, 12.9, 3.10, arm-kernel-build-node) (push) Has been cancelled
Release SGLang Kernels / build-cu129-matrix (x86_64, 12.9, 3.10, x64-kernel-build-node) (push) Has been cancelled
Release SGLang Kernels / release-cu129 (push) Has been cancelled
Release SGLang Kernels / build-cu130-matrix (aarch64, 13.0, 3.10, arm-kernel-build-node) (push) Has been cancelled
Release SGLang Kernels / build-cu130-matrix (x86_64, 13.0, 3.10, x64-kernel-build-node) (push) Has been cancelled
Release SGLang Kernels / release-cu130 (push) Has been cancelled
Release SGLang Kernels / build-rocm-matrix (3.10, 700) (push) Has been cancelled
Release SGLang Kernels / build-rocm-matrix (3.10, 720) (push) Has been cancelled
Release SGLang Kernels / release-rocm700 (push) Has been cancelled
Release SGLang Kernels / release-rocm720 (push) Has been cancelled
Release SGLang Kernels / build-musa43 (43, 3.10) (push) Has been cancelled
Release SGLang Kernels / release-musa43 (push) Has been cancelled
171 lines
5.5 KiB
Python
171 lines
5.5 KiB
Python
# SPDX-License-Identifier: Apache-2.0
|
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
|
# Adapted from https://raw.githubusercontent.com/vllm-project/vllm/v0.5.5/vllm/model_executor/layers/quantization/__init__.py
|
|
from __future__ import annotations
|
|
|
|
import builtins
|
|
import inspect
|
|
from typing import TYPE_CHECKING, Dict, Optional, Type
|
|
|
|
import torch
|
|
|
|
|
|
# Define empty classes as placeholders when vllm is not available
|
|
class DummyConfig:
|
|
def override_quantization_method(self, *args, **kwargs):
|
|
return None
|
|
|
|
|
|
CompressedTensorsConfig = DummyConfig
|
|
|
|
from sglang.srt.layers.quantization.auto_round import AutoRoundConfig
|
|
from sglang.srt.layers.quantization.awq import AWQConfig, AWQCPUConfig, AWQMarlinConfig
|
|
from sglang.srt.layers.quantization.base_config import QuantizationConfig
|
|
from sglang.srt.layers.quantization.bitsandbytes import BitsAndBytesConfig
|
|
from sglang.srt.layers.quantization.blockwise_int8 import BlockInt8Config
|
|
from sglang.srt.layers.quantization.compressed_tensors.compressed_tensors import (
|
|
CompressedTensorsConfig,
|
|
)
|
|
from sglang.srt.layers.quantization.fp8 import Fp8Config
|
|
from sglang.srt.layers.quantization.fpgemm_fp8 import FBGEMMFp8Config
|
|
from sglang.srt.layers.quantization.gguf import GGUFConfig
|
|
from sglang.srt.layers.quantization.gptq import (
|
|
CPUGPTQConfig,
|
|
GPTQAscendConfig,
|
|
GPTQConfig,
|
|
GPTQMarlinConfig,
|
|
)
|
|
from sglang.srt.layers.quantization.mlx import MlxQuantizationConfig
|
|
from sglang.srt.layers.quantization.modelopt_quant import (
|
|
ModelOptFp4Config,
|
|
ModelOptFp8Config,
|
|
ModelOptMixedPrecisionConfig,
|
|
)
|
|
from sglang.srt.layers.quantization.modelslim.modelslim import ModelSlimConfig
|
|
from sglang.srt.layers.quantization.moe_wna16 import MoeWNA16Config
|
|
from sglang.srt.layers.quantization.mxfp4 import Mxfp4Config
|
|
from sglang.srt.layers.quantization.npu_mxfp4 import Mxfp4W4A8Config
|
|
from sglang.srt.layers.quantization.nvfp4_online import NvFp4OnlineConfig
|
|
from sglang.srt.layers.quantization.petit import PetitNvFp4Config
|
|
from sglang.srt.layers.quantization.qoq import QoQConfig
|
|
from sglang.srt.layers.quantization.quark.quark import QuarkConfig
|
|
from sglang.srt.layers.quantization.quark_int4fp8_moe import QuarkInt4Fp8Config
|
|
from sglang.srt.layers.quantization.w4afp8 import W4AFp8Config
|
|
from sglang.srt.layers.quantization.w8a8_fp8 import W8A8Fp8Config
|
|
from sglang.srt.layers.quantization.w8a8_int8 import W8A8Int8Config
|
|
from sglang.srt.platforms import current_platform
|
|
from sglang.srt.utils import (
|
|
cpu_has_amx_support,
|
|
is_cpu,
|
|
is_cuda,
|
|
is_hip,
|
|
is_mps,
|
|
is_npu,
|
|
mxfp_supported,
|
|
)
|
|
|
|
_is_mxfp_supported = mxfp_supported()
|
|
|
|
if TYPE_CHECKING:
|
|
from sglang.srt.layers.moe.topk import TopKOutput
|
|
|
|
# Base quantization methods
|
|
BASE_QUANTIZATION_METHODS: Dict[str, Type[QuantizationConfig]] = {
|
|
"fp8": Fp8Config,
|
|
"mxfp8": Fp8Config,
|
|
"blockwise_int8": BlockInt8Config,
|
|
"modelopt": ModelOptFp8Config, # Auto-detect, defaults to FP8
|
|
"modelopt_fp8": ModelOptFp8Config,
|
|
"modelopt_fp4": ModelOptFp4Config,
|
|
"nvfp4_online": NvFp4OnlineConfig,
|
|
"modelopt_mixed": ModelOptMixedPrecisionConfig,
|
|
"w8a8_int8": W8A8Int8Config,
|
|
"w8a8_fp8": W8A8Fp8Config,
|
|
"awq": AWQConfig,
|
|
"awq_marlin": AWQMarlinConfig,
|
|
"bitsandbytes": BitsAndBytesConfig,
|
|
"gguf": GGUFConfig,
|
|
"gptq": GPTQConfig,
|
|
"gptq_marlin": GPTQMarlinConfig,
|
|
"moe_wna16": MoeWNA16Config,
|
|
"compressed-tensors": CompressedTensorsConfig,
|
|
"qoq": QoQConfig,
|
|
"w4afp8": W4AFp8Config,
|
|
"petit_nvfp4": PetitNvFp4Config,
|
|
"fbgemm_fp8": FBGEMMFp8Config,
|
|
"quark": QuarkConfig,
|
|
"quark_mxfp4": QuarkConfig,
|
|
"auto-round": AutoRoundConfig,
|
|
"auto-round-int8": W8A8Int8Config,
|
|
"modelslim": ModelSlimConfig,
|
|
"quark_int4fp8_moe": QuarkInt4Fp8Config,
|
|
"mxfp_w4a8": Mxfp4W4A8Config,
|
|
}
|
|
|
|
|
|
if is_cpu() or is_cuda() or (_is_mxfp_supported and is_hip()):
|
|
BASE_QUANTIZATION_METHODS.update(
|
|
{
|
|
"mxfp4": Mxfp4Config,
|
|
}
|
|
)
|
|
|
|
|
|
if is_npu():
|
|
BASE_QUANTIZATION_METHODS.update(
|
|
{
|
|
"gptq": GPTQAscendConfig,
|
|
}
|
|
)
|
|
|
|
|
|
if is_mps():
|
|
BASE_QUANTIZATION_METHODS.update(
|
|
{
|
|
"mlx_q4": MlxQuantizationConfig,
|
|
"mlx_q8": MlxQuantizationConfig,
|
|
}
|
|
)
|
|
|
|
# subset of above quant methods, supported on CPU
|
|
CPU_QUANTIZATION_METHODS = {
|
|
"fp8": Fp8Config,
|
|
"w8a8_int8": W8A8Int8Config,
|
|
"compressed-tensors": CompressedTensorsConfig,
|
|
"awq": AWQCPUConfig,
|
|
"gptq": CPUGPTQConfig,
|
|
"mxfp4": Mxfp4Config,
|
|
}
|
|
|
|
QUANTIZATION_METHODS = {**BASE_QUANTIZATION_METHODS}
|
|
|
|
|
|
def get_quantization_config(quantization: str) -> Type[QuantizationConfig]:
|
|
if quantization not in QUANTIZATION_METHODS:
|
|
raise ValueError(
|
|
f"Invalid quantization method: {quantization}. "
|
|
f"Available methods: {list(QUANTIZATION_METHODS.keys())}"
|
|
)
|
|
from sglang.srt.utils import is_cpu
|
|
|
|
if is_cpu() and cpu_has_amx_support():
|
|
if quantization not in CPU_QUANTIZATION_METHODS:
|
|
raise ValueError(
|
|
f"Invalid quantization method on CPU: {quantization}. "
|
|
f"Available methods on CPU: {list(QUANTIZATION_METHODS.keys())}"
|
|
)
|
|
else:
|
|
return CPU_QUANTIZATION_METHODS[quantization]
|
|
|
|
if current_platform.is_out_of_tree():
|
|
config = current_platform.get_quantization_config(quantization)
|
|
|
|
# If the platform has a quantization config, use it else use the default
|
|
if config is not None:
|
|
return config
|
|
|
|
return QUANTIZATION_METHODS[quantization]
|
|
|
|
|
|
original_isinstance = builtins.isinstance
|