evaluating-code-models について
BigCode Evaluation Harnessは、HumanEval、MBPP、MultiPL-Eなどでコード生成モデルを評価するベンチマークツールです。生成コードの実行とpass@kの算出に加え、多言語評価や指示モデル、モデル比較に対応します。
主な機能
- 01複数のコードベンチマークに対応
- 0218言語での評価
- 03生成コードを実行しpass@kを算出
- 04指示モデル向けタスク
- 05生成結果の保存と読み込み
活用シーン
- 01複数のコード生成モデルの比較
- 02Pythonコード補完の評価
- 03言語をまたいだ生成品質の検証
- 04指示モデルのコード合成能力の確認
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ orchestra-research/ ai-research-skills --skill evaluating-code-modelsインストール後、Claude Code で/evaluating-code-modelsを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
references/benchmarks.mdcustom-tasks.mdissues.md詳細
BigCode Evaluation Harness - コードモデルのベンチマーク
クイックスタート
BigCode Evaluation Harness は、HumanEval、MBPP、MultiPL-E(18 言語)などを含む 15 種類以上のベンチマークでコード生成モデルを評価します。
インストール:
git clone https://github.com/bigcode-project/bigcode-evaluation-harness.git
cd bigcode-evaluation-harness
pip install -e .
accelerate config
HumanEval で評価:
accelerate launch main.py \
--model bigcode/starcoder2-7b \
--tasks humaneval \
--max_length_generation 512 \
--temperature 0.2 \
--n_samples 20 \
--batch_size 10 \
--allow_code_execution \
--save_generations
利用可能なタスクを表示:
python -c "from bigcode_eval.tasks import ALL_TASKS; print(ALL_TASKS)"
よくあるワークフロー
ワークフロー 1: 標準的なコードベンチマークによる評価
主要なコードベンチマーク(HumanEval、MBPP、HumanEval+)でモデルを評価します。
チェックリスト:
Code Benchmark Evaluation:
- [ ] Step 1: Choose benchmark suite
- [ ] Step 2: Configure model and generation
- [ ] Step 3: Run evaluation with code execution
- [ ] Step 4: Analyze pass@k results
ステップ 1: ベンチマークスイートを選択
Python のコード生成(最も一般的):
- HumanEval: 手書きの 164 問。関数補完
- HumanEval+: 同じ 164 問を、80 倍のテストで評価(より厳密)
- MBPP: クラウドソーシングで作成された 500 問。初級レベルの難易度
- MBPP+: 厳選された 399 問。35 倍のテストで評価
多言語(18 言語):
- MultiPL-E: HumanEval/MBPP を C++、Java、JavaScript、Go、Rust などに翻訳したもの
発展的なもの:
- APPS: 10,000 問(入門/面接/競技レベル)
- DS-1000: 7 つのライブラリにまたがる 1,000 問のデータサイエンス問題
ステップ 2: モデルと生成を設定
# Standard HuggingFace model
accelerate launch main.py \
--model bigcode/starcoder2-7b \
--tasks humaneval \
--max_length_generation 512 \
--temperature 0.2 \
--do_sample True \
--n_samples 200 \
--batch_size 50 \
--allow_code_execution
# Quantized model (4-bit)
accelerate launch main.py \
--model codellama/CodeLlama-34b-hf \
--tasks humaneval \
--load_in_4bit \
--max_length_generation 512 \
--allow_code_execution
# Custom/private model
accelerate launch main.py \
--model /path/to/my-code-model \
--tasks humaneval \
--trust_remote_code \
--use_auth_token \
--allow_code_execution
ステップ 3: 評価を実行
# Full evaluation with pass@k estimation (k=1,10,100)
accelerate launch main.py \
--model bigcode/starcoder2-7b \
--tasks humaneval \
--temperature 0.8 \
--n_samples 200 \
--batch_size 50 \
--allow_code_execution \
--save_generations \
--metric_output_path results/starcoder2-humaneval.json
ステップ 4: 結果を分析
results/starcoder2-humaneval.json に結果が出力されます:
{
"humaneval": {
"pass@1": 0.354,
"pass@10": 0.521,
"pass@100": 0.689
},
"config": {
"model": "bigcode/starcoder2-7b",
"temperature": 0.8,
"n_samples": 200
}
}
ワークフロー 2: 多言語評価(MultiPL-E)
18 のプログラミング言語にわたってコード生成を評価します。
チェックリスト:
Multi-Language Evaluation:
- [ ] Step 1: Generate solutions (host machine)
- [ ] Step 2: Run evaluation in Docker (safe execution)
- [ ] Step 3: Compare across languages
ステップ 1: ホスト上で解答を生成
# Generate without execution (safe)
accelerate launch main.py \
--model bigcode/starcoder2-7b \
--tasks multiple-py,multiple-js,multiple-java,multiple-cpp \
--max_length_generation 650 \
--temperature 0.8 \
--n_samples 50 \
--batch_size 50 \
--generation_only \
--save_generations \
--save_generations_path generations_multi.json
ステップ 2: Docker コンテナ内で評価
# Pull the MultiPL-E Docker image
docker pull ghcr.io/bigcode-project/evaluation-harness-multiple
# Run evaluation inside container
docker run -v $(pwd)/generations_multi.json:/app/generations.json:ro \
-it evaluation-harness-multiple python3 main.py \
--model bigcode/starcoder2-7b \
--tasks multiple-py,multiple-js,multiple-java,multiple-cpp \
--load_generations_path /app/generations.json \
--allow_code_execution \
--n_samples 50
対応言語: Python、JavaScript、Java、C++、Go、Rust、TypeScript、C#、PHP、Ruby、Swift、Kotlin、Scala、Perl、Julia、Lua、R、Racket
ワークフロー 3: 命令チューニング済みモデルの評価
チャット/命令モデルを適切なフォーマットで評価します。
チェックリスト:
Instruction Model Evaluation:
- [ ] Step 1: Use instruction-tuned tasks
- [ ] Step 2: Configure instruction tokens
- [ ] Step 3: Run evaluation
ステップ 1: 命令タスクを選択
- instruct-humaneval: 命令プロンプトを用いた HumanEval
- humanevalsynthesize-{lang}: HumanEvalPack の合成タスク
ステップ 2: 命令用トークンを設定
# For models with chat templates (e.g., CodeLlama-Instruct)
accelerate launch main.py \
--model codellama/CodeLlama-7b-Instruct-hf \
--tasks instruct-humaneval \
--instruction_tokens "<s>[INST],</s>,[/INST]" \
--max_length_generation 512 \
--allow_code_execution
ステップ 3: 命令モデル向けの HumanEvalPack
# Test code synthesis across 6 languages
accelerate launch main.py \
--model codellama/CodeLlama-7b-Instruct-hf \
--tasks humanevalsynthesize-python,humanevalsynthesize-js \
--prompt instruct \
--max_length_generation 512 \
--allow_code_execution
ワークフロー 4: 複数モデルの比較
モデル比較のためのベンチマークスイートです。
ステップ 1: 評価スクリプトを作成
#!/bin/bash
# eval_models.sh
MODELS=(
"bigcode/starcoder2-7b"
"codellama/CodeLlama-7b-hf"
"deepseek-ai/deepseek-coder-6.7b-base"
)
TASKS="humaneval,mbpp"
for model in "${MODELS[@]}"; do
model_name=$(echo $model | tr '/' '-')
echo "Evaluating $model"
accelerate launch main.py \
--model $model \
--tasks $TASKS \
--temperature 0.2 \
--n_samples 20 \
--batch_size 20 \
--allow_code_execution \
--metric_output_path results/${model_name}.json
done
ステップ 2: 比較表を生成
import json
import pandas as pd
models = ["bigcode-starcoder2-7b", "codellama-CodeLlama-7b-hf", "deepseek-ai-deepseek-coder-6.7b-base"]
results = []
for model in models:
with open(f"results/{model}.json") as f:
data = json.load(f)
results.append({
"Model": model,
"HumanEval pass@1": f"{data['humaneval']['pass@1']:.3f}",
"MBPP pass@1": f"{data['mbpp']['pass@1']:.3f}"
})
df = pd.DataFrame(results)
print(df.to_markdown(index=False))
使い分けと代替手段
BigCode Evaluation Harness を使うべき場合:
- 特にコード生成モデルを評価するとき
- 多言語評価が必要なとき(MultiPL-E による 18 言語)
- ユニットテストによる機能的正しさ(pass@k)を検証するとき
- BigCode/HuggingFace のリーダーボード向けにベンチマークするとき
- **穴埋め(fill-in-the-middle, FIM)**能力を評価するとき
代わりに使うべきもの:
- lm-evaluation-harness: 一般的な LLM ベンチマーク(MMLU、GSM8K、HellaSwag)
- EvalPlus: テストケースを増やした、より厳密な HumanEval+/MBPP+
- SWE-bench: 実際の GitHub の Issue 解決
- LiveCodeBench: データ汚染のない、継続的に更新される問題
- CodeXGLUE: コード理解タスク(クローン検出、欠陥予測)
対応ベンチマーク
| ベンチマーク | 問題数 | 言語 | 指標 | 用途 |
|---|---|---|---|---|
| HumanEval | 164 | Python | pass@k | 標準的なコード補完 |
| HumanEval+ | 164 | Python | pass@k | より厳密な評価(80 倍のテスト) |
| MBPP | 500 | Python | pass@k | 初級レベルの問題 |
| MBPP+ | 399 | Python | pass@k | より厳密な評価(35 倍のテスト) |
| MultiPL-E | 164×18 | 18 言語 | pass@k | 多言語評価 |
| APPS | 10,000 | Python | pass@k | 競技レベル |
| DS-1000 | 1,000 | Python | pass@k | データサイエンス(pandas、numpy など) |
| HumanEvalPack | 164×3×6 | 6 言語 | pass@k | 合成/修正/説明 |
| Mercury | 1,889 | Python | 効率性 | 計算効率 |
よくある問題
問題: 論文で報告された結果と異なる
以下の要素を確認してください:
# 1. Verify n_samples (need 200 for accurate pass@k)
--n_samples 200
# 2. Check temperature (0.2 for greedy-ish, 0.8 for sampling)
--temperature 0.8
# 3. Verify task name matches exactly
--tasks humaneval # Not "human_eval" or "HumanEval"
# 4. Check max_length_generation
--max_length_generation 512 # Increase for longer problems
問題: CUDA out of memory
# Use quantization
--load_in_8bit
# OR
--load_in_4bit
# Reduce batch size
--batch_size 1
# Set memory limit
--max_memory_per_gpu "20GiB"
問題: コードの実行がハングする、またはタイムアウトする
安全に実行するには Docker を使用してください:
# Generate on host (no execution)
--generation_only --save_generations
# Evaluate in Docker
docker run ... --allow_code_execution --load_generations_path ...
問題: 命令モデルのスコアが低い
命令形式が正しく適用されていることを確認してください:
# Use instruction-specific tasks
--tasks instruct-humaneval
# Set instruction tokens for your model
--instruction_tokens "<s>[INST],</s>,[/INST]"
問題: MultiPL-E の言語で失敗する
専用の Docker イメージを使用してください:
docker pull ghcr.io/bigcode-project/evaluation-harness-multiple
コマンドリファレンス
| 引数 | デフォルト | 説明 |
|---|---|---|
--model | - | HuggingFace のモデル ID またはローカルパス |
--tasks | - | カンマ区切りのタスク名 |
--n_samples | 1 | 問題ごとのサンプル数(pass@k の場合は 200) |
--temperature | 0.2 | サンプリングの temperature |
--max_length_generation | 512 | 最大トークン数(プロンプト + 生成) |
--batch_size | 1 | GPU あたりのバッチサイズ |
--allow_code_execution | False | コード実行を有効化(必須) |
--generation_only | False | 評価せずに生成のみを行う |
--load_generations_path | - | 事前に生成されたソリューションを読み込む |
--save_generations | False | 生成されたコードを保存する |
--metric_output_path | results.json | メトリクスの出力ファイル |
--load_in_8bit | False | 8 ビット量子化 |
--load_in_4bit | False | 4 ビット量子化 |
--trust_remote_code | False | カスタムモデルコードを許可する |
--precision | fp32 | モデルの精度(fp32/fp16/bf16) |
ハードウェア要件
| モデルサイズ | VRAM (fp16) | VRAM (4-bit) | 所要時間 (HumanEval, n=200) |
|---|---|---|---|
| 7B | 14GB | 6GB | 約 30 分 (A100) |
| 13B | 26GB | 10GB | 約 1 時間 (A100) |
| 34B | 68GB | 20GB | 約 2 時間 (A100) |
リソース
- GitHub: https://github.com/bigcode-project/bigcode-evaluation-harness
- ドキュメント: https://github.com/bigcode-project/bigcode-evaluation-harness/tree/main/docs
- BigCode Leaderboard: https://huggingface.co/spaces/bigcode/bigcode-models-leaderboard
- HumanEval Dataset: https://huggingface.co/datasets/openai/openai_humaneval
- MultiPL-E: https://github.com/nuprl/MultiPL-E