🚀 StarCoder2
StarCoder2は、600以上のプログラミング言語のコード生成に特化したモデルで、GitHubコードやArxiv、Wikipediaなどのデータを用いて訓練されています。
🚀 クイックスタート
モデル概要
StarCoder2-15Bモデルは、The Stack v2の600以上のプログラミング言語のコードを使って訓練された150億パラメータのモデルです。このモデルは、Grouped Query Attention、16,384トークンのコンテキストウィンドウ、4,096トークンのスライディングウィンドウアテンションを使用し、Fill-in-the-Middleオブジェクティブで4兆以上のトークンを用いて訓練されています。
モデルの使用
想定される使用方法
このモデルはGitHubのコードやArxiv、Wikipediaなどの追加データソースを使って訓練されています。したがって、命令型のモデルではなく、「平方根を計算する関数を書け」などのコマンドはうまく機能しません。
コード生成
以下は、モデルを使ってコード生成を開始するための例です。微調整用のスクリプトは、StarCoder2のGitHubリポジトリで見つけることができます。
まず、transformers
をソースからインストールする必要があります。
pip install git+https://github.com/huggingface/transformers.git
CPU/GPU/マルチGPUでのモデル実行
from transformers import AutoModelForCausalLM, AutoTokenizer
checkpoint = "bigcode/starcoder2-15b"
device = "cuda"
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
model = AutoModelForCausalLM.from_pretrained(checkpoint).to(device)
inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to(device)
outputs = model.generate(inputs)
print(tokenizer.decode(outputs[0]))
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
checkpoint = "bigcode/starcoder2-15b"
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto", torch_dtype=torch.bfloat16)
inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to("cuda")
outputs = model.generate(inputs)
print(tokenizer.decode(outputs[0]))
>>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")
Memory footprint: 32251.33 MB
bitsandbytes
を使用した量子化バージョン
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
quantization_config = BitsAndBytesConfig(load_in_8bit=True)
checkpoint = "bigcode/starcoder2-15b"
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
model = AutoModelForCausalLM.from_pretrained(checkpoint, quantization_config=quantization_config)
inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to("cuda")
outputs = model.generate(inputs)
print(tokenizer.decode(outputs[0]))
>>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")
Memory footprint: 16900.18 MB
>>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")
Memory footprint: 9224.60 MB
帰属とその他の要件
このモデルの事前学習データセットは、許容ライセンスのコードとライセンスのないコードのみでフィルタリングされています。それにもかかわらず、モデルはデータセットからそのままソースコードを生成することができます。コードのライセンスには、帰属やその他の特定の要件が必要な場合があり、それらを尊重する必要があります。私たちは、生成されたコードがどこから来たかを特定し、コードに適切な帰属を適用するために、事前学習データを検索できる検索インデックスを提供しています。
✨ 主な機能
モデルの制限
このモデルは600以上のプログラミング言語のソースコードで訓練されています。ソースコードの主な言語は英語ですが、他の言語も含まれています。したがって、モデルはある程度のコンテキストが与えられればコードスニペットを生成することができますが、生成されたコードが意図した通りに動作することは保証されていません。非効率であったり、バグや脆弱性を含んでいることがあります。モデルの制限についての詳細な議論は、論文を参照してください。
訓練
モデル
- アーキテクチャ: グループ化クエリとスライディングウィンドウアテンション、Fill-in-the-Middleオブジェクティブを持つTransformerデコーダ
- 事前学習ステップ: 100万
- 事前学習トークン: 4兆以上
- 精度: bfloat16
ハードウェア
ソフトウェア
📄 ライセンス
このモデルは、BigCode OpenRAIL-M v1ライセンス契約の下でライセンスされています。完全な契約はこちらで確認できます。
📚 ドキュメント
引用
@misc{lozhkov2024starcoder,
title={StarCoder 2 and The Stack v2: The Next Generation},
author={Anton Lozhkov and Raymond Li and Loubna Ben Allal and Federico Cassano and Joel Lamy-Poirier and Nouamane Tazi and Ao Tang and Dmytro Pykhtar and Jiawei Liu and Yuxiang Wei and Tianyang Liu and Max Tian and Denis Kocetkov and Arthur Zucker and Younes Belkada and Zijian Wang and Qian Liu and Dmitry Abulkhanov and Indraneil Paul and Zhuang Li and Wen-Ding Li and Megan Risdal and Jia Li and Jian Zhu and Terry Yue Zhuo and Evgenii Zheltonozhskii and Nii Osae Osae Dade and Wenhao Yu and Lucas Krauß and Naman Jain and Yixuan Su and Xuanli He and Manan Dey and Edoardo Abati and Yekun Chai and Niklas Muennighoff and Xiangru Tang and Muhtasham Oblokulov and Christopher Akiki and Marc Marone and Chenghao Mou and Mayank Mishra and Alex Gu and Binyuan Hui and Tri Dao and Armel Zebaze and Olivier Dehaene and Nicolas Patry and Canwen Xu and Julian McAuley and Han Hu and Torsten Scholak and Sebastien Paquet and Jennifer Robinson and Carolyn Jane Anderson and Nicolas Chapados and Mostofa Patwary and Nima Tajbakhsh and Yacine Jernite and Carlos Muñoz Ferrandis and Lingming Zhang and Sean Hughes and Thomas Wolf and Arjun Guha and Leandro von Werra and Harm de Vries},
year={2024},
eprint={2402.19173},
archivePrefix={arXiv},
primaryClass={cs.SE}
}