Views
No views yet
1from quark.torch import LLMTemplate, ModelQuantizer
2
3# --- Register GLM-5 template ---
4GLM5_template = LLMTemplate(
5 model_type="glm_moe_dsa",
6 kv_layers_name=["*kv_a_proj_with_mqa", "*kv_b_proj"],
7 q_layer_name="*q_a_proj",
8 exclude_layers_name=["lm_head"],
9)
10LLMTemplate.register_template(GLM5_template)
11print(f"[INFO]: Registered template '{GLM5_template.model_type}'")
12
13# --- Configuration ---
14model_dir = "zai-org/GLM-5"
15output_dir = "amd/GLM-5-MXFP4"
16quant_scheme = "mxfp4"
17exclude_layers = [
18 "*self_attn*",
19 "*mlp.gate",
20 "*lm_head",
21 "*mlp.gate_proj",
22 "*mlp.up_proj",
23 "*mlp.down_proj",
24]
25
26# --- Build quant config from template ---
27template = LLMTemplate.get("glm_moe_dsa")
28quant_config = template.get_config(scheme=quant_scheme, exclude_layers=exclude_layers)
29
30# --- File-to-file quantization (memory-efficient, no full model loading) ---
31quantizer = ModelQuantizer(quant_config)
32quantizer.direct_quantize_checkpoint(
33 pretrained_model_path=model_dir,
34 save_path=output_dir,
35)
36
37print(f"[INFO]: Quantization complete. Output saved to {output_dir}")
38| Benchmark | GLM-5 | GLM-5-MXFP4(this model) | Recovery |
| GSM8K (flexible-extract) | 95.00 | 94.92 | 99.92% |
lm-evaluation-harness framework, based on the Docker image rocm/pytorch-private:vllm_glm5_0225, with vLLM, lm-eval compiled and installed from source inside the image.
The Docker image contains the necessary vLLM code modifications to support this model.export VLLM_ROCM_USE_AITER=1
export VLLM_ROCM_USE_AITER_FP8BMM=0
export VLLM_ROCM_USE_AITER_FP4BMM=0
vllm serve amd/GLM-5-MXFP4 \
-tp 8 \
--block-size 1 \
--trust-remote-code \
--max-model-len 4096lm_eval \
--model local-completions \
--model_args '{"model": "amd/GLM-5-MXFP4", "base_url": "http://localhost:8000/v1/completions", "num_concurrent": 32, "max_retries": 10, "max_gen_toks": 2048, "tokenizer_backend":"None","tokenized_requests":"False" }' \
--tasks gsm8k \
--batch_size auto \
--num_fewshot 5 \
--trust_remote_code