Granite-3B-Code-Instruct-2K 是一个拥有 30 亿参数的模型,它基于 Granite-3B-Code-Base-2K 进行微调,训练数据为多种宽松许可的指令数据,旨在增强模型的指令遵循能力,包括逻辑推理和问题解决技能。
该模型旨在响应与编码相关的指令,可用于构建编码助手。
以下是使用 Granite-3B-Code-Instruct-2K 模型的简单示例。
import torch
from openmind import is_torch_npu_available, AutoModelForCausalLM, AutoTokenizer
if is_torch_npu_available():
device = "npu:0"
elif torch.cuda.is_available():
device = "cuda:0"
else:
device = "cpu"
model_path = "SY_AICC/granite-3b-code-instruct-2k"
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": "Write a code to find the maximum value in a list of numbers." },
]
chat = tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
# tokenize the text
input_tokens = tokenizer(chat, return_tensors="pt")
# transfer tokenized inputs to the device
for i in input_tokens:
input_tokens[i] = input_tokens[i].to(device)
# generate output tokens
output = model.generate(**input_tokens, max_new_tokens=100)
# decode output tokens into text
output = tokenizer.batch_decode(output)
# loop over the batch to print, in this example the batch size is 1
for i in output:
print(i)Granite Code Instruct 模型的训练数据包含以下几种类型。
我们使用 IBM 的两个超级计算集群(即 Vela 和 Blue Vela)来训练 Granite Code 模型,这两个集群分别配备了 NVIDIA A100 和 H100 GPU。这些集群提供了可扩展且高效的基础设施,支持我们在数千块 GPU 上进行模型训练。
Granite 代码指令模型主要是通过特定一组编程语言的指令-响应对进行微调的。因此,对于域外编程语言,其性能可能会受到限制。在这种情况下,提供少量示例以引导模型输出会有所帮助。此外,开发人员在将这些模型部署到关键应用之前,应进行安全测试和特定目标的调优。该模型还继承了其基础模型的伦理考量和局限性。欲了解更多信息,请参阅 Granite-3B-Code-Base-2K 模型卡片。