Instructions to use ibm-granite/granite-4.2-8b-bf16-mlx with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use ibm-granite/granite-4.2-8b-bf16-mlx with MLX:
# Download the model from the Hub pip install huggingface_hub[hf_xet] hf download ibm-granite/granite-4.2-8b-bf16-mlx --local-dir granite-4.2-8b-bf16-mlx
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Atomic Chat
Uploading generated README.md for ibm-granite/granite-4.2-8b-bf16-mlx
Browse files
README.md
CHANGED
|
@@ -49,11 +49,11 @@ pip install mlx-lm
|
|
| 49 |
|
| 50 |
```bash
|
| 51 |
# mlx-lm is downloaded into a temporary environment on first use
|
| 52 |
-
uvx
|
| 53 |
-
--model ibm-granite/granite-4.2-8b-
|
| 54 |
--prompt "Why is the sky blue according to science?" \
|
| 55 |
-
--temp
|
| 56 |
-
--top-p 0.
|
| 57 |
```
|
| 58 |
|
| 59 |
#### Available MLX Variants
|
|
@@ -80,25 +80,25 @@ Run directly from a variant repository (mlx-lm will download weights on first us
|
|
| 80 |
|
| 81 |
```bash
|
| 82 |
mlx_lm generate \
|
| 83 |
-
--model ibm-granite/granite-4.2-8b-
|
| 84 |
--prompt "Why is the sky blue according to science?" \
|
| 85 |
-
--temp
|
| 86 |
-
--top-p 0.
|
| 87 |
```
|
| 88 |
|
| 89 |
To use a different quantization, substitute the variant suffix, for example `-q8-mlx` or `-bf16-mlx`.
|
| 90 |
|
| 91 |
-
You can also
|
| 92 |
|
| 93 |
```bash
|
| 94 |
-
|
| 95 |
-
|
| 96 |
|
| 97 |
mlx_lm generate \
|
| 98 |
-
--model ./granite-4.2-8b-
|
| 99 |
--prompt "Why is the sky blue according to science?" \
|
| 100 |
-
--temp
|
| 101 |
-
--top-p 0.
|
| 102 |
```
|
| 103 |
|
| 104 |
#### Recommended Generation Parameters
|
|
@@ -109,8 +109,8 @@ The Granite 4.2 base model recommends:
|
|
| 109 |
|
| 110 |
| Parameter | Recommended value | CLI flag |
|
| 111 |
|---|---|---|
|
| 112 |
-
| Temperature | `
|
| 113 |
-
| Top-p | `0.
|
| 114 |
|
| 115 |
> Without these flags, `mlx_lm generate` defaults to `--temp 0.0` (greedy / deterministic decoding) and `--top-p 1.0`.
|
| 116 |
|
|
@@ -118,10 +118,10 @@ Example with the recommended values applied:
|
|
| 118 |
|
| 119 |
```bash
|
| 120 |
mlx_lm generate \
|
| 121 |
-
--model ibm-granite/granite-4.2-8b-
|
| 122 |
--prompt "Explain retrieval-augmented generation in simple terms." \
|
| 123 |
-
--temp
|
| 124 |
-
--top-p 0.
|
| 125 |
```
|
| 126 |
|
| 127 |
In Python, always apply the chat template and pre-tokenize before calling `generate()`:
|
|
@@ -129,7 +129,7 @@ In Python, always apply the chat template and pre-tokenize before calling `gener
|
|
| 129 |
```python
|
| 130 |
from mlx_lm import load, generate
|
| 131 |
|
| 132 |
-
model, tokenizer = load("ibm-granite/granite-4.2-8b-
|
| 133 |
|
| 134 |
messages = [{"role": "user", "content": "Explain retrieval-augmented generation in simple terms."}]
|
| 135 |
|
|
@@ -142,7 +142,7 @@ prompt_str = tokenizer.apply_chat_template(
|
|
| 142 |
)
|
| 143 |
prompt = tokenizer.encode(prompt_str, add_special_tokens=False)
|
| 144 |
|
| 145 |
-
response = generate(model, tokenizer, prompt=prompt, temp=
|
| 146 |
print(response)
|
| 147 |
```
|
| 148 |
|
|
@@ -163,10 +163,10 @@ No extra flags are needed to enable thinking. The model reasons automatically:
|
|
| 163 |
|
| 164 |
```bash
|
| 165 |
mlx_lm generate \
|
| 166 |
-
--model ibm-granite/granite-4.2-8b-
|
| 167 |
--prompt "What is the difference between a mutex and a semaphore?" \
|
| 168 |
-
--temp
|
| 169 |
-
--top-p 0.
|
| 170 |
--max-tokens 1024
|
| 171 |
```
|
| 172 |
|
|
@@ -176,22 +176,22 @@ Pass `enable_thinking=false` via `--chat-template-config` to skip the reasoning
|
|
| 176 |
|
| 177 |
```bash
|
| 178 |
mlx_lm generate \
|
| 179 |
-
--model ibm-granite/granite-4.2-8b-
|
| 180 |
--prompt "Summarize this paragraph in one sentence." \
|
| 181 |
--chat-template-config '{"enable_thinking": false}' \
|
| 182 |
-
--temp
|
| 183 |
-
--top-p 0.
|
| 184 |
```
|
| 185 |
|
| 186 |
**CLI — request low-effort (faster) reasoning:**
|
| 187 |
|
| 188 |
```bash
|
| 189 |
mlx_lm generate \
|
| 190 |
-
--model ibm-granite/granite-4.2-8b-
|
| 191 |
--prompt "What is the difference between a mutex and a semaphore?" \
|
| 192 |
--chat-template-config '{"reasoning_effort": "low"}' \
|
| 193 |
-
--temp
|
| 194 |
-
--top-p 0.
|
| 195 |
--max-tokens 1024
|
| 196 |
```
|
| 197 |
|
|
@@ -205,7 +205,7 @@ Include `<think>` block before answer:
|
|
| 205 |
from mlx_lm import load, generate
|
| 206 |
|
| 207 |
model, tokenizer = load(
|
| 208 |
-
"ibm-granite/granite-4.2-8b-
|
| 209 |
)
|
| 210 |
|
| 211 |
messages = [{"role": "user", "content": "What is the difference between a mutex and a semaphore?"}]
|
|
@@ -225,7 +225,7 @@ prompt_str = tokenizer.apply_chat_template(
|
|
| 225 |
)
|
| 226 |
prompt = tokenizer.encode(prompt_str, add_special_tokens=False)
|
| 227 |
|
| 228 |
-
response = generate(model, tokenizer, prompt=prompt, temp=
|
| 229 |
print(response)
|
| 230 |
```
|
| 231 |
|
|
@@ -237,7 +237,7 @@ Direct answer with no `<think>` block:
|
|
| 237 |
from mlx_lm import load, generate
|
| 238 |
|
| 239 |
model, tokenizer = load(
|
| 240 |
-
"ibm-granite/granite-4.2-8b-
|
| 241 |
)
|
| 242 |
|
| 243 |
messages = [{"role": "user", "content": "Summarize this paragraph in one sentence."}]
|
|
@@ -250,7 +250,7 @@ prompt_str = tokenizer.apply_chat_template(
|
|
| 250 |
)
|
| 251 |
prompt = tokenizer.encode(prompt_str, add_special_tokens=False)
|
| 252 |
|
| 253 |
-
response = generate(model, tokenizer, prompt=prompt, temp=
|
| 254 |
print(response)
|
| 255 |
```
|
| 256 |
|
|
@@ -269,7 +269,7 @@ prompt_str = tokenizer.apply_chat_template(
|
|
| 269 |
)
|
| 270 |
prompt = tokenizer.encode(prompt_str, add_special_tokens=False)
|
| 271 |
|
| 272 |
-
response = generate(model, tokenizer, prompt=prompt, temp=
|
| 273 |
print(response)
|
| 274 |
```
|
| 275 |
|
|
|
|
| 49 |
|
| 50 |
```bash
|
| 51 |
# mlx-lm is downloaded into a temporary environment on first use
|
| 52 |
+
uvx mlx_lm generate \
|
| 53 |
+
--model ibm-granite/granite-4.2-8b-bf16-mlx \
|
| 54 |
--prompt "Why is the sky blue according to science?" \
|
| 55 |
+
--temp 1.0 \
|
| 56 |
+
--top-p 0.95
|
| 57 |
```
|
| 58 |
|
| 59 |
#### Available MLX Variants
|
|
|
|
| 80 |
|
| 81 |
```bash
|
| 82 |
mlx_lm generate \
|
| 83 |
+
--model ibm-granite/granite-4.2-8b-bf16-mlx \
|
| 84 |
--prompt "Why is the sky blue according to science?" \
|
| 85 |
+
--temp 1.0 \
|
| 86 |
+
--top-p 0.95
|
| 87 |
```
|
| 88 |
|
| 89 |
To use a different quantization, substitute the variant suffix, for example `-q8-mlx` or `-bf16-mlx`.
|
| 90 |
|
| 91 |
+
You can also download the model and run from a local path:
|
| 92 |
|
| 93 |
```bash
|
| 94 |
+
uvx --from huggingface-hub hf download ibm-granite/granite-4.2-8b-bf16-mlx \
|
| 95 |
+
--local-dir ./granite-4.2-8b-bf16-mlx
|
| 96 |
|
| 97 |
mlx_lm generate \
|
| 98 |
+
--model ./granite-4.2-8b-bf16-mlx \
|
| 99 |
--prompt "Why is the sky blue according to science?" \
|
| 100 |
+
--temp 1.0 \
|
| 101 |
+
--top-p 0.95
|
| 102 |
```
|
| 103 |
|
| 104 |
#### Recommended Generation Parameters
|
|
|
|
| 109 |
|
| 110 |
| Parameter | Recommended value | CLI flag |
|
| 111 |
|---|---|---|
|
| 112 |
+
| Temperature | `1.0` | `--temp 1.0` |
|
| 113 |
+
| Top-p | `0.95` | `--top-p 0.95` |
|
| 114 |
|
| 115 |
> Without these flags, `mlx_lm generate` defaults to `--temp 0.0` (greedy / deterministic decoding) and `--top-p 1.0`.
|
| 116 |
|
|
|
|
| 118 |
|
| 119 |
```bash
|
| 120 |
mlx_lm generate \
|
| 121 |
+
--model ibm-granite/granite-4.2-8b-bf16-mlx \
|
| 122 |
--prompt "Explain retrieval-augmented generation in simple terms." \
|
| 123 |
+
--temp 1.0 \
|
| 124 |
+
--top-p 0.95
|
| 125 |
```
|
| 126 |
|
| 127 |
In Python, always apply the chat template and pre-tokenize before calling `generate()`:
|
|
|
|
| 129 |
```python
|
| 130 |
from mlx_lm import load, generate
|
| 131 |
|
| 132 |
+
model, tokenizer = load("ibm-granite/granite-4.2-8b-bf16-mlx")
|
| 133 |
|
| 134 |
messages = [{"role": "user", "content": "Explain retrieval-augmented generation in simple terms."}]
|
| 135 |
|
|
|
|
| 142 |
)
|
| 143 |
prompt = tokenizer.encode(prompt_str, add_special_tokens=False)
|
| 144 |
|
| 145 |
+
response = generate(model, tokenizer, prompt=prompt, temp=1.0, top_p=0.95, max_tokens=256)
|
| 146 |
print(response)
|
| 147 |
```
|
| 148 |
|
|
|
|
| 163 |
|
| 164 |
```bash
|
| 165 |
mlx_lm generate \
|
| 166 |
+
--model ibm-granite/granite-4.2-8b-bf16-mlx \
|
| 167 |
--prompt "What is the difference between a mutex and a semaphore?" \
|
| 168 |
+
--temp 1.0 \
|
| 169 |
+
--top-p 0.95 \
|
| 170 |
--max-tokens 1024
|
| 171 |
```
|
| 172 |
|
|
|
|
| 176 |
|
| 177 |
```bash
|
| 178 |
mlx_lm generate \
|
| 179 |
+
--model ibm-granite/granite-4.2-8b-bf16-mlx \
|
| 180 |
--prompt "Summarize this paragraph in one sentence." \
|
| 181 |
--chat-template-config '{"enable_thinking": false}' \
|
| 182 |
+
--temp 1.0 \
|
| 183 |
+
--top-p 0.95
|
| 184 |
```
|
| 185 |
|
| 186 |
**CLI — request low-effort (faster) reasoning:**
|
| 187 |
|
| 188 |
```bash
|
| 189 |
mlx_lm generate \
|
| 190 |
+
--model ibm-granite/granite-4.2-8b-bf16-mlx \
|
| 191 |
--prompt "What is the difference between a mutex and a semaphore?" \
|
| 192 |
--chat-template-config '{"reasoning_effort": "low"}' \
|
| 193 |
+
--temp 1.0 \
|
| 194 |
+
--top-p 0.95 \
|
| 195 |
--max-tokens 1024
|
| 196 |
```
|
| 197 |
|
|
|
|
| 205 |
from mlx_lm import load, generate
|
| 206 |
|
| 207 |
model, tokenizer = load(
|
| 208 |
+
"ibm-granite/granite-4.2-8b-bf16-mlx"
|
| 209 |
)
|
| 210 |
|
| 211 |
messages = [{"role": "user", "content": "What is the difference between a mutex and a semaphore?"}]
|
|
|
|
| 225 |
)
|
| 226 |
prompt = tokenizer.encode(prompt_str, add_special_tokens=False)
|
| 227 |
|
| 228 |
+
response = generate(model, tokenizer, prompt=prompt, temp=1.0, top_p=0.95, max_tokens=1024)
|
| 229 |
print(response)
|
| 230 |
```
|
| 231 |
|
|
|
|
| 237 |
from mlx_lm import load, generate
|
| 238 |
|
| 239 |
model, tokenizer = load(
|
| 240 |
+
"ibm-granite/granite-4.2-8b-bf16-mlx"
|
| 241 |
)
|
| 242 |
|
| 243 |
messages = [{"role": "user", "content": "Summarize this paragraph in one sentence."}]
|
|
|
|
| 250 |
)
|
| 251 |
prompt = tokenizer.encode(prompt_str, add_special_tokens=False)
|
| 252 |
|
| 253 |
+
response = generate(model, tokenizer, prompt=prompt, temp=1.0, top_p=0.95, max_tokens=256)
|
| 254 |
print(response)
|
| 255 |
```
|
| 256 |
|
|
|
|
| 269 |
)
|
| 270 |
prompt = tokenizer.encode(prompt_str, add_special_tokens=False)
|
| 271 |
|
| 272 |
+
response = generate(model, tokenizer, prompt=prompt, temp=1.0, top_p=0.95, max_tokens=512)
|
| 273 |
print(response)
|
| 274 |
```
|
| 275 |
|