File size: 6,965 Bytes
82b36e9 ec4f380 82b36e9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
---
license: apache-2.0
pipeline_tag: text-generation
tags:
- fp8
- quantized
- llm-compressor
- compressed-tensors
- red hat
base_model:
- ibm-granite/granite-4.0-h-tiny
---
# Granite-4.0-h-tiny
## Model Overview
- **Model Architecture:** GraniteMoeHybridForCausalLM
- **Input:** Text
- **Output:** Text
- **Model Optimizations:**
- **Weight quantization:** FP8
- **Activation quantization:** FP8
- **Release Date:**
- **Version:** 1.0
- **Model Developers:**: Red Hat
Quantized version of [ibm-granite/granite-4.0-h-tiny](https://huggingface.co/ibm-granite/granite-4.0-h-tiny).
### Model Optimizations
This model was obtained by quantizing the weights and activations of [ibm-granite/granite-4.0-h-tiny](https://huggingface.co/ibm-granite/granite-4.0-h-tiny) to FP8 data type.
This optimization reduces the number of bits per parameter from 16 to 8, reducing the disk size and GPU memory requirements by approximately 50%.
Only the weights and activations of the linear operators within transformers blocks of the language model are quantized.
## Deployment
### Use with vLLM
1. Install specific version:
```
uv pip install -U git+https://github.com/vllm-project/vllm.git \
--extra-index-url https://wheels.vllm.ai/nightly \
--no-deps \
--no-cache
uv pip install compressed-tensors==0.12.3a20251114 --no-cache
uv pip install --upgrade torchvision --break-system-packages --no-cache
uv pip install cloudpickle msgspec zmq blake3 cachetools prometheus_client fastapi openai openai_harmony pybase64 llguidance diskcache xgrammar lm-format-enforcer partial-json-parser cbor2 einops gguf numba --no-cache
```
2. Initialize vLLM server:
```
vllm serve RedHatAI/granite-4.0-h-tiny-FP8-block --tensor_parallel_size 1
```
3. Send requests to the server:
```python
from openai import OpenAI
# Modify OpenAI's API key and API base to use vLLM's API server.
openai_api_key = "EMPTY"
openai_api_base = "http://<your-server-host>:8000/v1"
client = OpenAI(
api_key=openai_api_key,
base_url=openai_api_base,
)
model = "RedHatAI/granite-4.0-h-tiny-FP8-block"
messages = [
{"role": "user", "content": "Explain quantum mechanics clearly and concisely."},
]
outputs = client.chat.completions.create(
model=model,
messages=messages,
)
generated_text = outputs.choices[0].message.content
print(generated_text)
```
## Creation
This model was quantized using the [llm-compressor](https://github.com/vllm-project/llm-compressor) library as shown below.
<details>
<summary>Creation details</summary>
Install specific llm-compression version:
```
uv pip install git+https://github.com/vllm-project/llm-compressor.git@refs/pull/2001/head --no-cache
uv pip install --upgrade torchvision --break-system-packages --no-cache
```
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
from llmcompressor import oneshot
from llmcompressor.modifiers.quantization import QuantizationModifier
from llmcompressor.utils import dispatch_for_generation
from llmcompressor.modeling import replace_modules_for_calibration
from llmcompressor.modeling.granite4 import pack_3d_experts
MODEL_ID = "ibm-granite/granite-4.0-h-tiny"
model = AutoModelForCausalLM.from_pretrained(MODEL_ID, torch_dtype="auto")
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
model = replace_modules_for_calibration(model)
ignore_lay = ["lm_head", "re:.*block_sparse_moe.router", "re:.*mamba.in_proj", "re:.*shared_mlp.input_linear"]
recipe = QuantizationModifier(
targets=["Linear"],
scheme="FP8_BLOCK",
ignore=ignore_lay,
)
oneshot(model=model, recipe=recipe)
print("========== SAMPLE GENERATION ==============")
dispatch_for_generation(model)
input_ids = tokenizer(
"Describe Large Language Model", return_tensors="pt"
).input_ids.to(model.device)
output = model.generate(input_ids, max_new_tokens=35)
print(tokenizer.decode(output[0]))
print("==========================================")
SAVE_DIR = MODEL_ID.rstrip("/").split("/")[-1] + "-FP8-block"
print(f"Saving to {SAVE_DIR}")
model.save_pretrained(SAVE_DIR)
tokenizer.save_pretrained(SAVE_DIR)
pack_3d_experts(SAVE_DIR)
```
</details>
## Evaluation
The model was evaluated on the OpenLLM leaderboard task, using [lm-evaluation-harness](https://github.com/EleutherAI/lm-evaluation-harness).
[vLLM](https://docs.vllm.ai/en/stable/) was used for all evaluations.
<details>
<summary>Evaluation details</summary>
Install specific version:
```
uv pip install -U git+https://github.com/vllm-project/vllm.git \
--extra-index-url https://wheels.vllm.ai/nightly \
--no-deps \
--no-cache
uv pip install compressed-tensors==0.12.3a20251114 --no-cache
uv pip install --upgrade torchvision --break-system-packages --no-cache
uv pip install cloudpickle msgspec zmq blake3 cachetools prometheus_client fastapi openai openai_harmony pybase64 llguidance diskcache xgrammar lm-format-enforcer partial-json-parser cbor2 einops gguf numba --no-cache
```
**Openllm V1**
```
lm_eval \
--model vllm \
--model_args pretrained="RedHatAI/granite-4.0-h-tiny-FP8-block",dtype=auto,add_bos_token=True,max_model_len=16384,tensor_parallel_size=1,gpu_memory_utilization=0.9,enable_chunked_prefill=True,trust_remote_code=True \
--tasks openllm \
--write_out \
--batch_size auto \
--show_config
```
**Openllm V2**
```
lm_eval \
--model vllm \
--model_args pretrained="RedHatAI/granite-4.0-h-tiny-FP8-block",dtype=auto,add_bos_token=False,max_model_len=16384,tensor_parallel_size=1,gpu_memory_utilization=0.7,disable_log_stats=True,enable_chunked_prefill=True,trust_remote_code=True \
--tasks leaderboard \
--apply_chat_template \
--fewshot_as_multiturn \
--write_out \
--batch_size auto \
--show_config
```
**Coding Benchmarks**
```
evalplus.evaluate --model "RedHatAI/granite-4.0-h-tiny-FP8-block" \
--dataset "humaneval" \
--backend vllm \
--tp 1 \
--greedy
evalplus.evaluate --model "RedHatAI/granite-4.0-h-tiny-FP8-block" \
--dataset "mbpp" \
--backend vllm \
--tp 1 \
--greedy
```
</details>
<!-- <b>*</b> I/p Length = 2048, O/p Length = 2048, #Requests = 1024 -->
### Accuracy Comparison
| Category | Benchmark | ibm-granite/granite-4.0-h-tiny | RedHatAI/granite-4.0-h-tiny-FP8-block | Recovery (%) |
|:--|:--|:-:|:-:|:-:|
| **OpenLLM V1** | ARC-Challenge (Acc, 25-shot) | 62.97 | 63.40 | 100.68 |
| | GSM8K (Strict-Match, 5-shot) | 80.44 | 81.05 | 100.76 |
| | HellaSwag (Acc-Norm, 10-shot) | 61.75 | 61.79 | 100.06 |
| | MMLU (Acc, 5-shot) | 66.46 | 66.22 | 99.64 |
| | TruthfulQA (MC2, 0-shot) | 58.48 | 58.76 | 100.48 |
| | Winogrande (Acc, 5-shot) | 71.43 | 71.35 | 99.89 |
| | **Average** | **66.92** | **67.10** | **100.26** |
| **OpenLLM V2** | IFEval (Inst Level Strict Acc, 0-shot) | 70.62 | 69.30 | 98.13 |
|