Text Generation
Transformers
Safetensors
granite
granite-4.2
reasoning
thinking
tool-calling
ibm
conversational
Instructions to use ibm-granite/granite-4.2-30b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ibm-granite/granite-4.2-30b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="ibm-granite/granite-4.2-30b") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("ibm-granite/granite-4.2-30b") model = AutoModelForCausalLM.from_pretrained("ibm-granite/granite-4.2-30b", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Inference
- HuggingChat
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use ibm-granite/granite-4.2-30b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "ibm-granite/granite-4.2-30b" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ibm-granite/granite-4.2-30b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/ibm-granite/granite-4.2-30b
- SGLang
How to use ibm-granite/granite-4.2-30b with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "ibm-granite/granite-4.2-30b" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ibm-granite/granite-4.2-30b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "ibm-granite/granite-4.2-30b" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ibm-granite/granite-4.2-30b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use ibm-granite/granite-4.2-30b with Docker Model Runner:
docker model run hf.co/ibm-granite/granite-4.2-30b
Commit ·
70fc514
1
Parent(s): a0057a7
Update Serving with SGLang section (#1)
Browse files- Update Serving with SGLang section (ee753aa1cf9818b8f1a3ff9a40b0c43d0a7b5816)
- Use auto parser resolution and v0.5.18+ in the SGLang section (b5cbf0c68763a412bf52ede7fd39a9c6ff6ab993)
Co-authored-by: Xinyuan Tong <JustinTong@users.noreply.huggingface.co>
README.md
CHANGED
|
@@ -434,15 +434,12 @@ response = client.chat.completions.create(
|
|
| 434 |
print(response.choices[0].message.tool_calls)
|
| 435 |
```
|
| 436 |
|
| 437 |
-
<!--
|
| 438 |
## Serving with SGLang
|
| 439 |
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
Granite-4.2-30B can also be served with [SGLang](https://github.com/sgl-project/sglang) (v0.5.17+) for high-throughput inference.
|
| 443 |
|
| 444 |
-
> **Reasoning parser:** Use `nemotron_3`.
|
| 445 |
-
> **Tool calling parser:** Use `qwen3_coder`.
|
| 446 |
|
| 447 |
### Starting the Server
|
| 448 |
|
|
@@ -451,8 +448,8 @@ python3 -m sglang.launch_server \
|
|
| 451 |
--model-path ibm-granite/granite-4.2-30b \
|
| 452 |
--dtype bfloat16 \
|
| 453 |
--context-length 131072 \
|
| 454 |
-
--reasoning-parser
|
| 455 |
-
--tool-call-parser
|
| 456 |
```
|
| 457 |
|
| 458 |
### OpenAI-Compatible API Usage
|
|
@@ -463,13 +460,14 @@ from openai import OpenAI
|
|
| 463 |
client = OpenAI(base_url="http://localhost:30000/v1", api_key="unused")
|
| 464 |
|
| 465 |
response = client.chat.completions.create(
|
| 466 |
-
model="granite-4.2-30b",
|
| 467 |
messages=[{"role": "user", "content": "Explain the Riemann hypothesis in simple terms."}],
|
| 468 |
temperature=1.0,
|
| 469 |
top_p=0.95,
|
| 470 |
max_tokens=8192,
|
| 471 |
)
|
| 472 |
|
|
|
|
| 473 |
print(response.choices[0].message.content)
|
| 474 |
```
|
| 475 |
|
|
@@ -498,7 +496,7 @@ tools = [
|
|
| 498 |
]
|
| 499 |
|
| 500 |
response = client.chat.completions.create(
|
| 501 |
-
model="granite-4.2-30b",
|
| 502 |
messages=[{"role": "user", "content": "What's the weather like in Boston right now?"}],
|
| 503 |
tools=tools,
|
| 504 |
temperature=1.0,
|
|
@@ -508,7 +506,8 @@ response = client.chat.completions.create(
|
|
| 508 |
|
| 509 |
print(response.choices[0].message.tool_calls)
|
| 510 |
```
|
| 511 |
-
|
|
|
|
| 512 |
|
| 513 |
---
|
| 514 |
|
|
|
|
| 434 |
print(response.choices[0].message.tool_calls)
|
| 435 |
```
|
| 436 |
|
|
|
|
| 437 |
## Serving with SGLang
|
| 438 |
|
| 439 |
+
Granite-4.2-30B can also be served with [SGLang](https://github.com/sgl-project/sglang) (v0.5.18+) for high-throughput inference.
|
|
|
|
|
|
|
| 440 |
|
| 441 |
+
> **Reasoning parser:** Use `--reasoning-parser auto`, which resolves to the built-in `nemotron_3` parser for this checkpoint. It separates the thinking trace into `reasoning_content` and the final answer into `content`, and it handles all three thinking modes (`enable_thinking=True/False`, `low_effort=True`) described in [Thinking Modes](#thinking-modes).
|
| 442 |
+
> **Tool calling parser:** Use `--tool-call-parser auto`, which resolves to `qwen3_coder` for this checkpoint.
|
| 443 |
|
| 444 |
### Starting the Server
|
| 445 |
|
|
|
|
| 448 |
--model-path ibm-granite/granite-4.2-30b \
|
| 449 |
--dtype bfloat16 \
|
| 450 |
--context-length 131072 \
|
| 451 |
+
--reasoning-parser auto \
|
| 452 |
+
--tool-call-parser auto
|
| 453 |
```
|
| 454 |
|
| 455 |
### OpenAI-Compatible API Usage
|
|
|
|
| 460 |
client = OpenAI(base_url="http://localhost:30000/v1", api_key="unused")
|
| 461 |
|
| 462 |
response = client.chat.completions.create(
|
| 463 |
+
model="ibm-granite/granite-4.2-30b",
|
| 464 |
messages=[{"role": "user", "content": "Explain the Riemann hypothesis in simple terms."}],
|
| 465 |
temperature=1.0,
|
| 466 |
top_p=0.95,
|
| 467 |
max_tokens=8192,
|
| 468 |
)
|
| 469 |
|
| 470 |
+
print(response.choices[0].message.reasoning_content)
|
| 471 |
print(response.choices[0].message.content)
|
| 472 |
```
|
| 473 |
|
|
|
|
| 496 |
]
|
| 497 |
|
| 498 |
response = client.chat.completions.create(
|
| 499 |
+
model="ibm-granite/granite-4.2-30b",
|
| 500 |
messages=[{"role": "user", "content": "What's the weather like in Boston right now?"}],
|
| 501 |
tools=tools,
|
| 502 |
temperature=1.0,
|
|
|
|
| 506 |
|
| 507 |
print(response.choices[0].message.tool_calls)
|
| 508 |
```
|
| 509 |
+
|
| 510 |
+
For a full deployment recipe (Docker, H200/B200 launch matrix, thinking-mode examples, and benchmark data), see the [SGLang Granite 4.2 cookbook](https://docs.sglang.io/cookbook/autoregressive/IBM/Granite-4.2).
|
| 511 |
|
| 512 |
---
|
| 513 |
|