geminiDeveloper commited on
Commit
781cd65
·
verified ·
1 Parent(s): 011abf2

Create score_clawbenchpro.sh

Browse files
Files changed (1) hide show
  1. sc1/score_clawbenchpro.sh +203 -0
sc1/score_clawbenchpro.sh ADDED
@@ -0,0 +1,203 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # ClawBenchPro base100/hard100 后处理评分。
3
+ # 可选在本机启动 OpenAI-compatible vLLM Judge,然后调用每题自带 verifier。
4
+
5
+ set -x
6
+
7
+ SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
8
+ BUNDLE_ROOT=/opt/huawei/dataset/zyr_yuyin/lyf/datasets/testClawBenchPro/upload_clawbenchpro_base100_hard100_npu
9
+
10
+ export WORK_DIR=${WORK_DIR:-${BUNDLE_ROOT}/verl}
11
+ export BASE_TASKS=${BASE_TASKS:-${BUNDLE_ROOT}/data/ClawBenchPro_base100_hard100_quality}
12
+ export INFERENCE_ROOT=${INFERENCE_ROOT:-/opt/huawei/dataset/zyr_yuyin/lyf/datasets/testClawBenchPro/output/qwen35_2b}
13
+ export SCORE_OUTPUT_ROOT=${SCORE_OUTPUT_ROOT:-${INFERENCE_ROOT}/scores}
14
+ export SETUP_ENVIRONMENT=${SETUP_ENVIRONMENT:-1}
15
+
16
+ # 留空表示评测 INFERENCE_ROOT 下所有含 step_1/ 的模型目录;也可逗号分隔。
17
+ export MODELS=${MODELS:-}
18
+
19
+ # JUDGE_ENABLED=0 只评 66 条规则任务,134 条 LLM Judge 任务会明确标记为 skipped。
20
+ export JUDGE_ENABLED=${JUDGE_ENABLED:-1}
21
+ # START_JUDGE_SERVER=1 在本机启动 vLLM;设为 0 时连接已有的兼容服务。
22
+ export START_JUDGE_SERVER=${START_JUDGE_SERVER:-1}
23
+ export JUDGE_MODEL_PATH=${JUDGE_MODEL_PATH:-/opt/huawei/dataset/zyr_yuyin/models/Qwen/Qwen3___5-9B}
24
+ export JUDGE_SERVED_MODEL_NAME=${JUDGE_SERVED_MODEL_NAME:-qwen35_9b_judge}
25
+ export JUDGE_BIND_HOST=${JUDGE_BIND_HOST:-127.0.0.1}
26
+ export JUDGE_PORT=${JUDGE_PORT:-8000}
27
+ export JUDGE_BASE_URL=${JUDGE_BASE_URL:-http://${JUDGE_BIND_HOST}:${JUDGE_PORT}/v1}
28
+ export JUDGE_API_KEY=${JUDGE_API_KEY:-dummy_key}
29
+ export JUDGE_DEVICES=${JUDGE_DEVICES:-0,1,2,3,4,5,6,7}
30
+ export JUDGE_TP=${JUDGE_TP:-8}
31
+ export JUDGE_DTYPE=${JUDGE_DTYPE:-bfloat16}
32
+ export JUDGE_MAX_MODEL_LEN=${JUDGE_MAX_MODEL_LEN:-32768}
33
+ export JUDGE_MAX_NUM_BATCHED_TOKENS=${JUDGE_MAX_NUM_BATCHED_TOKENS:-32768}
34
+ export JUDGE_MAX_NUM_SEQS=${JUDGE_MAX_NUM_SEQS:-128}
35
+ export JUDGE_GPU_MEMORY_UTILIZATION=${JUDGE_GPU_MEMORY_UTILIZATION:-0.80}
36
+ export JUDGE_STARTUP_TIMEOUT=${JUDGE_STARTUP_TIMEOUT:-1800}
37
+ export JUDGE_LOG=${JUDGE_LOG:-${SCORE_OUTPUT_ROOT}/judge.log}
38
+
39
+ export PARALLEL=${PARALLEL:-128}
40
+ export VERIFIER_TIMEOUT=${VERIFIER_TIMEOUT:-600}
41
+ export PASS_THRESHOLD=${PASS_THRESHOLD:-0.75}
42
+ export RESUME=${RESUME:-1}
43
+ export OVERWRITE=${OVERWRITE:-0}
44
+ export FAIL_ON_ERROR=${FAIL_ON_ERROR:-1}
45
+
46
+ if [ ! -f "${WORK_DIR}/recipe/nanoclaw/score_clawbenchpro.py" ]; then
47
+ echo "ERROR: scorer not found: ${WORK_DIR}/recipe/nanoclaw/score_clawbenchpro.py" >&2
48
+ exit 2
49
+ fi
50
+ if [ ! -f "${BASE_TASKS}/benchmark_manifest.json" ]; then
51
+ echo "ERROR: benchmark manifest not found: ${BASE_TASKS}/benchmark_manifest.json" >&2
52
+ exit 2
53
+ fi
54
+ if [ ! -d "${INFERENCE_ROOT}" ]; then
55
+ echo "ERROR: inference root not found: ${INFERENCE_ROOT}" >&2
56
+ exit 2
57
+ fi
58
+ if [ ! -f "${BUNDLE_ROOT}/scripts/setup_full_npu_environment.sh" ]; then
59
+ echo "ERROR: full NPU environment installer not found: ${BUNDLE_ROOT}/scripts/setup_full_npu_environment.sh" >&2
60
+ exit 2
61
+ fi
62
+
63
+ mkdir -p "${SCORE_OUTPUT_ROOT}" "$(dirname "${JUDGE_LOG}")"
64
+
65
+ # Triton/vLLM 在 Judge 初始化 KV cache 前会通过 tempfile 创建 hivmc
66
+ # 探测文件。训练环境安装脚本历史上默认使用 /cache/ray_tmp,但该目录在
67
+ # 某些独立评分节点上不存在、不可写或已耗尽配额。评分任务使用独立临时
68
+ # 目录,允许通过 JUDGE_TMPDIR 覆盖,避免把 Judge 启动失败误报成评分失败。
69
+ export JUDGE_TMPDIR=${JUDGE_TMPDIR:-/tmp/clawbenchpro_judge_${USER:-unknown}_$$}
70
+ if [ -z "${TMPDIR:-}" ]; then
71
+ export TMPDIR="${JUDGE_TMPDIR}"
72
+ fi
73
+ if ! mkdir -p "${TMPDIR}" 2>/dev/null || [ ! -d "${TMPDIR}" ] || [ ! -w "${TMPDIR}" ]; then
74
+ echo "WARNING: configured TMPDIR is unavailable: ${TMPDIR}; falling back to ${JUDGE_TMPDIR}" >&2
75
+ export TMPDIR="${JUDGE_TMPDIR}"
76
+ mkdir -p "${TMPDIR}"
77
+ fi
78
+ if [ ! -d "${TMPDIR}" ] || [ ! -w "${TMPDIR}" ]; then
79
+ echo "ERROR: Judge temporary directory is not writable: ${TMPDIR}" >&2
80
+ df -h "$(dirname "${TMPDIR}")" >&2 || true
81
+ df -i "$(dirname "${TMPDIR}")" >&2 || true
82
+ exit 2
83
+ fi
84
+ export TEMP="${TMPDIR}"
85
+ export TMP="${TMPDIR}"
86
+ echo "Judge temporary directory: ${TMPDIR}"
87
+
88
+ # 默认与训练/推理一样完整安装 GCC、CANN、torch-npu、vLLM-Ascend、Triton、
89
+ # VERL 和 verifier 依赖。使用 source,确保导出的动态库和 Python 路径对 Judge 生效。
90
+ source "${BUNDLE_ROOT}/scripts/setup_full_npu_environment.sh"
91
+ cd "${BUNDLE_ROOT}"
92
+
93
+ # Probe the same Python tempfile path used by Triton before launching all TP
94
+ # workers. This produces a short actionable error instead of a long vLLM
95
+ # multiprocess traceback.
96
+ python3 - "${TMPDIR}" <<'PY'
97
+ import shutil
98
+ import sys
99
+ import tempfile
100
+ from pathlib import Path
101
+
102
+ tmpdir = Path(sys.argv[1])
103
+ try:
104
+ probe = Path(tempfile.mkdtemp(prefix="clawbenchpro_probe_", dir=str(tmpdir)))
105
+ (probe / "probe").write_text("ok", encoding="utf-8")
106
+ shutil.rmtree(probe)
107
+ except Exception as exc:
108
+ print(f"ERROR: Python/Triton temporary-file probe failed in {tmpdir}: {type(exc).__name__}: {exc}", file=sys.stderr)
109
+ raise SystemExit(2)
110
+ PY
111
+
112
+ judge_pid=""
113
+ cleanup() {
114
+ exit_code=$?
115
+ if [ -n "${judge_pid}" ]; then
116
+ kill "${judge_pid}" 2>/dev/null || true
117
+ wait "${judge_pid}" 2>/dev/null || true
118
+ fi
119
+ exit "${exit_code}"
120
+ }
121
+ trap cleanup EXIT INT TERM
122
+
123
+ check_judge() {
124
+ 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)' \
125
+ "${JUDGE_BASE_URL}" "${JUDGE_API_KEY}" "${JUDGE_SERVED_MODEL_NAME}"
126
+ }
127
+
128
+ if [ "${JUDGE_ENABLED}" = "1" ]; then
129
+ if [ "${START_JUDGE_SERVER}" = "1" ]; then
130
+ if [ -z "${JUDGE_MODEL_PATH}" ] || [ ! -d "${JUDGE_MODEL_PATH}" ]; then
131
+ echo "ERROR: set JUDGE_MODEL_PATH to a local Hugging Face Judge model directory." >&2
132
+ exit 2
133
+ fi
134
+ visible_count=$(awk -F, '{print NF}' <<< "${JUDGE_DEVICES}")
135
+ if [ "${JUDGE_TP}" -gt "${visible_count}" ]; then
136
+ echo "ERROR: JUDGE_TP=${JUDGE_TP} exceeds JUDGE_DEVICES count=${visible_count}." >&2
137
+ exit 2
138
+ fi
139
+ export ASCEND_RT_VISIBLE_DEVICES=${JUDGE_DEVICES}
140
+ judge_args=(
141
+ --model "${JUDGE_MODEL_PATH}"
142
+ --tokenizer "${JUDGE_MODEL_PATH}"
143
+ --served-model-name "${JUDGE_SERVED_MODEL_NAME}"
144
+ --host "${JUDGE_BIND_HOST}"
145
+ --port "${JUDGE_PORT}"
146
+ --tensor-parallel-size "${JUDGE_TP}"
147
+ --dtype "${JUDGE_DTYPE}"
148
+ --max-model-len "${JUDGE_MAX_MODEL_LEN}"
149
+ --max-num-batched-tokens "${JUDGE_MAX_NUM_BATCHED_TOKENS}"
150
+ --max-num-seqs "${JUDGE_MAX_NUM_SEQS}"
151
+ --gpu-memory-utilization "${JUDGE_GPU_MEMORY_UTILIZATION}"
152
+ )
153
+ echo "Starting Judge model: ${JUDGE_MODEL_PATH}"
154
+ python3 -m vllm.entrypoints.openai.api_server "${judge_args[@]}" >"${JUDGE_LOG}" 2>&1 &
155
+ judge_pid=$!
156
+ fi
157
+
158
+ started=$(date +%s)
159
+ until check_judge; do
160
+ if [ -n "${judge_pid}" ] && ! kill -0 "${judge_pid}" 2>/dev/null; then
161
+ echo "ERROR: Judge process exited before becoming ready. Log: ${JUDGE_LOG}" >&2
162
+ tail -n 160 "${JUDGE_LOG}" >&2 || true
163
+ exit 2
164
+ fi
165
+ elapsed=$(($(date +%s) - started))
166
+ if [ "${elapsed}" -ge "${JUDGE_STARTUP_TIMEOUT}" ]; then
167
+ echo "ERROR: Judge API did not become ready within ${JUDGE_STARTUP_TIMEOUT}s." >&2
168
+ tail -n 160 "${JUDGE_LOG}" >&2 || true
169
+ exit 2
170
+ fi
171
+ echo "Waiting for Judge API ${JUDGE_BASE_URL}; elapsed=${elapsed}s"
172
+ sleep 5
173
+ done
174
+ echo "Judge API ready: ${JUDGE_BASE_URL}, model=${JUDGE_SERVED_MODEL_NAME}"
175
+ else
176
+ echo "WARNING: JUDGE_ENABLED=0; 134 LLM Judge tasks will be skipped explicitly."
177
+ fi
178
+
179
+ score_args=(
180
+ python3 "${WORK_DIR}/recipe/nanoclaw/score_clawbenchpro.py"
181
+ --inference-root "${INFERENCE_ROOT}"
182
+ --base-tasks "${BASE_TASKS}"
183
+ --output-root "${SCORE_OUTPUT_ROOT}"
184
+ --models "${MODELS}"
185
+ --judge-enabled "${JUDGE_ENABLED}"
186
+ --judge-base-url "${JUDGE_BASE_URL}"
187
+ --judge-api-key "${JUDGE_API_KEY}"
188
+ --judge-model "${JUDGE_SERVED_MODEL_NAME}"
189
+ --parallel "${PARALLEL}"
190
+ --timeout "${VERIFIER_TIMEOUT}"
191
+ --pass-threshold "${PASS_THRESHOLD}"
192
+ --resume "${RESUME}"
193
+ --overwrite "${OVERWRITE}"
194
+ )
195
+ if [ "${FAIL_ON_ERROR}" = "1" ]; then
196
+ score_args+=(--fail-on-error)
197
+ fi
198
+ "${score_args[@]}"
199
+
200
+ echo "Scoring completed:"
201
+ echo " ${SCORE_OUTPUT_ROOT}/summary.json"
202
+ echo " ${SCORE_OUTPUT_ROOT}/leaderboard.csv"
203
+ echo " ${SCORE_OUTPUT_ROOT}/<model>/scoring_summary.json"