模型概述
模型特點
模型能力
使用案例
🚀 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 助手,如業務應用 |
重要提示
⚠️ 重要提示
儘管模型在訓練過程中考慮了安全性,但在某些情況下,模型可能會產生不準確、有偏見或不安全的響應。因此,建議社區在使用該模型時進行適當的安全測試和調整。
使用建議
💡 使用建議
當處理非英語任務時,引入少量示例(少樣本學習)可以幫助模型生成更準確的輸出。



