Text Generation
Transformers
Safetensors
granite
granite-4.2
reasoning
thinking
tool-calling
ibm
conversational
Eval Results
Instructions to use ibm-granite/granite-4.2-3b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ibm-granite/granite-4.2-3b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="ibm-granite/granite-4.2-3b") 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-3b") model = AutoModelForCausalLM.from_pretrained("ibm-granite/granite-4.2-3b", 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-3b 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-3b" # 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-3b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/ibm-granite/granite-4.2-3b
- SGLang
How to use ibm-granite/granite-4.2-3b 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-3b" \ --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-3b", "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-3b" \ --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-3b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use ibm-granite/granite-4.2-3b with Docker Model Runner:
docker model run hf.co/ibm-granite/granite-4.2-3b
Clarification on enabling and evaluating 512K context
#3
by pengwenzhi - opened
Hi Granite team,
The model card says Granite-4.2-3B natively supports 128K, with long-context extension to 512K, but the architecture still lists a sequence length of 131072, and the vLLM/SGLang examples do not show how to enable 512K.
Could you clarify the recommended configuration for 512K inference?
- Is 512K officially supported by the released checkpoint?
- Does it require any RoPE scaling or other positional-encoding settings?
- For vLLM, is
--max-model-len 524288sufficient? - For SGLang, is
--context-length 524288sufficient? - Do you have an official 512K evaluation or launch example?
Thanks!
Hi @pengwenzhi thanks for the question! Here are the details on the 128k vs 512k context lengths:
- All models in the 4.2 family were trained to support 512k context, so for each inference platform, you can simply use the corresponding flag to raise the max context length (no RoPE scaling needed)
- All models in the 4.2 were benchmarked and evaluated using 128k context, so the default values for each distributed checkpoint format is set to 128k as the maximum verified length
I got it.