Skip to content

Commit 8f66b65

Browse files
C-KRSWkrizaltang
andauthored
[ref]: Refeactor weight-only quantization. (#275)
Co-authored-by: krizaltang <krizaltang@tencent.com>
1 parent 0b4c6a5 commit 8f66b65

15 files changed

Lines changed: 194 additions & 72 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ A more accessible, comprehensive, and efficient toolkit for large model compress
2222
</p>
2323

2424
## 📣Latest News
25+
- [26/03/25] We have released **DAQ**, the quantization algorithm that preserves the knowledge acquired while the update of parameters is relatively small during post-training training.[[Paper]](https://arxiv.org/abs/2603.22324) | [[Docs]](docs/source/features/quantization/daq.md)
2526
- [26/02/09] We have released HY-1.8B-2Bit, 2bit on-device large language model,[[Huggingface]](https://huggingface.co/AngelSlim/HY-1.8B-2Bit).
2627
- [26/01/13] We have released v0.3. We support the training and deployment of Eagle3 for all-scale LLMs/VLMs/Audio models, as detailed in the [guidance documentation](https://angelslim.readthedocs.io/zh-cn/latest/features/speculative_decoding/eagle/index.html). And We released **Sherry**, the hardware-efficient 1.25 bit quantization algorithm [[Paper]](https://arxiv.org/abs/2601.07892) | [[Code]](https://github.com/Tencent/AngelSlim/tree/sherry/Sherry)🔥🔥🔥
2728
- [25/11/05] We have released v0.2. Quantization support for new models, such as `GLM-4.6`, `Qwen3-VL` and `Qwen3-Omni`, open-sources the Eagle3 speculative decoding training framework, and updates the Diffusion model quantization tools.

README_cn.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
</p>
2323

2424
## 📣最新进展
25+
- [26/03/25] 我们发布了量化算法DAQ,该方法在后训练参数更新较小时,可保留量化后模型能力 [[论文]](https://arxiv.org/abs/2603.22324) | [[文档]](docs/source/features/quantization/daq.md)
2526
- [26/02/09] 我们发布了 HY-1.8B-2Bit, 2比特端侧大模型, 模型可见[[Huggingface]](https://huggingface.co/AngelSlim/HY-1.8B-2Bit).
26-
- [26/01/13]我们发布V0.3版本, 支持了全模态场景的投机采样训练及部署,文档:[Eagle3 for LLM/VLM/Audio](https://angelslim.readthedocs.io/zh-cn/latest/features/speculative_decoding/eagle/index.html)。并且我们发布了 **Sherry** 新的硬件高效的1.25bit三值量化算法 [[论文]](https://arxiv.org/abs/2601.07892) | [[代码]](https://github.com/Tencent/AngelSlim/tree/sherry/Sherry)🔥🔥🔥
27+
- [26/01/13] 我们发布V0.3版本, 支持了全模态场景的投机采样训练及部署,文档:[Eagle3 for LLM/VLM/Audio](https://angelslim.readthedocs.io/zh-cn/latest/features/speculative_decoding/eagle/index.html)。并且我们发布了 **Sherry** 新的硬件高效的1.25bit三值量化算法 [[论文]](https://arxiv.org/abs/2601.07892) | [[代码]](https://github.com/Tencent/AngelSlim/tree/sherry/Sherry)🔥🔥🔥
2728
- [25/11/05] 我们发布V0.2版本,支持了包括GLM-4.6/Qwen3-VL/Qwen3-Omni等更多模型的量化,开源投机采样Eagle3训练框架,更新Diffusion模型量化工具。
2829
- [25/09/30] 我们开源了思考早退新算法 **SpecExit** [[论文]](http://arxiv.org/abs/2509.24248) | [[文档]](https://angelslim.readthedocs.io/zh-cn/latest/features/speculative_decoding/spec_exit.html) | [[vLLM代码]](https://github.com/vllm-project/vllm/pull/27192)
2930
- [25/09/30] 我们发布了三值量化新算法 **Tequila** [[论文]](https://arxiv.org/abs/2509.23809) | [[代码]](https://github.com/Tencent/AngelSlim/tree/tequila/TernaryQuant)
File renamed without changes.

angelslim/compressor/quant/modules/daq/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from angelslim.compressor.quant.core.kernels import ( # noqa: F401
16+
FP8_E4M3_SCHEME,
17+
QuantScheme,
18+
)
19+
1520
from .daq import DAQ # noqa: F401
16-
from .kernels import FP8_E4M3_SCHEME, QuantScheme # noqa: F401
1721

1822
__all__ = [
1923
"DAQ",

angelslim/compressor/quant/modules/daq/daq.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,16 @@
2828
from safetensors.torch import load_file, save_file
2929
from tqdm import tqdm
3030

31-
from .kernels import FP8_E4M3_SCHEME, create_quant_kernel
31+
from angelslim.compressor.quant.core.kernels import FP8_E4M3_SCHEME, create_quant_kernel
32+
from angelslim.utils import print_info
33+
3234
from .scale_search import scale_search_weight_quant
3335
from .utils import (
3436
compute_dynamic_cache_size,
3537
get_available_gpus,
3638
get_weight_map,
3739
load_base_weight,
3840
prefetch_base_shard,
39-
print_info,
4041
)
4142

4243
__all__ = ["DAQ"]
@@ -282,17 +283,6 @@ def run(self, save_path: str):
282283

283284
print_info("DAQ quantization complete!")
284285

285-
def save(self, save_path: str):
286-
"""Run DAQ quantization and save the quantized model."""
287-
self.run(save_path)
288-
289-
index_file = os.path.join(save_path, "model.safetensors.index.json")
290-
config_file = os.path.join(save_path, "config.json")
291-
if os.path.exists(index_file) and os.path.exists(config_file):
292-
print_info(f"Quantized model saved to {save_path}")
293-
else:
294-
print_info(f"Warning: Expected output files not found in {save_path}")
295-
296286
def _prepare_output_dir(self, save_path: str):
297287
# TODO: Currently we only support quantizing BF16 DeepSeek V3/R1 models to FP8.
298288
# To support all model architectures, the logic for determining which weights

angelslim/compressor/quant/modules/daq/scale_search.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818

1919
import torch
2020

21-
from .kernels import FP8E4M3Kernel, QuantKernel
21+
from angelslim.compressor.quant.core.kernels import FP8E4M3Kernel, QuantKernel
22+
2223
from .utils import print_info
2324

2425

angelslim/compressor/quant/modules/daq/utils.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,8 @@
2222
import torch
2323
from safetensors.torch import load_file
2424

25-
from .kernels import weight_dequant
26-
27-
28-
def print_info(msg: str):
29-
"""Print info message with [DAQ] prefix."""
30-
print(f"[DAQ] {msg}")
25+
from angelslim.compressor.quant.core.kernels import weight_dequant
26+
from angelslim.utils import print_info
3127

3228

3329
def get_available_gpus():

angelslim/compressor/quant/ptq.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from ..compressor_factory import CompressorFactory
2525
from ..transform import TransformFactory
2626
from .core import PTQHook
27-
from .modules import AWQ, DAQ, FP8, GPTQ, INT8, NVFP4, W4A8INT8, LeptoFP8, SmoothQuant
27+
from .modules import AWQ, FP8, GPTQ, INT8, NVFP4, W4A8INT8, LeptoFP8, SmoothQuant
2828

2929
__all__ = ["PTQ"]
3030

@@ -117,10 +117,6 @@ def __init__(self, model, slim_config=None):
117117
)
118118
elif "nvfp4" in self.quant_algo:
119119
self.nvfp4 = NVFP4(self.quant_model)
120-
elif "daq" in self.quant_algo:
121-
self.daq = DAQ(
122-
self.quant_model.quant_config._quantization_config, self.absolute_model_path
123-
)
124120
else:
125121
raise NotImplementedError(f"[AngelSlim Error] algo {self.quant_algo} is not support")
126122

@@ -144,8 +140,6 @@ def calibrate(self, dataloader):
144140
self.int8.run(dataloader)
145141
elif "nvfp4" in self.quant_algo:
146142
self.nvfp4.run(dataloader)
147-
elif "daq" in self.quant_algo:
148-
pass
149143
else:
150144
raise AssertionError(
151145
f"[AngelSlim Error] algo {self.quant_algo} is not support calibrate"
@@ -155,10 +149,6 @@ def convert(self):
155149
"""
156150
Saves scales and inserts QDQ modules.
157151
"""
158-
if "daq" in self.quant_algo:
159-
print_info("DAQ: skipping convert (quantization is performed during save)")
160-
return
161-
162152
print_info("Start convert model...")
163153
if "gptq" in self.quant_algo or "gptaq" in self.quant_algo:
164154
self.gptq.convert()
@@ -209,8 +199,6 @@ def save(self, save_path: str):
209199
self.w4a8i8.save(save_path)
210200
elif "awq" in self.quant_algo:
211201
self.awq.save(save_path)
212-
elif "daq" in self.quant_algo:
213-
self.daq.save(save_path)
214202
else:
215203
save_func = self.quant_model.get_save_func()(self.quant_model)
216204
save_func.save(save_path)

angelslim/engine.py

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ def prepare_model(
7878
using_multi_nodes=False,
7979
use_audio_in_video=False,
8080
attn_implementation="default",
81-
build_model=True,
8281
) -> Any:
8382
"""Load pretrained model and tokenizer
8483
Args:
@@ -114,28 +113,26 @@ def prepare_model(
114113
assert tokenizer, " If model is set, tokenizer must be also set."
115114
self.slim_model.tokenizer = tokenizer
116115
else:
117-
if build_model:
118-
self.slim_model.from_pretrained(
119-
model_path,
120-
torch_dtype=torch_dtype,
121-
device_map=device_map,
122-
trust_remote_code=trust_remote_code,
123-
low_cpu_mem_usage=low_cpu_mem_usage,
124-
use_cache=use_cache,
125-
using_multi_nodes=using_multi_nodes,
126-
)
116+
self.slim_model.from_pretrained(
117+
model_path,
118+
torch_dtype=torch_dtype,
119+
device_map=device_map,
120+
trust_remote_code=trust_remote_code,
121+
low_cpu_mem_usage=low_cpu_mem_usage,
122+
use_cache=use_cache,
123+
using_multi_nodes=using_multi_nodes,
124+
)
127125
self.model_path = model_path
128126
elif self.series in ["Omni"]:
129127
if not model:
130-
if build_model:
131-
self.slim_model.from_pretrained(
132-
model_path,
133-
torch_dtype=torch_dtype,
134-
device_map=device_map,
135-
trust_remote_code=trust_remote_code,
136-
use_audio_in_video=use_audio_in_video,
137-
attn_implementation=attn_implementation,
138-
)
128+
self.slim_model.from_pretrained(
129+
model_path,
130+
torch_dtype=torch_dtype,
131+
device_map=device_map,
132+
trust_remote_code=trust_remote_code,
133+
use_audio_in_video=use_audio_in_video,
134+
attn_implementation=attn_implementation,
135+
)
139136
self.model_path = model_path
140137
else:
141138
raise ValueError(f"Unsupported series: {self.series}")

angelslim/utils/config_parser.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -320,20 +320,6 @@ def need_dataset(self) -> bool:
320320
return True
321321
return False
322322

323-
@property
324-
def need_build_model(self) -> bool:
325-
"""Check if any of the methods requires building the model."""
326-
if not self.name:
327-
return True
328-
329-
for method in self.name:
330-
# PTQ/QAT usually need calibration dataset
331-
if method in ["PTQ"]:
332-
# DAQ is data-free, no calibration dataset needed
333-
if self.quantization and self.quantization.name == "daq":
334-
return False
335-
return True
336-
337323
@property
338324
def only_inference(self) -> Union[bool, List[bool]]:
339325
"""

0 commit comments

Comments
 (0)