CoolFace
Modelpublic

RedHatAI/GLM-4.6-quantized.w8a8

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes29downloads
README.md263 linesDownload Raw Back to root
1---2tags:3- w8a84- vllm5language:6- en7- zh8pipeline_tag: text-generation9base_model: zai-org/GLM-4.610---11 12# GLM-4.6-quantized.w8a813 14## Model Overview15- **Model Architecture:** zai-org/GLM-4.616  - **Input:** Text17  - **Output:** Text18- **Model Optimizations:**19  - **Weight quantization:** INT820  - **Activation quantization:** INT821- **Out-of-scope:** Use in any manner that violates applicable laws or regulations (including trade compliance laws). Use in languages other than English.22- **Version:** 1.023- **Model Developers:** RedHatAI24 25This model is a quantized version of [zai-org/GLM-4.6](https://huggingface.co/zai-org/GLM-4.6).26It was evaluated on a several tasks to assess the its quality in comparison to the unquatized model.27 28### Model Optimizations29 30This model was obtained by quantizing the weights and activations of [zai-org/GLM-4.6](https://huggingface.co/zai-org/GLM-4.6) to INT8 data type, ready for inference with vLLM>=0.11.0.31 32Only the weights and activations of the linear operators within transformers blocks are quantized using [LLM Compressor](https://github.com/vllm-project/llm-compressor).33 34## Deployment35 36### Use with vLLM37 38This model can be deployed efficiently using the [vLLM](https://docs.vllm.ai/en/latest/) backend, as shown in the example below.39 40```python41from vllm import LLM, SamplingParams42from transformers import AutoTokenizer43 44model_id = "RedHatAI/GLM-4.6-quantized.w8a8"45number_gpus = 446 47sampling_params = SamplingParams(temperature=0.6, top_p=0.9, max_tokens=256)48 49tokenizer = AutoTokenizer.from_pretrained(model_id)50 51messages = [52    {"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},53    {"role": "user", "content": "Who are you?"},54]55 56prompts = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)57 58llm = LLM(model=model_id, tensor_parallel_size=number_gpus)59 60outputs = llm.generate(prompts, sampling_params)61 62generated_text = outputs[0].outputs[0].text63print(generated_text)64```65 66vLLM aslo supports OpenAI-compatible serving. See the [documentation](https://docs.vllm.ai/en/latest/) for more details.67 68## Creation69 70This model was created by applying a script similar to [LLM Compressor with calibration samples from UltraChat](https://github.com/vllm-project/llm-compressor/blob/main/examples/quantizing_moe/glm4_7_example.py), as presented in the code snipet below.71 72<details>73  74```python75from datasets import load_dataset76from transformers import AutoModelForCausalLM, AutoTokenizer77 78from llmcompressor import oneshot79from llmcompressor.modifiers.quantization import GPTQModifier80from llmcompressor.utils import dispatch_for_generation81 82MODEL_ID = "zai-org/GLM-4.6"83 84# Load model.85model = AutoModelForCausalLM.from_pretrained(86    MODEL_ID, torch_dtype="auto"87)88tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)89 90# Select calibration dataset.91DATASET_ID = "HuggingFaceH4/ultrachat_200k"92DATASET_SPLIT = "train_sft"93 94# Select number of samples.95# Increasing the number of samples can improve accuracy.96NUM_CALIBRATION_SAMPLES = 51297MAX_SEQUENCE_LENGTH = 204898 99# Load dataset and preprocess.100ds = load_dataset(DATASET_ID, split=f"{DATASET_SPLIT}[:{NUM_CALIBRATION_SAMPLES}]")101ds = ds.shuffle(seed=42)102 103def preprocess(example):104    return {105        "text": tokenizer.apply_chat_template(106            example["messages"],107            tokenize=False,108        )109    }110 111ds = ds.map(preprocess)112 113# Tokenize inputs.114def tokenize(sample):115    return tokenizer(116        sample["text"],117        padding=False,118        max_length=MAX_SEQUENCE_LENGTH,119        truncation=True,120        add_special_tokens=False,121    )122 123ds = ds.map(tokenize, remove_columns=ds.column_names)124 125# Configure the quantization algorithm and scheme with explicit parameters.126recipe = GPTQModifier(127    targets="Linear",128    scheme="W8A8",129    ignore=[130        "lm_head",131        "re:.*mlp.gate$"132    ],133)134 135# Apply quantization.136oneshot(137    model=model,138    dataset=ds,139    recipe=recipe,140    max_seq_length=MAX_SEQUENCE_LENGTH,141    num_calibration_samples=NUM_CALIBRATION_SAMPLES,142    pipeline="sequential",143    sequential_targets=["Glm4MoeDecoderLayer"],  144    trust_remote_code_model=True,145)146 147SAVE_DIR = "./" + MODEL_ID.rstrip("/").split("/")[-1] + "-quantized.w8a8"148model.save_pretrained(SAVE_DIR, save_compressed=True)149tokenizer.save_pretrained(SAVE_DIR)150 151```152</details>153 154## Evaluation155 156This model was evaluated on the well-known text benchmarks using [lm-evaluation-harness](https://github.com/neuralmagic/lm-evaluation-harness). The Reasoning evals were done using [ligheval](https://github.com/neuralmagic/lighteval).157 158### Accuracy159 160<table>161  <thead>162    <tr>163      <th>Category</th>164      <th>Metric</th>165      <th>zai-org/GLM-4.6-FP8</th>166      <th>RedHatAI/GLM-4.6-quantized.w8a8 (this model)</th>167      <th>Recovery</th>168    </tr>169  </thead>170<tbody>171<!-- OpenLLM V1 -->172<tr>173  <td rowspan="2"><b>Leaderboard</b></td>174  <td>MMLU Pro</td>175  <td>50.65%</td>176  <td>50.08%</td>177  <td>98.87%</td>178</tr>179<tr>180  <td>IFEVAL</td>181  <td>91.97%</td>182  <td>93.68%</td>183  <td>101.86%</td>184</tr>185<tr>186  <td rowspan="6"><b>Reasoning</b></td>187  <td>AIME25</td>188  <td>96.67%</td>189  <td>90.00%</td>190  <td>93.10%</td>191</tr>192<tr>193  <td>Math-500 (0-shot)</td>194  <td>88.80%</td>195  <td>90.60%</td>196  <td>102.03%</td>197</tr>198<tr>199  <td>GPQA (Diamond, 0-shot)</td>200  <td>81.82%</td>201  <td>78.78%</td>202  <td>96.28%</td>203</tr>204</tbody>205</table>206 207 208### Reproduction209 210The results were obtained using the following commands:211 212<details>213 214#### Leaderboard215 216```217lm_eval --model local-chat-completions \218  --tasks mmlu_pro  \219  --model_args "model=RedHatAI/GLM-4.6-quantized.w8a8,max_length=90000,base_url=http://0.0.0.0:3758/v1/chat/completions,num_concurrent=128,max_retries=3,tokenized_requests=False,tokenizer_backend=None,timeout=1200" \220  --num_fewshot 5 \221  --apply_chat_template \222  --fewshot_as_multiturn \223  --output_path ./ \224  --seed 42 \225  --gen_kwargs "do_sample=True,temperature=1.0,top_p=0.95,max_gen_toks=64000"226 227 228lm_eval --model local-chat-completions \229  --tasks leaderboard_ifeval  \230  --model_args "model=RedHatAI/GLM-4.6-quantized.w8a8,max_length=90000,base_url=http://0.0.0.0:3758/v1/chat/completions,num_concurrent=128,max_retries=3,tokenized_requests=False,tokenizer_backend=None,timeout=1200" \231  --num_fewshot 5 \232  --apply_chat_template \233  --fewshot_as_multiturn \234  --output_path ./ \235  --seed 42 \236  --gen_kwargs "do_sample=True,temperature=1.0,top_p=0.95,max_gen_toks=64000"237```238 239 240#### Reasoning241```242litellm_config.yaml:243 244model_parameters:245  provider: "hosted_vllm"246  model_name: "hosted_vllm/redhatai-glm-4.6-w8a8"247  base_url: "http://0.0.0.0:3759/v1"248  api_key: ""249  timeout: 3600250  concurrent_requests: 128251  generation_parameters:252    temperature: 1.0253    max_new_tokens: 131072254    top_p: 0.95255    seed: 0256 257lighteval endpoint litellm litellm_config.yaml \258  "aime25|0,math_500|0,gpqa:diamond|0" \259  --output-dir ./ \260  --save-details261```262 263</details>