docs_new/docs/developer_guide/quantization_contribution_guide.mdx
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.
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:
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/.
Use this layout for a quantization method that has multiple schemes or backend-specific execution paths:
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:
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.
python/sglang/srt/layers/quantization/__init__.py when needed.get_linear_scheme and get_moe_scheme.For examples, see the AWQ and GPTQ refactors:
Quantization changes can affect both accuracy and performance. Include validation that matches the blast radius of the change.
For Python-only structure changes:
ruff check <changed-python-files>
git diff --check
For quantized model behavior:
/generate request and confirm the output path succeeds.For backend-specific changes:
Before requesting review, make sure the PR description includes:
Use the general Contribution Guide for source setup, formatting, unit tests, CI triggering, and review process details.