Update README.md
Browse files
README.md
CHANGED
|
@@ -1,6 +1,131 @@
|
|
| 1 |
---
|
| 2 |
license: mit
|
| 3 |
---
|
| 4 |
-
#
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: mit
|
| 3 |
---
|
| 4 |
+
# Model Overview
|
| 5 |
|
| 6 |
+
- **Model Architecture:** GLM-5
|
| 7 |
+
- **Input:** Text
|
| 8 |
+
- **Output:** Text
|
| 9 |
+
- **Supported Hardware Microarchitecture:** AMD MI350/MI355
|
| 10 |
+
- **ROCm:** 7.1.0
|
| 11 |
+
- **Operating System(s):** Linux
|
| 12 |
+
- **Inference Engine:** [vLLM](https://docs.vllm.ai/en/latest/)
|
| 13 |
+
- **Model Optimizer:** [AMD-Quark](https://quark.docs.amd.com/latest/index.html) (V0.11.1)
|
| 14 |
+
- **moe**
|
| 15 |
+
- **Weight quantization:** MOE-only, OCP MXFP4, Static
|
| 16 |
+
- **Activation quantization:** MOE-only, OCP MXFP4, Dynamic
|
| 17 |
+
- **Calibration Dataset:** [Pile](https://huggingface.co/datasets/mit-han-lab/pile-val-backup)
|
| 18 |
+
|
| 19 |
+
This model was built with GLM-5 model by applying [AMD-Quark](https://quark.docs.amd.com/latest/index.html) for MXFP4 quantization.
|
| 20 |
+
|
| 21 |
+
# Model Quantization
|
| 22 |
+
|
| 23 |
+
The model was quantized from [zai-org/GLM-5](https://huggingface.co/zai-org/GLM-5) using [AMD-Quark](https://quark.docs.amd.com/latest/index.html). The weights and activations are quantized to MXFP4.
|
| 24 |
+
|
| 25 |
+
**Quantization scripts:**
|
| 26 |
+
|
| 27 |
+
```python
|
| 28 |
+
from quark.torch import LLMTemplate, ModelQuantizer
|
| 29 |
+
|
| 30 |
+
# --- Register GLM-5 template ---
|
| 31 |
+
GLM5_template = LLMTemplate(
|
| 32 |
+
model_type="glm_moe_dsa",
|
| 33 |
+
kv_layers_name=["*kv_a_proj_with_mqa", "*kv_b_proj"],
|
| 34 |
+
q_layer_name="*q_a_proj",
|
| 35 |
+
exclude_layers_name=["lm_head"],
|
| 36 |
+
)
|
| 37 |
+
LLMTemplate.register_template(GLM5_template)
|
| 38 |
+
print(f"[INFO]: Registered template '{GLM5_template.model_type}'")
|
| 39 |
+
|
| 40 |
+
# --- Configuration ---
|
| 41 |
+
model_dir = "zai-org/GLM-5"
|
| 42 |
+
output_dir = "amd/GLM-5-MXFP4"
|
| 43 |
+
quant_scheme = "mxfp4"
|
| 44 |
+
exclude_layers = [
|
| 45 |
+
"*self_attn*",
|
| 46 |
+
"*mlp.gate",
|
| 47 |
+
"*lm_head",
|
| 48 |
+
"*mlp.gate_proj",
|
| 49 |
+
"*mlp.up_proj",
|
| 50 |
+
"*mlp.down_proj",
|
| 51 |
+
"*shared_experts*",
|
| 52 |
+
]
|
| 53 |
+
|
| 54 |
+
# --- Build quant config from template ---
|
| 55 |
+
template = LLMTemplate.get("glm_moe_dsa")
|
| 56 |
+
quant_config = template.get_config(scheme=quant_scheme, exclude_layers=exclude_layers)
|
| 57 |
+
|
| 58 |
+
# --- File-to-file quantization (memory-efficient, no full model loading) ---
|
| 59 |
+
quantizer = ModelQuantizer(quant_config)
|
| 60 |
+
quantizer.direct_quantize_checkpoint(
|
| 61 |
+
pretrained_model_path=model_dir,
|
| 62 |
+
save_path=output_dir,
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
print(f"[INFO]: Quantization complete. Output saved to {output_dir}")
|
| 66 |
+
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
# Deployment
|
| 70 |
+
### Use with vLLM
|
| 71 |
+
|
| 72 |
+
This model can be deployed efficiently using the [vLLM](https://docs.vllm.ai/en/latest/) backend.
|
| 73 |
+
|
| 74 |
+
## Evaluation
|
| 75 |
+
The model was evaluated on GSM8K benchmarks.
|
| 76 |
+
|
| 77 |
+
### Accuracy
|
| 78 |
+
|
| 79 |
+
<table>
|
| 80 |
+
<tr>
|
| 81 |
+
<td><strong>Benchmark</strong>
|
| 82 |
+
</td>
|
| 83 |
+
<td><strong>GLM-5 </strong>
|
| 84 |
+
</td>
|
| 85 |
+
<td><strong>GLM-5-MXFP4(this model)</strong>
|
| 86 |
+
</td>
|
| 87 |
+
<td><strong>Recovery</strong>
|
| 88 |
+
</td>
|
| 89 |
+
</tr>
|
| 90 |
+
<tr>
|
| 91 |
+
<td>GSM8K (flexible-extract)
|
| 92 |
+
</td>
|
| 93 |
+
<td>95.45
|
| 94 |
+
</td>
|
| 95 |
+
<td>95.00
|
| 96 |
+
</td>
|
| 97 |
+
<td>99.53%
|
| 98 |
+
</td>
|
| 99 |
+
</tr>
|
| 100 |
+
</table>
|
| 101 |
+
|
| 102 |
+
### Reproduction
|
| 103 |
+
|
| 104 |
+
The GSM8K results were obtained using the `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.
|
| 105 |
+
The Docker image contains the necessary vLLM code modifications to support this model.
|
| 106 |
+
|
| 107 |
+
#### Launching server
|
| 108 |
+
```
|
| 109 |
+
export VLLM_ROCM_USE_AITER=1
|
| 110 |
+
export VLLM_ROCM_USE_AITER_FP8BMM=0
|
| 111 |
+
export VLLM_ROCM_USE_AITER_FP4BMM=0
|
| 112 |
+
vllm serve amd/GLM-5-MXFP4 \
|
| 113 |
+
-tp 8 \
|
| 114 |
+
--block-size 1 \
|
| 115 |
+
--trust-remote-code \
|
| 116 |
+
--max-model-len 4096
|
| 117 |
+
```
|
| 118 |
+
|
| 119 |
+
#### Evaluating model in a new terminal
|
| 120 |
+
```
|
| 121 |
+
lm_eval \
|
| 122 |
+
--model local-completions \
|
| 123 |
+
--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" }' \
|
| 124 |
+
--tasks gsm8k \
|
| 125 |
+
--batch_size auto \
|
| 126 |
+
--num_fewshot 5 \
|
| 127 |
+
--trust_remote_code
|
| 128 |
+
```
|
| 129 |
+
|
| 130 |
+
# License
|
| 131 |
+
Modifications Copyright(c) 2025 Advanced Micro Devices, Inc. All rights reserved.
|