模型简介
模型特点
模型能力
使用案例
🚀 Granite-3.1-3B-A800M-Instruct
Granite-3.1-3B-A800M-Instruct 是一款拥有 30 亿参数的长上下文指令模型。它基于开源的指令数据集和内部合成数据集,对基础模型进行微调,旨在解决长上下文问题,可用于构建多领域的 AI 助手。
🚀 快速开始
安装依赖库
在使用 Granite-3.1-3B-A800M-Instruct 模型之前,需要安装以下库:
pip install torch torchvision torchaudio
pip install accelerate
pip install transformers
代码示例
以下是一个简单的使用示例,展示了如何使用该模型进行文本生成:
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
device = "auto"
model_path = "ibm-granite/granite-3.1-3b-a800m-Instruct"
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)
✨ 主要特性
多语言支持
支持英语、德语、西班牙语、法语、日语、葡萄牙语、阿拉伯语、捷克语、意大利语、韩语、荷兰语和中文等 12 种语言。用户还可以对模型进行微调,以支持更多语言。
广泛的任务能力
- 文本摘要:能够对长文本进行有效摘要。
- 文本分类:对文本进行分类。
- 信息提取:从文本中提取关键信息。
- 问答系统:回答用户的问题。
- 检索增强生成(RAG):结合检索信息进行文本生成。
- 代码相关任务:处理代码相关的任务。
- 函数调用任务:执行函数调用任务。
- 多语言对话:支持多语言的对话场景。
- 长上下文任务:处理长文档摘要、长文档问答等长上下文任务。
📦 安装指南
安装所需的库:
pip install torch torchvision torchaudio
pip install accelerate
pip install transformers
💻 使用示例
基础用法
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
device = "auto"
model_path = "ibm-granite/granite-3.1-3b-a800m-Instruct"
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)
📚 详细文档
评估结果
HuggingFace Open LLM Leaderboard V1
模型 | ARC-Challenge | Hellaswag | MMLU | TruthfulQA | Winogrande | GSM8K | 平均分 |
---|---|---|---|---|---|---|---|
Granite-3.1-8B-Instruct | 62.62 | 84.48 | 65.34 | 66.23 | 75.37 | 73.84 | 71.31 |
Granite-3.1-2B-Instruct | 54.61 | 75.14 | 55.31 | 59.42 | 67.48 | 52.76 | 60.79 |
Granite-3.1-3B-A800M-Instruct | 50.42 | 73.01 | 52.19 | 49.71 | 64.87 | 48.97 | 56.53 |
Granite-3.1-1B-A400M-Instruct | 42.66 | 65.97 | 26.13 | 46.77 | 62.35 | 33.88 | 46.29 |
HuggingFace Open LLM Leaderboard V2
模型 | IFEval | BBH | MATH Lvl 5 | GPQA | MUSR | MMLU-Pro | 平均分 |
---|---|---|---|---|---|---|---|
Granite-3.1-8B-Instruct | 72.08 | 34.09 | 21.68 | 8.28 | 19.01 | 28.19 | 30.55 |
Granite-3.1-2B-Instruct | 62.86 | 21.82 | 11.33 | 5.26 | 4.87 | 20.21 | 21.06 |
Granite-3.1-3B-A800M-Instruct | 55.16 | 16.69 | 10.35 | 5.15 | 2.51 | 12.75 | 17.1 |
Granite-3.1-1B-A400M-Instruct | 46.86 | 6.18 | 4.08 | 0 | 0.78 | 2.41 | 10.05 |
模型架构
Granite-3.1-3B-A800M-Instruct 基于仅解码器的密集 Transformer 架构,核心组件包括 GQA 和 RoPE、带有 SwiGLU 的 MLP、RMSNorm 以及共享的输入/输出嵌入。
模型参数 | 2B Dense | 8B Dense | 1B MoE | 3B MoE |
---|---|---|---|---|
嵌入大小 | 2048 | 4096 | 1024 | 1536 |
层数 | 40 | 40 | 24 | 32 |
注意力头大小 | 64 | 128 | 64 | 64 |
注意力头数量 | 32 | 32 | 16 | 24 |
KV 头数量 | 8 | 8 | 8 | 8 |
MLP 隐藏大小 | 8192 | 12800 | 512 | 512 |
MLP 激活函数 | SwiGLU | SwiGLU | SwiGLU | SwiGLU |
专家数量 | — | — | 32 | 40 |
MoE TopK | — | — | 8 | 8 |
初始化标准差 | 0.1 | 0.1 | 0.1 | 0.1 |
序列长度 | 128K | 128K | 128K | 128K |
位置嵌入 | RoPE | RoPE | RoPE | RoPE |
参数数量 | 2.5B | 8.1B | 1.3B | 3.3B |
活跃参数数量 | 2.5B | 8.1B | 400M | 800M |
训练令牌数量 | 12T | 12T | 10T | 10T |
训练数据
SFT 数据主要来自三个关键来源:
- 具有宽松许可的公开可用数据集。
- 针对特定能力(包括长上下文任务)的内部合成数据。
- 少量人工策划的数据。
详细的数据集归因可在 Granite 3.0 技术报告、Granite 3.1 技术报告(即将发布) 和 作者列表 中找到。
基础设施
使用 IBM 的超级计算集群 Blue Vela 训练 Granite 3.1 语言模型,该集群配备了 NVIDIA H100 GPU,为模型训练提供了可扩展且高效的基础设施。
伦理考量与局限性
- 多语言性能:虽然模型支持多语言对话,但在非英语任务上的性能可能不如英语任务。引入少量示例(少样本学习)可以帮助模型生成更准确的输出。
- 安全性:尽管模型在训练过程中考虑了安全性,但在某些情况下,模型可能会产生不准确、有偏见或不安全的响应。因此,建议社区在使用该模型时进行适当的安全测试和调整。
资源链接
- 了解最新更新:https://www.ibm.com/granite
- 入门教程和最佳实践:https://www.ibm.com/granite/docs/
- 最新学习资源:https://ibm.biz/granite-learning-resources
🔧 技术细节
Granite-3.1-3B-A800M-Instruct 基于仅解码器的密集 Transformer 架构,核心组件包括 GQA 和 RoPE、带有 SwiGLU 的 MLP、RMSNorm 以及共享的输入/输出嵌入。这种架构设计使得模型在处理长上下文任务时具有更好的性能。
📄 许可证
本模型采用 Apache 2.0 许可证。
模型基本信息
属性 | 详情 |
---|---|
模型类型 | 基于 Transformer 架构的长上下文指令模型 |
训练数据 | 公开数据集、内部合成数据和少量人工策划数据 |
支持语言 | 英语、德语、西班牙语、法语、日语、葡萄牙语、阿拉伯语、捷克语、意大利语、韩语、荷兰语和中文 |
预期用途 | 构建多领域的 AI 助手,如业务应用 |
重要提示
⚠️ 重要提示
尽管模型在训练过程中考虑了安全性,但在某些情况下,模型可能会产生不准确、有偏见或不安全的响应。因此,建议社区在使用该模型时进行适当的安全测试和调整。
使用建议
💡 使用建议
当处理非英语任务时,引入少量示例(少样本学习)可以帮助模型生成更准确的输出。



