pipeline_tag: 文本生成
inference: false
license: apache-2.0
datasets:
- bigcode/commitpackft
- TIGER-Lab/MathInstruct
- meta-math/MetaMathQA
- glaiveai/glaive-code-assistant-v3
- glaive-function-calling-v2
- bugdaryan/sql-create-context-instruction
- garage-bAInd/Open-Platypus
- nvidia/HelpSteer
- bigcode/self-oss-instruct-sc2-exec-filter-50k
metrics:
- 代码评估
library_name: transformers
tags:
- 代码
- 花岗岩
model-index:
- name: granite-3b-code-instruct-128k
results:
- task:
type: 文本生成
dataset:
type: bigcode/humanevalpack
name: HumanEvalSynthesis (Python)
metrics:
- name: 通过率@1
type: 通过率@1
value: 53.7
verified: false
- task:
type: 文本生成
dataset:
type: bigcode/humanevalpack
name: HumanEvalSynthesis (平均)
metrics:
- name: 通过率@1
type: 通过率@1
value: 41.4
verified: false
- task:
type: 文本生成
dataset:
type: bigcode/humanevalpack
name: HumanEvalExplain (平均)
metrics:
- name: 通过率@1
type: 通过率@1
value: 25.1
verified: false
- task:
type: 文本生成
dataset:
type: bigcode/humanevalpack
name: HumanEvalFix (平均)
metrics:
- name: 通过率@1
type: 通过率@1
value: 26.2
verified: false
- task:
type: 文本生成
dataset:
type: repoqa
name: RepoQA (Python@16K)
metrics:
- name: 通过率@1 (阈值=0.5)
type: 通过率@1 (阈值=0.5)
value: 48.0
verified: false
- task:
type: 文本生成
dataset:
type: repoqa
name: RepoQA (C++@16K)
metrics:
- name: 通过率@1 (阈值=0.5)
type: 通过率@1 (阈值=0.5)
value: 36.0
verified: false
- task:
type: 文本生成
dataset:
type: repoqa
name: RepoQA (Java@16K)
metrics:
- name: 通过率@1 (阈值=0.5)
type: 通过率@1 (阈值=0.5)
value: 38.0
verified: false
- task:
type: 文本生成
dataset:
type: repoqa
name: RepoQA (TypeScript@16K)
metrics:
- name: 通过率@1 (阈值=0.5)
type: 通过率@1 (阈值=0.5)
value: 39.0
verified: false
- task:
type: 文本生成
dataset:
type: repoqa
name: RepoQA (Rust@16K)
metrics:
- name: 通过率@1 (阈值=0.5)
type: 通过率@1 (阈值=0.5)
value: 29.0
verified: false

Granite-3B-Code-Instruct-128K
模型概述
Granite-3B-Code-Instruct-128K 是一个拥有30亿参数的长上下文指令模型,基于Granite-3B-Code-Base-128K微调而来,结合了原始Granite代码指令模型训练中使用的宽松许可数据,以及为解决长上下文问题而量身定制的合成代码指令数据集。通过让模型接触短上下文和长上下文数据,我们的目标是在不牺牲短输入上下文代码生成性能的情况下增强其长上下文能力。
使用方式
预期用途
该模型设计用于响应长达128K长度的长上下文输入中的编码相关指令,可用于构建编码助手。
生成
以下是使用Granite-3B-Code-Instruct模型的简单示例。
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
device = "cuda"
model_path = "ibm-granite/granite-3b-code-instruct-128k"
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForCausalLM.from_pretrained(model_path, device_map=device)
model.eval()
chat = [
{ "role": "user", "content": "编写一个代码来查找数字列表中的最大值。" },
]
chat = tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
input_tokens = tokenizer(chat, return_tensors="pt")
for i in input_tokens:
input_tokens[i] = input_tokens[i].to(device)
output = model.generate(**input_tokens, max_new_tokens=100)
output = tokenizer.batch_decode(output)
for i in output:
print(i)
训练数据
Granite代码指令模型在以下短上下文和长上下文数据的混合上进行训练。
基础设施
我们使用IBM的两个超级计算集群Vela和Blue Vela训练Granite代码模型,这两个集群分别配备了NVIDIA A100和H100 GPU。这些集群为我们在数千个GPU上训练模型提供了可扩展且高效的基础设施。
伦理考量和限制
Granite代码指令模型主要通过特定编程语言的指令-响应对进行微调。因此,其在领域外编程语言上的表现可能有限。在这种情况下,提供少量示例有助于引导模型的输出。此外,开发者在将这些模型部署到关键应用之前应进行安全测试和针对性调优。该模型还继承了其基础模型的伦理考量和限制。更多信息请参考*Granite-3B-Code-Base-128K*模型卡片。