| #!/bin/bash |
| |
| |
|
|
| 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} |
|
|
| |
| export MODELS=${MODELS:-} |
|
|
| |
| export JUDGE_ENABLED=${JUDGE_ENABLED:-1} |
| |
| 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}")" |
|
|
| |
| |
| 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}" |
|
|
| |
| |
| |
| |
| 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}" |
|
|
| |
| |
| source "${BUNDLE_ROOT}/scripts/setup_full_npu_environment.sh" |
| cd "${BUNDLE_ROOT}" |
|
|
| |
| |
| |
| 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" |
|
|