Files
wehub-resource-sync 94057c3d3e
CI Model Inventory / build-inventory (push) Waiting to run
Lint / lint (push) Waiting to run
PR Benchmark (SMG Components) / Benchmark Compilation Check (push) Waiting to run
PR Benchmark (SMG Components) / Benchmark - Manual Policy (push) Waiting to run
PR Benchmark (SMG Components) / Benchmark - Request Processing (push) Waiting to run
PR Benchmark (SMG Components) / Benchmark Summary (push) Blocked by required conditions
Release SGLang Model Gateway Docker Image / publish (push) Waiting to run
Release SGLang Model Gateway to PyPI / build on macos (aarch64 - auto) (push) Waiting to run
Release SGLang Model Gateway to PyPI / build on windows (x86_64 - auto) (push) Waiting to run
Release SGLang Model Gateway to PyPI / build on macos (x86_64 - auto) (push) Waiting to run
Release SGLang Model Gateway to PyPI / build on linux (aarch64 - auto) (push) Waiting to run
Release SGLang Model Gateway to PyPI / build on linux (x86_64 - auto) (push) Waiting to run
Release SGLang Model Gateway to PyPI / build on linux (aarch64 - musllinux_1_1) (push) Waiting to run
Release SGLang Model Gateway to PyPI / build on linux (x86_64 - musllinux_1_1) (push) Waiting to run
Release SGLang Model Gateway to PyPI / Build SDist (push) Waiting to run
Release SGLang Model Gateway to PyPI / Upload to PyPI (push) Blocked by required conditions
Release SGLang Kernels / build-cu129-matrix (aarch64, 12.9, 3.10, arm-kernel-build-node) (push) Waiting to run
Release SGLang Kernels / build-cu129-matrix (x86_64, 12.9, 3.10, x64-kernel-build-node) (push) Waiting to run
Release SGLang Kernels / release-cu129 (push) Blocked by required conditions
Release SGLang Kernels / build-cu130-matrix (aarch64, 13.0, 3.10, arm-kernel-build-node) (push) Waiting to run
Release SGLang Kernels / build-cu130-matrix (x86_64, 13.0, 3.10, x64-kernel-build-node) (push) Waiting to run
Release SGLang Kernels / release-cu130 (push) Blocked by required conditions
Release SGLang Kernels / build-rocm-matrix (3.10, 700) (push) Waiting to run
PR Test (SMG) / build-wheel (push) Waiting to run
PR Test (SMG) / python-unit-tests (push) Blocked by required conditions
PR Test (SMG) / unit-tests (push) Waiting to run
PR Test (SMG) / benchmarks (push) Blocked by required conditions
PR Test (SMG) / chat-completions (push) Blocked by required conditions
PR Test (SMG) / chat-completions-4gpu (push) Blocked by required conditions
PR Test (SMG) / e2e (push) Blocked by required conditions
PR Test (SMG) / docker-build-test (push) Waiting to run
PR Test (SMG) / k8s-integration (push) Waiting to run
PR Test (SMG) / finish (push) Blocked by required conditions
PR Test (SMG) / summarize-benchmarks (push) Blocked by required conditions
Release SGLang Kernels / build-rocm-matrix (3.10, 720) (push) Waiting to run
Release SGLang Kernels / release-rocm700 (push) Blocked by required conditions
Release SGLang Kernels / release-rocm720 (push) Blocked by required conditions
Release SGLang Kernels / build-musa43 (43, 3.10) (push) Waiting to run
Release SGLang Kernels / release-musa43 (push) Blocked by required conditions
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
chore: import upstream snapshot with attribution
2026-07-13 12:38:16 +08:00

97 lines
4.7 KiB
Plaintext

