LM Evaluation Harness 빠른 시작 — CLI로 모델 평가하기

LM Evaluation Harness 빠른 시작 — CLI로 모델 평가하기

LM Evaluation Harness는 다양한 생성형 언어 모델을 표준 벤치마크에서 평가하는 통합 프레임워크예요. 60개 이상의 공개 학술 벤치마크와 수백 개의 서브태스크가 구현되어 있고, transformers·GPT-NeoX·Megatron-DeepSpeed·vLLM 그리고 OpenAI 같은 상용 API까지 지원합니다.

출처: https://github.com/EleutherAI/lm-evaluation-harness

설치

기본 평가 프레임워크를 설치한 뒤, 사용할 모델 백엔드는 별도 옵션으로 추가 설치합니다.

git clone --depth 1 https://github.com/EleutherAI/lm-evaluation-harness
cd lm-evaluation-harness
pip install -e .
pip install "lm_eval[hf]"       # HuggingFace transformers
pip install "lm_eval[vllm]"     # vLLM
pip install "lm_eval[api]"      # OpenAI·Anthropic 등 API

여러 백엔드는 함께 설치할 수도 있어요: pip install "lm_eval[hf,vllm,api]"

CLI로 평가하기

사용 가능한 옵션은 lm-eval -h로, 작업 목록은 lm-eval ls tasks로 확인할 수 있어요. Hugging Face Hub에 있는 모델을 hellaswag 작업에서 평가하는 명령은 이렇습니다.

lm_eval --model hf \
    --model_args pretrained=EleutherAI/gpt-j-6B \
    --tasks hellaswag \
    --device cuda:0 \
    --batch_size 8

--model_args로 체크포인트 리비전이나 데이터 타입 같은 추가 인자를 넘길 수 있어요. Hub의 리비전 기능으로 부분 학습 체크포인트를 지정하는 것도 흔한 패턴입니다.

lm_eval --model hf \
    --model_args pretrained=EleutherAI/pythia-160m,revision=step100000,dtype="float" \
    --tasks lambada_openai,hellaswag \
    --device cuda:0 \
    --batch_size 8

--batch_size auto는 기기에 맞는 최대 배치 크기를 자동 탐지합니다. 예제 길이 차이가 큰 작업에서는 auto:4처럼 리컴퓨트 횟수를 붙여 주기적으로 재계산하면 더 빠르게 돼요.

GGUF 모델 평가와 멀티 GPU

GGUF 형식 모델도 hf 백엔드로 평가할 수 있어요. 가중치 폴더 경로와 gguf_file, 가능하면 별도 tokenizer 를 지정하세요. 토크나이저를 별도로 안 넘기면 HF가 GGUF 파일에서 재구성하려다 몇 시간이 걸릴 수 있습니다.

lm_eval --model hf \
    --model_args pretrained=/path/to/gguf_folder,gguf_file=model-name.gguf,tokenizer=/path/to/tokenizer \
    --tasks hellaswag \
    --device cuda:0 \
    --batch_size 8

멀티 GPU는 accelerate를 씁니다. 데이터 병렬(각 GPU가 모델 전체 복사본)은 accelerate launch -m lm_eval로, 한 GPU에 안 들어가는 큰 모델은 --model_args parallelize=True로 가중치를 여러 GPU에 나눠 담는 식이에요. 둘을 합칠 수도 있습니다.

더 알아보기