File size: 12,479 Bytes
781cd65 26f880b 781cd65 26f880b 781cd65 26f880b 781cd65 26f880b 781cd65 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | #!/bin/bash
# ClawBenchPro base100/hard100 后处理评分。
# 可选在本机启动 OpenAI-compatible vLLM Judge,然后调用每题自带 verifier。
set -Eeo pipefail
set -x
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
BUNDLE_ROOT=/opt/huawei/dataset/zyr_yuyin/lyf/datasets/testClawBenchPro/upload_clawbenchpro_base100_hard100_npu
export WORK_DIR=${WORK_DIR:-${BUNDLE_ROOT}/verl}
export BASE_TASKS=${BASE_TASKS:-${BUNDLE_ROOT}/data/ClawBenchPro_base100_hard100_quality}
export INFERENCE_ROOT=${INFERENCE_ROOT:-/opt/huawei/dataset/zyr_yuyin/lyf/datasets/testClawBenchPro/output/qwen35_2b}
export SCORE_OUTPUT_ROOT=${SCORE_OUTPUT_ROOT:-${INFERENCE_ROOT}/scores}
export SETUP_ENVIRONMENT=${SETUP_ENVIRONMENT:-1}
# 留空表示评测 INFERENCE_ROOT 下所有含 step_1/ 的模型目录;也可逗号分隔。
export MODELS=${MODELS:-}
# JUDGE_ENABLED=0 只评 66 条规则任务,134 条 LLM Judge 任务会明确标记为 skipped。
export JUDGE_ENABLED=${JUDGE_ENABLED:-1}
# START_JUDGE_SERVER=1 在本机启动 vLLM;设为 0 时连接已有的兼容服务。
export START_JUDGE_SERVER=${START_JUDGE_SERVER:-1}
export JUDGE_MODEL_PATH=${JUDGE_MODEL_PATH:-/opt/huawei/dataset/zyr_yuyin/models/Qwen/Qwen3___5-9B}
export JUDGE_SERVED_MODEL_NAME=${JUDGE_SERVED_MODEL_NAME:-qwen35_9b_judge}
export JUDGE_BIND_HOST=${JUDGE_BIND_HOST:-127.0.0.1}
export JUDGE_PORT=${JUDGE_PORT:-8000}
export JUDGE_BASE_URL=${JUDGE_BASE_URL:-http://${JUDGE_BIND_HOST}:${JUDGE_PORT}/v1}
export JUDGE_API_KEY=${JUDGE_API_KEY:-dummy_key}
export JUDGE_DEVICES=${JUDGE_DEVICES:-0,1,2,3,4,5,6,7}
export JUDGE_TP=${JUDGE_TP:-8}
export JUDGE_DTYPE=${JUDGE_DTYPE:-bfloat16}
export JUDGE_MAX_MODEL_LEN=${JUDGE_MAX_MODEL_LEN:-32768}
export JUDGE_MAX_NUM_BATCHED_TOKENS=${JUDGE_MAX_NUM_BATCHED_TOKENS:-32768}
export JUDGE_MAX_NUM_SEQS=${JUDGE_MAX_NUM_SEQS:-128}
export JUDGE_GPU_MEMORY_UTILIZATION=${JUDGE_GPU_MEMORY_UTILIZATION:-0.80}
export JUDGE_STARTUP_TIMEOUT=${JUDGE_STARTUP_TIMEOUT:-1800}
export JUDGE_LOG=${JUDGE_LOG:-${SCORE_OUTPUT_ROOT}/judge.log}
export PARALLEL=${PARALLEL:-128}
export VERIFIER_TIMEOUT=${VERIFIER_TIMEOUT:-600}
export PASS_THRESHOLD=${PASS_THRESHOLD:-0.75}
export RESUME=${RESUME:-1}
export OVERWRITE=${OVERWRITE:-0}
export FAIL_ON_ERROR=${FAIL_ON_ERROR:-1}
if [ ! -f "${WORK_DIR}/recipe/nanoclaw/score_clawbenchpro.py" ]; then
echo "ERROR: scorer not found: ${WORK_DIR}/recipe/nanoclaw/score_clawbenchpro.py" >&2
exit 2
fi
if [ ! -f "${BASE_TASKS}/benchmark_manifest.json" ]; then
echo "ERROR: benchmark manifest not found: ${BASE_TASKS}/benchmark_manifest.json" >&2
exit 2
fi
if [ ! -d "${INFERENCE_ROOT}" ]; then
echo "ERROR: inference root not found: ${INFERENCE_ROOT}" >&2
exit 2
fi
if [ ! -f "${BUNDLE_ROOT}/scripts/setup_full_npu_environment.sh" ]; then
echo "ERROR: full NPU environment installer not found: ${BUNDLE_ROOT}/scripts/setup_full_npu_environment.sh" >&2
exit 2
fi
mkdir -p "${SCORE_OUTPUT_ROOT}" "$(dirname "${JUDGE_LOG}")"
# 只把完整通过磁盘审计的 checkpoint 交给评分器。残缺模型不能用部分题目
# 计算均分;它们由推理续跑脚本补齐后,再次运行本脚本即可自动纳入评分。
MODELS=$(python3 - "${INFERENCE_ROOT}" "${BASE_TASKS}/benchmark_manifest.json" "${MODELS}" <<'PY'
import json
import sys
from pathlib import Path
inference_root = Path(sys.argv[1])
manifest_path = Path(sys.argv[2])
requested_raw = sys.argv[3]
requested = {item.strip() for item in requested_raw.split(",") if item.strip()} or None
try:
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
task_ids = {str(item["task_id"]) for item in manifest["tasks"]}
except Exception as exc:
print(
f"ERROR: failed to load benchmark manifest {manifest_path}: {type(exc).__name__}: {exc}",
file=sys.stderr,
)
raise SystemExit(2)
def load_json(path: Path):
try:
value = json.loads(path.read_text(encoding="utf-8"))
except Exception:
return None
return value if isinstance(value, dict) else None
complete = []
discovered_names = set()
for model_dir in sorted(path for path in inference_root.iterdir() if path.is_dir()):
if not (model_dir / "step_1").is_dir():
continue
model_name = model_dir.name
discovered_names.add(model_name)
if requested is not None and model_name not in requested:
continue
result_dirs = sorted(
path for path in (model_dir / "step_1").glob("data_*_sample_*") if path.is_dir()
)
discovered_task_ids = {
path.name.rsplit("_sample_", 1)[0]
for path in result_dirs
if "_sample_" in path.name
}
missing = sorted(task_ids - discovered_task_ids)
extra = sorted(discovered_task_ids - task_ids)
issues = []
if missing:
issues.append(f"missing_tasks={len(missing)} first={missing[:5]}")
if extra:
issues.append(f"extra_tasks={len(extra)} first={extra[:5]}")
for result_dir in result_dirs:
if not (result_dir / "workspace_after").is_dir():
issues.append(f"missing_workspace={result_dir.name}")
metadata = load_json(result_dir / "nanoclaw_metadata.json")
if metadata is None:
issues.append(f"invalid_metadata={result_dir.name}")
elif metadata.get("status") != "ready":
issues.append(f"metadata_status={metadata.get('status')}:{result_dir.name}")
if load_json(result_dir / "conversation_history.json") is None:
issues.append(f"invalid_conversation={result_dir.name}")
if load_json(result_dir / "trajectory.json") is None:
issues.append(f"invalid_trajectory={result_dir.name}")
if len(issues) >= 20:
break
if issues:
print(
f"[score_skip_incomplete] model={model_name} issues={len(issues)} "
f"preview={' | '.join(issues[:8])}",
file=sys.stderr,
)
continue
complete.append(model_name)
print(
f"[score_include_complete] model={model_name} tasks={len(task_ids)} samples={len(result_dirs)}",
file=sys.stderr,
)
if requested is not None:
unknown = sorted(requested - discovered_names)
if unknown:
print(f"ERROR: requested model directories not found: {unknown}", file=sys.stderr)
raise SystemExit(2)
print(",".join(complete))
PY
)
export MODELS
if [ -z "${MODELS}" ]; then
echo "NO_COMPLETE_MODELS_TO_SCORE: incomplete checkpoints must finish inference before scoring."
exit 0
fi
echo "COMPLETE_MODELS_TO_SCORE=${MODELS}"
# Triton/vLLM 在 Judge 初始化 KV cache 前会通过 tempfile 创建 hivmc
# 探测文件。训练环境安装脚本历史上默认使用 /cache/ray_tmp,但该目录在
# 某些独立评分节点上不存在、不可写或已耗尽配额。评分任务使用独立临时
# 目录,允许通过 JUDGE_TMPDIR 覆盖,避免把 Judge 启动失败误报成评分失败。
export JUDGE_TMPDIR=${JUDGE_TMPDIR:-/tmp/clawbenchpro_judge_${USER:-unknown}_$$}
if [ -z "${TMPDIR:-}" ]; then
export TMPDIR="${JUDGE_TMPDIR}"
fi
if ! mkdir -p "${TMPDIR}" 2>/dev/null || [ ! -d "${TMPDIR}" ] || [ ! -w "${TMPDIR}" ]; then
echo "WARNING: configured TMPDIR is unavailable: ${TMPDIR}; falling back to ${JUDGE_TMPDIR}" >&2
export TMPDIR="${JUDGE_TMPDIR}"
mkdir -p "${TMPDIR}"
fi
if [ ! -d "${TMPDIR}" ] || [ ! -w "${TMPDIR}" ]; then
echo "ERROR: Judge temporary directory is not writable: ${TMPDIR}" >&2
df -h "$(dirname "${TMPDIR}")" >&2 || true
df -i "$(dirname "${TMPDIR}")" >&2 || true
exit 2
fi
export TEMP="${TMPDIR}"
export TMP="${TMPDIR}"
echo "Judge temporary directory: ${TMPDIR}"
# 默认与训练/推理一样完整安装 GCC、CANN、torch-npu、vLLM-Ascend、Triton、
# VERL 和 verifier 依赖。使用 source,确保导出的动态库和 Python 路径对 Judge 生效。
source "${BUNDLE_ROOT}/scripts/setup_full_npu_environment.sh"
cd "${BUNDLE_ROOT}"
# Probe the same Python tempfile path used by Triton before launching all TP
# workers. This produces a short actionable error instead of a long vLLM
# multiprocess traceback.
python3 - "${TMPDIR}" <<'PY'
import shutil
import sys
import tempfile
from pathlib import Path
tmpdir = Path(sys.argv[1])
try:
probe = Path(tempfile.mkdtemp(prefix="clawbenchpro_probe_", dir=str(tmpdir)))
(probe / "probe").write_text("ok", encoding="utf-8")
shutil.rmtree(probe)
except Exception as exc:
print(f"ERROR: Python/Triton temporary-file probe failed in {tmpdir}: {type(exc).__name__}: {exc}", file=sys.stderr)
raise SystemExit(2)
PY
judge_pid=""
cleanup() {
exit_code=$?
if [ -n "${judge_pid}" ]; then
kill "${judge_pid}" 2>/dev/null || true
wait "${judge_pid}" 2>/dev/null || true
fi
exit "${exit_code}"
}
trap cleanup EXIT INT TERM
check_judge() {
python3 -c 'import json,sys,urllib.request; req=urllib.request.Request(sys.argv[1].rstrip("/")+"/models",headers={"Authorization":"Bearer "+sys.argv[2]}); data=json.load(urllib.request.urlopen(req,timeout=10)); ids={str(x.get("id")) for x in data.get("data",[])}; raise SystemExit(0 if sys.argv[3] in ids else 1)' \
"${JUDGE_BASE_URL}" "${JUDGE_API_KEY}" "${JUDGE_SERVED_MODEL_NAME}" 2>/dev/null
}
if [ "${JUDGE_ENABLED}" = "1" ]; then
if [ "${START_JUDGE_SERVER}" = "1" ]; then
if [ -z "${JUDGE_MODEL_PATH}" ] || [ ! -d "${JUDGE_MODEL_PATH}" ]; then
echo "ERROR: set JUDGE_MODEL_PATH to a local Hugging Face Judge model directory." >&2
exit 2
fi
visible_count=$(awk -F, '{print NF}' <<< "${JUDGE_DEVICES}")
if [ "${JUDGE_TP}" -gt "${visible_count}" ]; then
echo "ERROR: JUDGE_TP=${JUDGE_TP} exceeds JUDGE_DEVICES count=${visible_count}." >&2
exit 2
fi
export ASCEND_RT_VISIBLE_DEVICES=${JUDGE_DEVICES}
judge_args=(
--model "${JUDGE_MODEL_PATH}"
--tokenizer "${JUDGE_MODEL_PATH}"
--served-model-name "${JUDGE_SERVED_MODEL_NAME}"
--host "${JUDGE_BIND_HOST}"
--port "${JUDGE_PORT}"
--tensor-parallel-size "${JUDGE_TP}"
--dtype "${JUDGE_DTYPE}"
--max-model-len "${JUDGE_MAX_MODEL_LEN}"
--max-num-batched-tokens "${JUDGE_MAX_NUM_BATCHED_TOKENS}"
--max-num-seqs "${JUDGE_MAX_NUM_SEQS}"
--gpu-memory-utilization "${JUDGE_GPU_MEMORY_UTILIZATION}"
)
echo "Starting Judge model: ${JUDGE_MODEL_PATH}"
python3 -m vllm.entrypoints.openai.api_server "${judge_args[@]}" >"${JUDGE_LOG}" 2>&1 &
judge_pid=$!
fi
started=$(date +%s)
until check_judge; do
if [ -n "${judge_pid}" ] && ! kill -0 "${judge_pid}" 2>/dev/null; then
echo "ERROR: Judge process exited before becoming ready. Log: ${JUDGE_LOG}" >&2
tail -n 160 "${JUDGE_LOG}" >&2 || true
exit 2
fi
elapsed=$(($(date +%s) - started))
if [ "${elapsed}" -ge "${JUDGE_STARTUP_TIMEOUT}" ]; then
echo "ERROR: Judge API did not become ready within ${JUDGE_STARTUP_TIMEOUT}s." >&2
tail -n 160 "${JUDGE_LOG}" >&2 || true
exit 2
fi
echo "Waiting for Judge API ${JUDGE_BASE_URL}; elapsed=${elapsed}s"
sleep 5
done
echo "Judge API ready: ${JUDGE_BASE_URL}, model=${JUDGE_SERVED_MODEL_NAME}"
else
echo "WARNING: JUDGE_ENABLED=0; 134 LLM Judge tasks will be skipped explicitly."
fi
score_args=(
python3 "${WORK_DIR}/recipe/nanoclaw/score_clawbenchpro.py"
--inference-root "${INFERENCE_ROOT}"
--base-tasks "${BASE_TASKS}"
--output-root "${SCORE_OUTPUT_ROOT}"
--models "${MODELS}"
--judge-enabled "${JUDGE_ENABLED}"
--judge-base-url "${JUDGE_BASE_URL}"
--judge-api-key "${JUDGE_API_KEY}"
--judge-model "${JUDGE_SERVED_MODEL_NAME}"
--parallel "${PARALLEL}"
--timeout "${VERIFIER_TIMEOUT}"
--pass-threshold "${PASS_THRESHOLD}"
--resume "${RESUME}"
--overwrite "${OVERWRITE}"
)
if [ "${FAIL_ON_ERROR}" = "1" ]; then
score_args+=(--fail-on-error)
fi
score_rc=0
"${score_args[@]}" || score_rc=$?
if [ "${score_rc}" -ne 0 ]; then
echo "ERROR: ClawBenchPro scoring failed with exit code ${score_rc}." >&2
exit "${score_rc}"
fi
echo "Scoring completed:"
echo " ${SCORE_OUTPUT_ROOT}/summary.json"
echo " ${SCORE_OUTPUT_ROOT}/leaderboard.csv"
echo " ${SCORE_OUTPUT_ROOT}/<model>/scoring_summary.json"
|