krishnateja95 commited on
Commit
82b36e9
·
verified ·
1 Parent(s): 04c1dad

Update README.md

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