ibm-granite/granite-4.1-8b · Hugging Face
摘要
IBM 发布 Granite-4.1-8B:Apache 2.0 许可的 80 亿参数长上下文 Instruct 模型,工具调用与多语言能力全面升级。
查看缓存全文
缓存时间: 2026/04/22 02:02
ibm-granite/granite-4.1-8b · Hugging Face
来源:https://huggingface.co/ibm-granite/granite-4.1-8b
mof-class3-qualified(https://mot.isitopen.ai/model/1160)
模型摘要:
Granite-4.1-8B 是一个 80 亿参数的长上下文指令模型,基于 Granite-4.1-8B-Base,在多种开源(宽松许可证)指令数据集以及内部合成数据上微调而来。Granite 4.1 系列经过升级的后训练流程,包括监督微调(SFT)与强化学习对齐,显著提升了工具调用、指令遵循与对话能力。
- **开发者:**Granite Team, IBM
- **HF 合集:**Granite 4.1 语言模型 HF 合集(https://huggingface.co/collections/ibm-granite/granite-40-language-models-6811a18b820ef362d9e5a82c)
- **技术博客:**Granite-4.1 博客(https://huggingface.co/blog/ibm-granite/granit-4-1)
- **GitHub 仓库:**ibm-granite/granite-4.1-language-models(https://github.com/ibm-granite/granite-4.1-language-models)
- **官网:**Granite 文档(https://www.ibm.com/granite/docs/)
- **发布日期:**2026 年 4 月 29 日
- **许可证:**Apache 2.0(https://www.apache.org/licenses/LICENSE-2.0)
支持语言:
英语、德语、西班牙语、法语、日语、葡萄牙语、阿拉伯语、捷克语、意大利语、韩语、荷兰语、中文。用户也可对 Granite 4.1 进行微调以支持更多语言。
预期用途:
模型旨在遵循通用指令,可作为多领域 AI 助手(含商业场景)的基础,也可用于具备工具调用能力的 LLM Agent。
能力
- 文本摘要
- 文本分类
- 信息抽取
- 问答
- 检索增强生成(RAG)
- 代码相关任务
- 函数调用任务
- 多语言对话
- Fill-In-the-Middle(FIM)代码补全
生成示例:
以下展示如何快速调用 Granite-4.1-8B 模型。先安装依赖:
pip install torch torchvision torchaudio
pip install accelerate
pip install transformers
随后复制对应场景的代码片段:
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
device = "cuda"
model_path = "ibm-granite/granite-4.1-8b"
tokenizer = AutoTokenizer.from_pretrained(model_path)
# 若在 CPU 运行,请去掉 device_map
model = AutoModelForCausalLM.from_pretrained(model_path, device_map=device)
model.eval()
# 按需修改输入
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)
input_tokens = tokenizer(chat, return_tensors="pt").to(device)
output = model.generate(**input_tokens, max_new_tokens=100)
output = tokenizer.batch_decode(output)
print(output[0])
预期输出:
<|start_of_role|>system<|end_of_role|>You are a helpful assistant. Please ensure responses are professional, accurate, and safe.<|end_of_text|>
<|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|>
工具调用:
Granite-4.1-8B 具备增强的工具调用能力,可无缝集成外部函数与 API。定义工具列表时请遵循 OpenAI 的函数定义模式(https://platform.openai.com/docs/guides/function-calling)。示例:
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
device = "cuda"
model_path = "ibm-granite/granite-4.1-8b"
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForCausalLM.from_pretrained(model_path, device_map=device)
model.eval()
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"]
}
}
}
]
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)
input_tokens = tokenizer(chat, return_tensors="pt").to(device)
output = model.generate(**input_tokens, max_new_tokens=100)
output = tokenizer.batch_decode(output)
print(output[0])
预期输出:
<|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 XML tags: {"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"]}}} For each tool call, return a json object with function name and arguments within XML tags: {"name": <name>, "arguments": <args>} . 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|> {"name": "get_current_weather", "arguments": {"city": "Boston"}} <|end_of_text|>
评测结果:
| 基准 | 指标 | 3B Dense | 8B Dense | 30B Dense |
|---|---|---|---|---|
| 通用任务 | ||||
| MMLU 5-shot | 67.02 | 73.84 | 80.16 | |
| MMLU-Pro 5-shot, CoT | 49.83 | 55.99 | 64.09 | |
| BBH 3-shot, CoT | 75.83 | 80.51 | 83.74 | |
| AGI Eval 0-shot, CoT | 65.16 | 72.43 | 77.80 | |
| GPQA 0-shot, CoT | 31.70 | 41.96 | 45.76 | |
| SimpleQA | 3.68 | 4.82 | 6.81 | |
| 对齐任务 | ||||
| AlpacaEval 2.0 | 38.57 | 50.08 | 56.16 | |
| IFEval Avg | 82.30 | 85.87 | 88.88 | |
| ArenaHard | 37.80 | 68.98 | 71.02 | |
| MTBench Avg | 7.57 | 8.61 | 8.61 | |
| 数学任务 | ||||
| GSM8K 8-shot | 86.88 | 92.49 | 94.16 | |
| GSM Symbolic 8-shot | 81.32 | 83.70 | 75.70 | |
| Minerva Math 0-shot, CoT | 67.94 | 80.10 | 81.32 | |
| DeepMind Math 0-shot, CoT | 64.64 | 80.07 | 81.93 | |
| 代码任务 | ||||
| HumanEval pass@1 | 81.71 | 85.37 | 88.41 | |
| HumanEval+ pass@1 | 76.83 | 79.88 | 85.37 | |
| MBPP pass@1 | 71.16 | 87.30 | 85.45 | |
| MBPP+ pass@1 | 62.17 | 73.81 | 73.54 | |
| CRUXEval-O pass@1 | 40.75 | 47.63 | 55.75 | |
| BigCodeBench pass@1 | 32.19 | 35.00 | 38.77 | |
| MULTIPLE pass@1 | 52.54 | 60.26 | 62.31 | |
| Eval+ Avg pass@1 | 67.05 | 80.21 | 82.66 | |
| 工具调用任务 | ||||
| BFCL v3 | 60.80 | 68.27 | 73.68 | |
| 多语言任务 | ||||
| MMMLU 5-shot | 57.61 | 64.84 | 73.71 | |
| INCLUDE 5-shot | 52.05 | 58.89 | 67.26 | |
| MGSM 8-shot | 70.00 | 82.32 | 71.12 | |
| 安全 | ||||
| SALAD-Bench | 93.95 | 95.80 | 96.41 | |
| AttaQ | 81.88 | 81.19 | 85.76 | |
| Tulu3 Safety Eval Avg | 66.84 | 75.57 | 78.19 |
多语言基准及所含语言:
| 基准 | 语言数量 | 语言 |
|---|---|---|
| MMMLU | 11 | ar, de, en, es, fr, ja, ko, pt, zh, bn, hi |
| INCLUDE | 14 | hi, bn, ta, te, ar, de, es, fr, it, ja, ko, nl, pt, zh |
| MGSM | 5 | en, es, fr, ja, zh |
模型架构:
Granite-4.1-8B 基线采用纯解码器稠密 Transformer 架构,核心组件包括 GQA、RoPE、SwiGLU MLP、RMSNorm 及共享输入/输出嵌入。
| 模型 | 3B Dense | 8B Dense | 30B Dense |
|---|---|---|---|
| Embedding size | 2560 | 4096 | 4096 |
| 层数 | 40 | 40 | 64 |
| Attention head size | 64 | 128 | 128 |
| Attention heads | 40 | 32 | 32 |
| KV heads | 8 | 8 | 8 |
| MLP 隐层 / 共享专家 | 8192 | 12800 | 32768 |
| MLP 激活 | SwiGLU | SwiGLU | SwiGLU |
| 序列长度 | 4096 | 4096 | 4096 |
| 位置编码 | RoPE | RoPE | RoPE |
| 参数量 | 3B | 8B | 30B |
训练数据:
SFT 数据主要来自三方面:
- 公开且许可证宽松的指令数据集
- 针对特定能力内部合成的数据
- 少量人工精标数据
监督微调与强化学习:
指令模型经过大幅改进的 SFT 与 RL 流程,使用上述高质量混合数据。通过多轮 SFT-RL 迭代,显著提升了工具调用、指令遵循与对话能力。详见 Granite-4.1 博客(https://huggingface.co/blog/ibm-granite/granit-4-1)。
基础设施:
Granite 4.1 语言模型在 CoreWeave 托管的 NVIDIA GB200 NVL72 集群上训练。单机柜内通过 72-GPU NVLink 域通信,机柜间采用无阻塞全 Fat-Tree NDR 400 Gb/s InfiniBand 网络,为数千 GPU 的可扩展高效训练提供保障。
伦理考量与限制:
Granite 4.1 指令模型主要使用英文学指令-回复对,同时包含多语言数据。尽管模型支持多语言对话,但在非英语场景下的表现可能不及英语任务,此时可引入少量示例(few-shot)提升准确性。虽然已进行安全对齐,模型仍可能输出不准确、有偏见或不安全的内容,建议社区针对具体任务进行充分的安全测试与调优。
资源
- ⭐️ 了解 Granite 最新动态:https://www.ibm.com/granite
- 📄 教程、最佳实践与提示工程指南:https://www.ibm.com/granite/docs/
- 💡 最新学习资源汇总:https://ibm.biz/granite-learning-resources
相似文章
IBM新款Granite 4.2模型乘势而上,引领本地大语言模型热潮
IBM发布了Granite 4.2,这是一系列开放权重大语言模型,提供高达300亿参数的版本,配备128,000个token的上下文窗口,并采用代理强化学习以增强能力。
IBM Granite Speech 5.0 2B
IBM 发布了 Granite Speech 5.0 2B,这是一款紧凑的多语言语音语言模型,支持六种语言的语音识别(ASR)和语音翻译,相比前代产品提升了噪声鲁棒性、语言识别提示(language-ID prompting)能力,并支持多达 2000 个关键词的偏置引导。
Granite 4.2 LLMs:构建原理
Granite 4.2是IBM推出的新型推理LLM系列,提供3B、8B和30B尺寸,具备思考模式、工具调用功能,并在Apache 2.0许可证下通过多阶段强化学习流水线进行训练。
Granite 4.0 3B Vision:面向企业文档的紧凑型多模态智能模型
IBM 发布 Granite 4.0 3B Vision,这是一款专为理解企业文档而设计的紧凑型视觉语言模型,具备表格提取、基于 ChartNet 的图表解读以及键值对 grounding 等专业能力。
ibm-granite/granite-switch-4.1 30B/8B
IBM 发布 Granite Switch 4.1 30B/8B,这是一个模块化 LLM,将基座模型、多个 aLoRA 适配器(决策、guardian)和语音编码器组合在一起,通过单个端点即可在聊天、通用/专业决策和语音转文本之间切换,采用 Apache 2.0 许可。