evaluating-code-models について
evaluating-code-models スキルは、BigCode Evaluation Harness を使ったコード生成モデルの評価を研究者や開発者向けに案内します。多言語ベンチマーク、コード実行、pass@k の分析を扱います。
主な機能
- 01複数のコードベンチマーク
- 02MultiPL-E による多言語評価
- 03指示調整モデルの評価
- 04コード生成と実行
- 05pass@k の結果分析
活用シーン
- 01コード生成モデルを比較する
- 0218 言語の生成結果を評価する
- 03生成コードの機能的正しさを確認する
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ kalarislabs/ research-agent-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 のメモリ不足
# 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 | サンプリング温度 |
--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 リーダーボード:https://huggingface.co/spaces/bigcode/bigcode-models-leaderboard
- HumanEval データセット:https://huggingface.co/datasets/openai/openai_humaneval
- MultiPL-E:https://github.com/nuprl/MultiPL-E
エージェントの作業手順
- 環境を確認します。 モデル、チェックポイント、ベンチマークのバージョン、評価ハーネスのバージョンを確認します。
- 入力を特定します。 データまたはユーザーから、形式、識別子、パラメーターを確認します。結果に影響する値は推測せず、質問してください。
- まず小規模に実行します。 プロンプト、解析、スコアリングを検証するため、小さなサブセットで評価します。
- 上記の手順と参照資料を使用して、タスク全体を実行します。
- 結果を検証します。 ベンチマークの公式分割と指標を使用し、データ汚染がないか確認して、シードやプロンプトによるばらつきを報告します。
- 報告します。 実行した内容(バージョン、コマンド、パラメーター)、確認した内容、未確定事項を明記します。
| このような場合 | 対応 |
|---|---|
| スコアが公開済みの数値と異なる | 結論を出す前に、プロンプト形式、少数例の設定、ハーネスのバージョンを確認します。 |
| これらの手順に記載された関数、フラグ、エンドポイントがインストール済みのバージョンに存在しない | インストール済みバージョンのドキュメント(help()、--help、公式ドキュメント)を確認し、適宜対応してユーザーに伝えます。API を捏造してはいけません。 |
| 必須の入力、識別子、パラメーターが曖昧 | ユーザーに質問するか、実行前に仮定を明示します。 |
インテグリティに関するルール
- 結果、パラメーター、識別子、引用、統計を捏造してはいけません。実行または検証できない場合は、その旨を明確に伝えます。
- 評価設定をすべて報告し、プロンプト、シード、サブセットを都合よく選んではいけません。
- ここに記載されたバージョン固有の詳細は古くなっている可能性があるものとして扱い、インストール済みバージョンの公式ドキュメントで確認します。
- 費用が発生する、共有 GPU やクラウドのクォータを消費する、個人データや患者データにアクセスする、または取り消せない操作を行う前には、ユーザーに確認します。
Related skills
evaluating-llms-harness: Evaluates LLMs across 60+ academic benchmarks (MMLU, HumanEval, GSM8K, TruthfulQA, HellaSwag).nemo-evaluator-sdk: Evaluates LLMs across 100+ benchmarks from 18+ harnesses (MMLU, HumanEval, GSM8K, safety, VLM) with multi-backend execution.