Views
No views yet
1#!/usr/bin/env python3
2"""Kimi-K2.5 W4A8 re-quantization via AMD Quark (File-to-File Quantization)."""
3
4import argparse
5import os
6from quark.torch.quantization.config.config import (
7 FP8E4M3PerTensorSpec, Int4PerChannelSpec, ProgressiveSpec,
8 QConfig, QLayerConfig,
9)
10from quark.torch.quantization.api import ModelQuantizer
11
12
13def get_config():
14 exclude_layers = [
15 "*self_attn*", "*mlp.gate", "*lm_head",
16 "*mlp.gate_proj", "*mlp.up_proj", "*mlp.down_proj",
17 "*shared_experts*", "*mm_projector*", "*vision_tower*",
18 ]
19
20 input_spec = FP8E4M3PerTensorSpec(
21 observer_method="min_max", scale_type="float32", is_dynamic=True,
22 ).to_quantization_spec()
23
24 weight_spec = ProgressiveSpec(
25 first_stage=FP8E4M3PerTensorSpec(
26 observer_method="min_max", scale_type="float32", is_dynamic=False,
27 ),
28 second_stage=Int4PerChannelSpec(
29 symmetric=True, scale_type="float32",
30 round_method="half_even", is_dynamic=False, ch_axis=0,
31 ),
32 ).to_quantization_spec()
33
34 return QConfig(
35 global_quant_config=QLayerConfig(input_tensors=input_spec, weight=weight_spec),
36 exclude=exclude_layers,
37 )
38
39
40if __name__ == "__main__":
41 parser = argparse.ArgumentParser()
42 parser.add_argument("--model-path", type=str, required=True,
43 help="Path to moonshotai/Kimi-K2.5 checkpoint")
44 parser.add_argument("--export-path", type=str, required=True,
45 help="Path to save quantized output")
46 args = parser.parse_args()
47
48 quantizer = ModelQuantizer(get_config())
49 quantizer.direct_quantize_checkpoint(
50 pretrained_model_path=args.model_path,
51 save_path=args.export_path,
52 )
53 print("[INFO] Quantization completed")| Benchmark | Kimi-K2.5 | Kimi-K2.5-W4A8(this model) | Recovery |
| GSM8K (flexible-extract) | 94.09 | 93.40 | 99.27% |
lm-evaluation-harness framework, based on the Docker image vllm/vllm-openai-rocm:v0.14.0.(commit ecb4f822091a64b5084b3a4aff326906487a363f) and lm-eval (Version: 0.4.10) in container first.git clone https://github.com/vllm-project/vllm.git
cd vllm
python3 setup.py develop
pip install lm-evalVLLM_ROCM_USE_AITER_MLA=0 VLLM_ROCM_USE_AITER=1 VLLM_ROCM_USE_AITER_FUSION_SHARED_EXPERTS=0 VLLM_ROCM_USE_AITER_FP4BMM=0 vllm serve amd/Kimi-K2.5-W4A8 \
--tensor-parallel-size 8 \
--mm-encoder-tp-mode data \
--tool-call-parser kimi_k2 \
--reasoning-parser kimi_k2 \
--trust-remote-code \
--enforce-eagerlm_eval \
--model local-completions \
--model_args "model=amd/Kimi-K2.5-W4A8,base_url=http://0.0.0.0:8000/v1/completions,tokenized_requests=False,tokenizer_backend=None,num_concurrent=32" \
--tasks gsm8k \
--num_fewshot 5 \
--batch_size 1