---
title: "Quantization Contribution Guide"
metatags:
description: "Guidance for contributing SGLang quantization methods, schemes, backend kernels, tests, and validation results."
---
This guide describes how to add or refactor quantization support in SGLang. It focuses on the common structure used by weight-only and weight-activation quantization methods such as AWQ, GPTQ, compressed-tensors, ModelSlim, Quark, and related backend kernels.
## Design Goals
Quantization code should keep the quantization format semantics separate from hardware-specific execution. This makes it easier to add new formats, reuse kernels across formats, and review platform-specific changes independently.
Follow the architecture proposed in [Quantization Modifications](https://github.com/sgl-project/sglang/issues/15194):
- **Config**: parses model and runtime quantization parameters, validates supported options, and selects the proper scheme.
- **Scheme**: owns quantized weight creation, weight loading, post-processing, and quantized layer wiring for Linear, MoE, embedding, or other module types.
- **Backend kernel**: wraps hardware-specific execution, layout conversion, kernel selection, and kernel calls for GPU (CUDA/HIP/XPU), NPU, or other backends.
Avoid putting config parsing, weight loading, and backend kernel calls in a single monolithic file. If a method needs multiple formats or backends, add a package under `python/sglang/srt/layers/quantization/<method>/` and split schemes into `schemes/`.
## Recommended File Layout
Use this layout for a quantization method that has multiple schemes or backend-specific execution paths:
```text
python/sglang/srt/layers/quantization/<method>/
__init__.py
<method>.py
schemes/
__init__.py
<method>_scheme.py
<method>_linear.py
<method>_moe.py
<method>_<variant>.py
```
Backend kernels should live under the hardware backend they target:
```text
python/sglang/srt/hardware_backend/gpu/quantization/<method>_kernels.py
python/sglang/srt/hardware_backend/npu/quantization/<method>_kernels.py
```
Keep shared method selection in the quantization package and keep backend imports narrow. This prevents circular imports and keeps non-target platforms from importing unavailable kernel dependencies.
## Adding or Refactoring a Quantization Method
1. Define the config entry point and register it through `python/sglang/srt/layers/quantization/__init__.py` when needed.
2. Add explicit scheme selection helpers such as `get_linear_scheme` and `get_moe_scheme`.
3. Move layer-specific weight creation and weight loading into scheme classes.
4. Move GPU (CUDA/HIP/XPU), NPU, or other hardware kernel calls into backend kernel modules.
5. Keep Linear, MoE, embedding, and non-linear module handling explicit. Do not assign a Linear quantization method to a module type that needs different semantics.
6. Preserve compatibility for existing quantized checkpoints and runtime flags.
7. Add tests that cover both config parsing and execution paths touched by the change.
For examples, see the AWQ and GPTQ refactors:
- [PR #21126](https://github.com/sgl-project/sglang/pull/21126): splits AWQ schemes, weight initialization, and backend kernel calls.
- [PR #26402](https://github.com/sgl-project/sglang/pull/26402): applies the same scheme/kernel split to GPTQ.
## Tests and Validation
Quantization changes can affect both accuracy and performance. Include validation that matches the blast radius of the change.
For Python-only structure changes:
```bash
ruff check <changed-python-files>
git diff --check
```
For quantized model behavior:
- Launch at least one representative model for each touched quantization method.
- Send a `/generate` request and confirm the output path succeeds.
- Run an accuracy sanity test if the change can affect numerics.
- Include warmup-aware benchmark results when the change affects kernel calls, layout conversion, or dispatch.
For backend-specific changes:
- Validate GPU changes on a supported GPU environment (NVIDIA, AMD, or Intel).
- Validate NPU changes on a supported Ascend environment.
- Include the exact model, quantization flag, backend flag, hardware, and command used in the PR description.
## PR Checklist
Before requesting review, make sure the PR description includes:
- The quantization method and backend paths changed.
- The issue, design proposal, or roadmap item the PR follows.
- Any compatibility notes for existing checkpoints or flags.
- Accuracy results when model outputs can change.
- Benchmark or profiling results when runtime performance can change.
- The exact local checks and model launch tests that were run.
Use the general [Contribution Guide](./contribution_guide) for source setup, formatting, unit tests, CI triggering, and review process details.