ai/granite4

Verified Publisher

By Docker

Updated 6 days ago

Artifact
0

7.5K

ai/granite4 repository overview

See our collection for all versions of Granite-4.0 including GGUF, 4-bit & 16-bit formats.

Learn to run Granite 4.0 correctly - Read our Guide.

See Unsloth Dynamic 2.0 GGUFs for our quantization benchmarks.

✨ Read our Granite-4.0 Guide here!

Granite-4.0-H-Small

Model Summary: Granite-4.0-H-Small is a 32B parameter long-context instruct model finetuned from Granite-4.0-H-Small-Base using a combination of open source instruction datasets with permissive license and internally collected synthetic datasets. This model is developed using a diverse set of techniques with a structured chat format, including supervised finetuning, model alignment using reinforcement learning, and model merging. Granite 4.0 instruct models feature improved instruction following (IF) and tool-calling capabilities, making them more effective in enterprise applications.

Supported Languages: English, German, Spanish, French, Japanese, Portuguese, Arabic, Czech, Italian, Korean, Dutch, and Chinese. Users may finetune Granite 4.0 models for languages beyond these languages.

Intended use: The model is designed to respond to general instructions and can be used to build AI assistants for multiple domains, including business applications.

Capabilities

  • Summarization
  • Text classification
  • Text extraction
  • Question-answering
  • Retrieval Augmented Generation (RAG)
  • Code related tasks
  • Function-calling tasks
  • Multilingual dialog use cases
  • Fill-In-the-Middle (FIM) code completions

Generation: This is a simple example of how to use Granite-4.0-H-Small model.

Install the following libraries:

pip install torch torchvision torchaudio
pip install accelerate
pip install transformers

Then, copy the snippet from the section that is relevant for your use case.

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer

device = "cuda"
model_path = "ibm-granite/granite-4.0-h-small"
tokenizer = AutoTokenizer.from_pretrained(model_path)
# drop device_map if running on CPU
model = AutoModelForCausalLM.from_pretrained(model_path, device_map=device)
model.eval()
# change input text as desired
chat = [
    { "role": "user", "content": "Please list one IBM Research laboratory located in the United States. You should only output its name and location." },
]
chat = tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
# tokenize the text
input_tokens = tokenizer(chat, return_tensors="pt").to(device)
# generate output tokens
output = model.generate(**input_tokens, 
                        max_new_tokens=100)
# decode output tokens into text
output = tokenizer.batch_decode(output)
# print output
print(output[0])

Expected output:

<|start_of_role|>user<|end_of_role|>Please list one IBM Research laboratory located in the United States. You should only output its name and location.<|end_of_text|>
<|start_of_role|>assistant<|end_of_role|>Almaden Research Center, San Jose, California<|end_of_text|>

Tool-calling: Granite-4.0-H-Small comes with enhanced tool calling capabilities, enabling seamless integration with external functions and APIs. To define a list of tools please follow OpenAI's function definition schema.

This is an example of how to use Granite-4.0-H-Small model tool-calling ability:

tools = [
    {
        "type": "function",
        "function": {
            "name": "get_current_weather",
            "description": "Get the current weather for a specified city.",
            "parameters": {
                "type": "object",
                "properties": {
                    "city": {
                        "type": "string",
                        "description": "Name of the city"
                    }
                },
                "required": ["city"]
            }
        }
    }
]

# change input text as desired
chat = [
    { "role": "user", "content": "What's the weather like in Boston right now?" },
]
chat = tokenizer.apply_chat_template(chat, \
                                     tokenize=False, \
                                     tools=tools, \
                                     add_generation_prompt=True)
# tokenize the text
input_tokens = tokenizer(chat, return_tensors="pt").to(device)
# generate output tokens
output = model.generate(**input_tokens, 
                        max_new_tokens=100)
# decode output tokens into text
output = tokenizer.batch_decode(output)
# print output
print(output[0])

Expected output:

<|start_of_role|>system<|end_of_role|>You are a helpful assistant with access to the following tools. You may call one or more tools to assist with the user query.

You are provided with function signatures within <tools></tools> XML tags:
- <tools>
- unsloth
{"type": "function", "function": {"name": "get_current_weather", "description": "Get the current weather for a specified city.", "parameters": {"type": "object", "properties": {"city": {"type": "string", "description": "Name of the city"}}, "required": ["city"]}}}
</tools>

For each tool call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:
- <tool_call>
- unsloth
{"name": <function-name>, "arguments": <args-json-object>}
</tool_call>. If a tool does not exist in the provided list of tools, notify the user that you do not have the ability to fulfill the request.<|end_of_text|>
<|start_of_role|>user<|end_of_role|>What's the weather like in Boston right now?<|end_of_text|>
<|start_of_role|>assistant<|end_of_role|><tool_call>
{"name": "get_current_weather", "arguments": {"city": "Boston"}}
</tool_call><|end_of_text|>

Evaluation Results:

…(truncated — see the full README on HuggingFace)

BenchmarksMetricMicro DenseH Micro DenseH Tiny MoEH Small MoE
General Tasks
MMLU5-shot65.9867.4368.6578.44
MMLU-Pro5-shot, CoT44.543.4844.9455.47
BBH3-shot, CoT72.4869.3666.3481.62
AGI EVAL0-shot, CoT64.295962.1570.63
GPQA0-shot, CoT30.1432.1532.5940.63
Alignment Tasks
AlpacaEval 2.029.4931.4930.6142.48
IFEvalInstruct, Strict85.586.9484.7889.87
IFEvalPrompt, Strict79.1281.7178.185.22
IFEvalAverage82.3184.3281.4487.55
ArenaHard25.8436.1535.7546.48
Math Tasks
GSM8K8-shot85.4581.3584.6987.27
GSM8K Symbolic8-shot79.8277.581.187.38
Minerva Math0-shot, CoT62.0666.4469.6474
DeepMind Math0-shot, CoT44.5643.8349.9259.33
Code Tasks
HumanEvalpass@180818388
HumanEval+pass@172757683
MBPPpass@172738084
MBPP+pass@164646971
CRUXEval-Opass@141.541.2539.6350.25
BigCodeBenchpass@139.2137.941.0646.23
Tool Calling Tasks
BFCL v359.9857.5657.6564.69
Multilingual Tasks
MULTIPLEpass@149.2149.4655.8357.37
MMMLU5-shot55.1455.1961.8769.69
INCLUDE5-shot51.6250.5153.1263.97
MGSM8-shot28.5644.4845.3638.72
Safety
SALAD-Bench97.0696.2897.7797.3
AttaQ86.0584.44

Tag summary

Content type

Unrecognized

Digest

sha256:4d6714bbe

Size

18.2 GB

Last updated

7 days ago

docker pull ai/granite4

This week's pulls

Pulls:

4,955

Last week