LLM 벤치마킹 퀵스타트
LLM 벤치마킹 퀵스타트 (LLM Benchmarking Quickstart)
benchmark_llm 템플릿은 할인 계산 작업에서 다양한 LLM 모델을 벤치마킹하고 비교해요. 프로젝트 생성부터 여러 모델의 정확도 비교까지 간단한 단계로 진행할 수 있어요.
출처: 문서
본문
benchmark_llm 템플릿은 할인 계산 작업에서 다양한 LLM 모델을 벤치마킹하고 비교해요.
프로젝트 만들기
ragas quickstart benchmark_llm
cd benchmark_llm
의존성 설치
uv sync
API 키 설정
export OPENAI_API_KEY="your-openai-key"
# 필요에 따라 다른 프로바이더 키
평가 실행
uv run python evals.py
특정 모델을 벤치마킹하려면:
uv run python evals.py --model gpt-4o
uv run python evals.py --model gpt-3.5-turbo
프로젝트 구조
benchmark_llm/
├── README.md # Project documentation
├── pyproject.toml # Project configuration
├── prompt.py # Prompt implementation
├── evals.py # Evaluation workflow
├── __init__.py # Python package marker
└── evals/
├── datasets/
│ └── discount_benchmark.csv # Customer profiles and expected discounts
├── experiments/ # Evaluation results
└── logs/ # Execution logs
무엇을 평가하나
템플릿은 구조화 출력 작업에서 LLM 성능을 벤치마킹해요.
- Task: 프로필을 바탕으로 고객 할인 비율 계산
- Models: GPT-4, GPT-3.5, Claude, Gemini 등 비교
- Output Format: 할인 비율이 있는 JSON
- Metric: 할인 정확도 (correct/incorrect)
코드 이해하기
프롬프트 (prompt.py)
고객 프로필에서 할인을 계산해요.
from prompt import run_prompt
profile = "Premium customer, 5 years tenure, $50k annual spend"
result = await run_prompt(profile, model="gpt-4o")
# Returns: {"discount_percentage": 15}
평가 (evals.py)
모델 정확도를 벤치마킹해요.
@discrete_metric(name="discount_accuracy", allowed_values=["correct", "incorrect"])
def discount_accuracy(prediction: str, expected_discount):
parsed_json = json.loads(prediction)
predicted_discount = parsed_json.get("discount_percentage")
if predicted_discount == int(expected_discount):
return MetricResult(value="correct", ...)
else:
return MetricResult(value="incorrect", ...)
테스트 데이터
템플릿에는 다음이 포함된 evals/datasets/discount_benchmark.csv가 있어요.
- 고객 프로필 (tenure, spend, tier 등)
- 기대 할인 비율
- 할인 계산용 비즈니스 규칙
여러 모델 벤치마킹
다양한 모델에서 동일한 평가를 실행해요.
# GPT-4
uv run python evals.py --model gpt-4o
# GPT-3.5
uv run python evals.py --model gpt-3.5-turbo
# Claude
uv run python evals.py --model claude-3-5-sonnet-20241022
# 결과 비교
커스터마이즈
자신만의 작업 추가
다른 역량을 벤치마킹하도록 프롬프트를 수정해요.
# Code generation
prompt = "Generate Python code to {task}"
# Summarization
prompt = "Summarize this text in 50 words: {text}"
# Classification
prompt = "Classify this email as spam/not-spam: {email}"
비용과 지연 시간 비교
추가 메트릭을 추적해요.
import time
start = time.time()
response = await run_prompt(profile, model=model_name)
latency = time.time() - start
# 정확도와 함께 비용 및 지연 시간 기록
결과 분석
모델 성능을 비교해요.
import pandas as pd
gpt4_results = pd.read_csv("evals/experiments/gpt4_benchmark.csv")
gpt35_results = pd.read_csv("evals/experiments/gpt35_benchmark.csv")
print(f"GPT-4 Accuracy: {(gpt4_results['discount_accuracy'] == 'correct').mean():.1%}")
print(f"GPT-3.5 Accuracy: {(gpt35_results['discount_accuracy'] == 'correct').mean():.1%}")
더 알아보기 (Learn more)
- Judge Alignment - 심판 정렬 측정
- Prompt Evaluation - 다양한 프롬프트 비교