Windows 上評測 Gemma 4 26B:從零到可跑通
如果你和我一樣是在 Windows 環境,硬體是 AMD 顯示核心(例如 Radeon 8060S),又想評測 google/gemma-4-26b-a4b,最穩定的方式不是直接走 CUDA 路徑,而是:
- 由 LM Studio 載入模型負責推論
- 讓
lm-eval-harness透過 OpenAI-compatible API 呼叫 LM Studio - 用任務指令做基準測試與結果輸出
先釐清一個常見誤會
lm-eval validate --tasks hellaswag 只會驗證任務設定與資料集配置。 它不會檢查你的 API 是否連得上,也不會測模型推論。
所以正確流程是:
- 先
validate任務 - 再測
/v1/models與/v1/completions、/v1/chat/completions - 最後跑正式評測
你的情境最適合的路線
你的條件是:
- Windows
- AMD Radeon 8060S
- 模型:
google/gemma-4-26b-a4b - API 位址:
http://172.31.160.1:1234
在這種情境下,建議用:
local-chat-completions跑生成型任務(例如gsm8k)local-completions跑需要 logprobs 的任務(例如hellaswag)- 前提是
/v1/completions回傳中真的有logprobs
手動步驟版(先看懂流程)
1) 建立環境與安裝
git clone --depth 1 https://github.com/EleutherAI/lm-evaluation-harness.git
Set-Location .\lm-evaluation-harness
python -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install --upgrade pip setuptools wheel
pip install -e .
pip install "lm_eval[api]"
2) 驗證任務
lm-eval validate --tasks hellaswag
若指令找不到,改用:
python -m lm_eval validate --tasks hellaswag
3) 測 API 是否可達
Invoke-RestMethod -Uri "http://172.31.160.1:1234/v1/models" -Method Get
4) 先跑最容易成功的生成型測試(gsm8k)
lm-eval run --model local-chat-completions `
--model_args "model=google/gemma-4-26b-a4b,base_url=http://172.31.160.1:1234/v1/chat/completions,num_concurrent=1,max_retries=3" `
--tasks gsm8k `
--apply_chat_template `
--batch_size 1 `
--limit 20 `
--output_path ".\results\gemma4-gsm8k-chat" `
--log_samples
5) 檢查 hellaswag 所需的 logprobs 能不能用
$body = @{
model = "google/gemma-4-26b-a4b"
prompt = "The quick brown fox"
max_tokens = 1
temperature = 0
logprobs = 1
echo = $true
} | ConvertTo-Json -Depth 5
Invoke-RestMethod -Uri "http://172.31.160.1:1234/v1/completions" `
-Method Post -ContentType "application/json" -Body $body
如果回傳內有 choices[0].logprobs,才能跑 hellaswag。
6) 跑 hellaswag
lm-eval run --model local-completions `
--model_args "model=google/gemma-4-26b-a4b,base_url=http://172.31.160.1:1234/v1/completions,tokenized_requests=False,num_concurrent=1,max_retries=3" `
--tasks hellaswag `
--batch_size 1 `
--limit 100 `
--output_path ".\results\gemma4-hellaswag" `
--log_samples
一鍵執行版(可直接複製貼上)
下面整段可直接貼 PowerShell。 它會自動做:建 venv、安裝、validate、測 API、跑 gsm8k、偵測 logprobs、可用時跑 hellaswag。
# =========================
# lm-eval Windows 全流程腳本
# =========================
$ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest
# -------- 可調整參數 --------
$RepoUrl = "https://github.com/EleutherAI/lm-evaluation-harness.git"
$WorkDir = "$HOME\AI\lm-evaluation-harness"
$VenvDir = "$WorkDir\.venv"
$ApiBase = "http://172.31.160.1:1234"
$ModelId = "google/gemma-4-26b-a4b"
$LimitGsm8k = 20
$LimitHellaswag = 100
$RunTag = Get-Date -Format "yyyyMMdd-HHmmss"
$ResultRoot = Join-Path $WorkDir "results\$RunTag"
Write-Host "=== 開始執行 lm-eval 評測流程 ===" -ForegroundColor Cyan
# 允許本次 PowerShell Session 啟用 venv
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force | Out-Null
# 檢查必要工具
if (-not (Get-Command git -ErrorAction SilentlyContinue)) {
throw "找不到 git,請先安裝 Git for Windows。"
}
if (-not (Get-Command python -ErrorAction SilentlyContinue)) {
throw "找不到 python,請先安裝 Python 3.10+ 並加入 PATH。"
}
# 1) 下載或進入專案
if (-not (Test-Path $WorkDir)) {
Write-Host "下載專案到 $WorkDir" -ForegroundColor Yellow
git clone --depth 1 $RepoUrl $WorkDir
}
Set-Location $WorkDir
# 2) 若非 git 倉庫則初始化
if (-not (Test-Path (Join-Path $WorkDir ".git"))) {
Write-Host "偵測到不是 git 倉庫,正在初始化..." -ForegroundColor Yellow
git init | Out-Null
Write-Host "已完成 git 初始化。" -ForegroundColor Green
}
# 3) 建立虛擬環境
if (-not (Test-Path $VenvDir)) {
Write-Host "建立虛擬環境..." -ForegroundColor Yellow
python -m venv $VenvDir
}
$Py = Join-Path $VenvDir "Scripts\python.exe"
if (-not (Test-Path $Py)) {
throw "找不到虛擬環境 Python:$Py"
}
# 4) 安裝套件
Write-Host "安裝/更新套件中..." -ForegroundColor Yellow
& $Py -m pip install --upgrade pip setuptools wheel
& $Py -m pip install -e .
& $Py -m pip install "lm_eval[api]"
# 5) 驗證 task
Write-Host "執行 task 驗證:hellaswag" -ForegroundColor Yellow
& $Py -m lm_eval validate --tasks hellaswag
# 6) 檢查 API 連線與模型清單
Write-Host "檢查 LM Studio API:$ApiBase/v1/models" -ForegroundColor Yellow
$modelsResp = Invoke-RestMethod -Uri "$ApiBase/v1/models" -Method Get -TimeoutSec 30
$modelIds = @()
if ($modelsResp.data) {
$modelIds = @($modelsResp.data | ForEach-Object { $_.id })
}
Write-Host ("API 可見模型: " + ($modelIds -join ", ")) -ForegroundColor Gray
if ($modelIds.Count -eq 0) {
Write-Warning "API 可連線,但未讀到模型清單。請確認 LM Studio 已載入模型。"
}
elseif ($modelIds -notcontains $ModelId) {
Write-Warning "找不到指定模型 $ModelId。請確認 LM Studio 右側 API Model Identifier 完全一致。"
}
# 建立結果資料夾
New-Item -ItemType Directory -Path $ResultRoot -Force | Out-Null
# 7) 先跑 generate 類任務
$OutGsm8k = Join-Path $ResultRoot "gsm8k-chat"
Write-Host "開始評測 gsm8k(local-chat-completions)..." -ForegroundColor Yellow
& $Py -m lm_eval run `
--model local-chat-completions `
--model_args "model=$ModelId,base_url=$ApiBase/v1/chat/completions,num_concurrent=1,max_retries=3" `
--tasks gsm8k `
--apply_chat_template `
--batch_size 1 `
--limit $LimitGsm8k `
--output_path $OutGsm8k `
--log_samples
# 8) 測試 completions 端點是否支援 logprobs
$hasLogprobs = $false
Write-Host "檢查 /v1/completions 與 logprobs 支援..." -ForegroundColor Yellow
try {
$payload = @{
model = $ModelId
prompt = "The quick brown fox jumps over the lazy dog."
max_tokens = 1
temperature = 0
logprobs = 1
echo = $true
} | ConvertTo-Json -Depth 10
$compResp = Invoke-RestMethod `
-Uri "$ApiBase/v1/completions" `
-Method Post `
-ContentType "application/json" `
-Body $payload `
-TimeoutSec 60
if ($compResp.choices -and $compResp.choices.Count -gt 0 -and $null -ne $compResp.choices[0].logprobs) {
$hasLogprobs = $true
}
}
catch {
Write-Warning "測試 /v1/completions 或 logprobs 時發生錯誤:$($_.Exception.Message)"
}
# 9) 若支援 logprobs,跑 hellaswag
if ($hasLogprobs) {
$OutHella = Join-Path $ResultRoot "hellaswag-completions"
Write-Host "偵測到 logprobs 可用,開始評測 hellaswag(local-completions)..." -ForegroundColor Yellow
& $Py -m lm_eval run `
--model local-completions `
--model_args "model=$ModelId,base_url=$ApiBase/v1/completions,tokenized_requests=False,num_concurrent=1,max_retries=3" `
--tasks hellaswag `
--batch_size 1 `
--limit $LimitHellaswag `
--output_path $OutHella `
--log_samples
}
else {
Write-Warning "目前 API 不支援(或未正確回傳)logprobs,已跳過 hellaswag。"
Write-Warning "你仍可先使用 generate 類任務(例如 gsm8k)進行評測。"
}
Write-Host ""
Write-Host "=== 流程完成 ===" -ForegroundColor Green
Write-Host "結果目錄:$ResultRoot" -ForegroundColor Green
Write-Host "你可以用下列指令查看結果檔案:" -ForegroundColor Gray
Write-Host "Get-ChildItem -Path `"$ResultRoot`" -Recurse -File | Select-Object FullName"
常見錯誤與排查重點
- 出現
Loglikelihood is not supported for chat completions
代表你用local-chat-completions跑了hellaswag,請改用local-completions。 - 出現 404
多半是base_url路徑不對。 Chat 請用/v1/chat/completions,Completions 請用/v1/completions。 - 出現
model not foundmodel=必須與 LM Studio 的 API Model Identifier 完全一致。 validate成功但run失敗
正常,因為validate不測 API,需另做端點測試。
結語
在 Windows + AMD 顯示架構下,LM Studio API + lm-eval-harness 是目前最務實、可維護、可複現的評測組合。 先讓 gsm8k 跑通,再確認 logprobs 後挑戰 hellaswag,能大幅降低排錯成本,也更適合把流程自動化成固定基準測試。
參考資料
- 黃奇傑,〈(步驟3)工具介紹〉 https://chichieh-huang.com/posts/42628a4362f7/
















