使用llmcompressor量化
llmcompressor==0.8.2
compressed-tensors==0.12.2量化脚本 per-group 128 w4a8
from transformers import AutoModelForCausalLM, AutoTokenizer
from llmcompressor import oneshot
MODEL_ID = "/shared/models/Qwen3-30B-A3B-Instruct-2507"
# Load model.
model = AutoModelForCausalLM.from_pretrained(MODEL_ID, torch_dtype="auto")
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
recipe = """
quant_stage:
quant_modifiers:
QuantizationModifier:
ignore: ["lm_head", "re:.*mlp.gate$"]
config_groups:
group_0:
weights:
num_bits: 8
type: int
strategy: channel
dynamic: false
symmetric: true
input_activations:
num_bits: 8
type: int
strategy: token
dynamic: true
symmetric: true
targets: ["re:.*self_attn.k_proj.*", "re:.*self_attn.o_proj.*",
"re:.*self_attn.q_proj.*", "re:.*self_attn.v_proj.*"]
group_1:
weights:
num_bits: 4
type: int
strategy: group
group_size: 128
dynamic: false
symmetric: true
input_activations:
num_bits: 8
type: int
strategy: token
dynamic: true
symmetric: true
targets: ["re:.*down_proj.*", "re:.*gate_proj.*", "re:.*up_proj.*"]
"""
# Apply quantization.
oneshot(
model=model,
recipe=recipe,
trust_remote_code_model=True,
)
# Save to disk in compressed-tensors format.
SAVE_DIR = "./Qwen3-30B-A3B-Instruct-2507-W4A8"
model.save_pretrained(SAVE_DIR, save_compressed=True)
tokenizer.save_pretrained(SAVE_DIR)SDK下载
#安装ModelScope
pip install modelscope#SDK模型下载
from modelscope import snapshot_download
model_dir = snapshot_download('vllm-ascend/Qwen3-30B-A3B-Instruct-2507-quantized.w4a8')Git下载
#Git模型下载
git clone https://www.modelscope.cn/vllm-ascend/Qwen3-30B-A3B-Instruct-2507-quantized.w4a8.git如果您是本模型的贡献者,我们邀请您根据模型贡献文档,及时完善模型卡片内容。