pipeline_tag: 文本生成
base_model: bigcode/starcoder2-15b
datasets:
- bigcode/self-oss-instruct-sc2-exec-filter-50k
license: bigcode-openrail-m
library_name: transformers
tags:
- 代码
model-index:
- name: starcoder2-15b-instruct-v0.1
results:
- task:
type: 文本生成
dataset:
name: LiveCodeBench(代码生成)
type: livecodebench-codegeneration
metrics:
- task:
type: 文本生成
dataset:
name: LiveCodeBench(自我修复)
type: livecodebench-selfrepair
metrics:
- task:
type: 文本生成
dataset:
name: LiveCodeBench(测试输出预测)
type: livecodebench-testoutputprediction
metrics:
- task:
type: 文本生成
dataset:
name: LiveCodeBench(代码执行)
type: livecodebench-codeexecution
metrics:
- task:
type: 文本生成
dataset:
name: HumanEval
type: humaneval
metrics:
- task:
type: 文本生成
dataset:
name: HumanEval+
type: humanevalplus
metrics:
- task:
type: 文本生成
dataset:
name: MBPP
type: mbpp
metrics:
- task:
type: 文本生成
dataset:
name: MBPP+
type: mbppplus
metrics:
- task:
type: 文本生成
dataset:
name: DS-1000
type: ds-1000
metrics:
StarCoder2-Instruct:完全透明开放的代码生成自对齐方案

模型概要
我们推出StarCoder2-15B-Instruct-v0.1,这是首个完全通过开放透明流程训练的自对齐代码大语言模型(LLM)。我们的开源流程使用StarCoder2-15B生成数千条指令-响应对,随后用这些数据对StarCoder-15B自身进行微调,全程无需人工标注或来自闭源大模型的蒸馏数据。

引用文献
@article{wei2024selfcodealign,
title={SelfCodeAlign: 代码生成的自对齐方法},
author={Yuxiang Wei and Federico Cassano and Jiawei Liu and Yifeng Ding and Naman Jain and Zachary Mueller and Harm de Vries and Leandro von Werra and Arjun Guha and Lingming Zhang},
year={2024},
journal={arXiv预印本 arXiv:2410.24198}
}
使用指南
适用范围
本模型专为单轮编程指令响应设计。其他风格的指令可能导致响应准确性下降。
以下是使用transformers库的快速入门示例:
import transformers
import torch
pipeline = transformers.pipeline(
model="bigcode/starcoder2-15b-instruct-v0.1",
task="text-generation",
torch_dtype=torch.bfloat16,
device_map="auto",
)
def respond(instruction: str, response_prefix: str) -> str:
messages = [{"role": "user", "content": instruction}]
prompt = pipeline.tokenizer.apply_chat_template(messages, tokenize=False)
prompt += response_prefix
teminators = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("###"),
]
result = pipeline(
prompt,
max_length=256,
num_return_sequences=1,
do_sample=False,
eos_token_id=teminators,
pad_token_id=pipeline.tokenizer.eos_token_id,
truncation=True,
)
response = response_prefix + result[0]["generated_text"][len(prompt) :].split("###")[0].rstrip()
return response
instruction = "用Python编写带类型提示的快速排序函数,并添加'less_than'参数支持自定义排序条件。"
response_prefix = ""
print(respond(instruction, response_prefix))
预期输出示例:
以下是实现带类型提示和支持自定义排序条件的Python快速排序函数:
```python
from typing import TypeVar, Callable
T = TypeVar('T')
def quicksort(items: list[T], less_than: Callable[[T, T], bool] = lambda x, y: x < y) -> list[T]:
if len(items) <= 1:
return items
pivot = items[0]
less = [x for x in items[1:] if less_than(x, pivot)]
greater = [x for x in items[1:] if not less_than(x, pivot)]
return quicksort(less, less_than) + [pivot] + quicksort(greater, less_than)
```
偏差、风险与局限
StarCoder2-15B-Instruct-v0.1主要针对可通过执行验证的Python代码生成任务进行微调,这可能导致某些偏差和限制。例如,模型可能不会严格遵循输出格式要求的指令。这类情况下,提供响应前缀或单样本示例有助于引导模型输出。此外,该模型对其他编程语言和领域外编码任务可能存在局限。
本模型也继承了基础模型StarCoder2-15B的偏差、风险和限制,详细信息请参阅StarCoder2-15B模型卡片。
EvalPlus、LiveCodeBench和DS-1000评估表现


训练详情
超参数配置
- 优化器: Adafactor
- 学习率: 1e-5
- 训练轮次: 4
- 批大小: 64
- 预热比例: 0.05
- 调度器: 线性
- 序列长度: 1280
- Dropout: 未启用
硬件配置
1×NVIDIA A100 80GB
资源索引
完整数据流程
我们的数据集生成流程包含多个步骤,每个步骤均提供中间数据集:
- 从The Stack v1筛选的原始种子数据集:https://huggingface.co/datasets/bigcode/python-stack-v1-functions-filtered
- 使用StarCoder2-15B作为评判器过滤掉文档字符串质量差的条目:https://huggingface.co/datasets/bigcode/python-stack-v1-functions-filtered-sc2
- 种子→概念转换:https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-concepts
- 概念→指令转换:https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-instructions
- 指令→响应生成:https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-responses-unfiltered
- 通过执行过滤响应:https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-500k-raw
- 去重处理后最终数据集:https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k