| #!/usr/bin/env bash |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| set -euo pipefail |
|
|
| REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)" |
| cd "${REPO_ROOT}" |
|
|
| |
| |
| |
| DATA_ROOT="${DATA_ROOT:-/apdcephfs_cq10/share_1603164/user/schmittzhu/data/process_data/genQA/all_qa_llm_by_difficulty_v2}" |
| SPLITS="${SPLITS:-easy_filtered medium hard}" |
| SPLIT_NAME="${SPLIT_NAME:-test}" |
|
|
| |
| |
| |
| |
| MODELS="${MODELS:-iv:stage1 iv:stage2 neural_iv:stage1 neural_iv:stage2}" |
|
|
| |
| |
| |
| IV_RUN_ROOT="${IV_RUN_ROOT:-${REPO_ROOT}/runs/v13d_easy_llmqa_iv}" |
| NEURAL_IV_RUN_ROOT="${NEURAL_IV_RUN_ROOT:-${REPO_ROOT}/runs/v13d_easy_llmqa_neural_iv}" |
| BEATS_RUN_ROOT="${BEATS_RUN_ROOT:-${REPO_ROOT}/runs/v13d_easy_llmqa}" |
|
|
| STAGE1_SUBDIR="${STAGE1_SUBDIR:-stage1_projector}" |
| STAGE2_SUBDIR="${STAGE2_SUBDIR:-stage2_encoder_lora}" |
| STAGE3_SUBDIR="${STAGE3_SUBDIR:-stage3_beats_lora}" |
| CKPT_NAME="${CKPT_NAME:-best_trainable.pt}" |
|
|
| |
| |
| |
| GPUS="${GPUS:-0,1,2,3,4,5,6,7}" |
| IFS=',' read -r -a GPU_ARRAY <<< "${GPUS}" |
| NPROC="${NPROC:-${#GPU_ARRAY[@]}}" |
| MASTER_PORT="${MASTER_PORT:-29551}" |
|
|
| BATCH_SIZE="${BATCH_SIZE:-1}" |
| NUM_WORKERS="${NUM_WORKERS:-4}" |
| MAX_NEW_TOKENS="${MAX_NEW_TOKENS:-128}" |
| DTYPE="${DTYPE:-bfloat16}" |
| ATTN_IMPL="${ATTN_IMPL:-auto}" |
|
|
| |
| QWEN_AUDIO_CACHE_MANIFEST="${QWEN_AUDIO_CACHE_MANIFEST:-}" |
|
|
| |
| |
| |
| RUN_SCORING="${RUN_SCORING:-1}" |
| USE_LLM_JUDGE="${USE_LLM_JUDGE:-1}" |
| LLM_CONCURRENCY="${LLM_CONCURRENCY:-8}" |
| SKIP_EXISTING_BENCH="${SKIP_EXISTING_BENCH:-1}" |
|
|
| |
| |
| |
| resolve_model_spec() { |
| local spec="$1" |
| local encoder stage |
| encoder="${spec%:*}" |
| stage="${spec#*:}" |
|
|
| local run_root stage_subdir bench_script |
| case "${encoder}" in |
| iv) |
| run_root="${IV_RUN_ROOT}" |
| bench_script="scripts/bench_test_generate_iv.py" |
| ;; |
| neural_iv) |
| run_root="${NEURAL_IV_RUN_ROOT}" |
| bench_script="scripts/bench_test_generate_iv.py" |
| ;; |
| beats) |
| run_root="${BEATS_RUN_ROOT}" |
| bench_script="scripts/bench_test_generate.py" |
| ;; |
| *) |
| echo "[ERROR] unknown encoder in MODELS spec: '${encoder}' (expected iv/neural_iv/beats)" >&2 |
| return 1 |
| ;; |
| esac |
| case "${stage}" in |
| stage1) stage_subdir="${STAGE1_SUBDIR}" ;; |
| stage2) stage_subdir="${STAGE2_SUBDIR}" ;; |
| stage3) |
| if [[ "${encoder}" != "beats" ]]; then |
| echo "[ERROR] stage3 only exists for beats (got encoder=${encoder})" >&2 |
| return 1 |
| fi |
| stage_subdir="${STAGE3_SUBDIR}" |
| ;; |
| *) |
| echo "[ERROR] unknown stage in MODELS spec: '${stage}' (expected stage1/stage2/stage3)" >&2 |
| return 1 |
| ;; |
| esac |
| echo "${encoder}|${run_root}|${stage_subdir}|${bench_script}" |
| } |
|
|
| |
| |
| |
| echo "===========================================================" |
| echo " Test-split bench (all models)" |
| echo " DATA_ROOT = ${DATA_ROOT}" |
| echo " SPLITS = ${SPLITS}" |
| echo " MODELS = ${MODELS}" |
| echo " GPUS = ${GPUS} NPROC=${NPROC}" |
| echo " BATCH_SIZE = ${BATCH_SIZE} MAX_NEW_TOKENS=${MAX_NEW_TOKENS}" |
| echo " ATTN_IMPL = ${ATTN_IMPL}" |
| echo " RUN_SCORING= ${RUN_SCORING} LLM_JUDGE=${USE_LLM_JUDGE}" |
| echo "===========================================================" |
|
|
| |
| |
| |
| for spec in ${MODELS}; do |
| parts="$(resolve_model_spec "${spec}")" || { echo "[abort] bad model spec"; exit 1; } |
| IFS='|' read -r encoder run_root stage_subdir bench_script <<< "${parts}" |
|
|
| ckpt_path="${run_root}/${stage_subdir}/checkpoints/${CKPT_NAME}" |
| if [[ ! -f "${ckpt_path}" ]]; then |
| echo "[skip] missing checkpoint: ${ckpt_path}" |
| continue |
| fi |
|
|
| for split in ${SPLITS}; do |
| qa_root="${DATA_ROOT}/${split}" |
| if [[ ! -f "${qa_root}/${SPLIT_NAME}.jsonl" ]]; then |
| echo "[skip] missing ${qa_root}/${SPLIT_NAME}.jsonl" |
| continue |
| fi |
|
|
| output_dir="${run_root}/${stage_subdir}/bench/${split}" |
| ckpt_tag="${CKPT_NAME%_trainable.pt}" |
| predictions_jsonl="${output_dir}/${ckpt_tag}/predictions.jsonl" |
|
|
| echo "" |
| echo "===========================================================" |
| echo "[run] model=${spec} split=${split}" |
| echo " ckpt = ${ckpt_path}" |
| echo " script = ${bench_script}" |
| echo " output_dir= ${output_dir}" |
| echo "===========================================================" |
|
|
| if [[ "${SKIP_EXISTING_BENCH}" == "1" && -s "${predictions_jsonl}" ]]; then |
| echo "[skip-bench] predictions.jsonl already exists: ${predictions_jsonl}" |
| else |
| mkdir -p "${output_dir}" |
|
|
| extra=() |
| if [[ -n "${QWEN_AUDIO_CACHE_MANIFEST}" ]]; then |
| extra+=(--audio-feature-cache-manifest "${QWEN_AUDIO_CACHE_MANIFEST}") |
| fi |
|
|
| |
| |
| PORT=$((MASTER_PORT + RANDOM % 100)) |
|
|
| CUDA_VISIBLE_DEVICES="${GPUS}" torchrun \ |
| --nnodes=1 \ |
| --nproc_per_node="${NPROC}" \ |
| --master_port="${PORT}" \ |
| "${REPO_ROOT}/${bench_script}" \ |
| --checkpoint-paths "${ckpt_path}" \ |
| --qa-root "${qa_root}" \ |
| --split "${SPLIT_NAME}" \ |
| --output-dir "${output_dir}" \ |
| --batch-size "${BATCH_SIZE}" \ |
| --num-workers "${NUM_WORKERS}" \ |
| --max-new-tokens "${MAX_NEW_TOKENS}" \ |
| --dtype "${DTYPE}" \ |
| --attn-impl "${ATTN_IMPL}" \ |
| "${extra[@]}" \ |
| "$@" |
| fi |
|
|
| if [[ ! -f "${predictions_jsonl}" ]]; then |
| echo "[ERROR] predictions not produced: ${predictions_jsonl}" >&2 |
| continue |
| fi |
|
|
| |
| if [[ "${RUN_SCORING}" == "1" ]]; then |
| score_json="$(dirname "${predictions_jsonl}")/score_result.json" |
| if [[ -s "${score_json}" && "${SKIP_EXISTING_BENCH}" == "1" ]]; then |
| echo "[skip-score] already exists: ${score_json}" |
| else |
| echo "-----------------------------------------------------------" |
| echo "[score] ${predictions_jsonl}" |
| echo "-----------------------------------------------------------" |
| score_args=( |
| python "${REPO_ROOT}/scripts/score_test_predictions.py" |
| --predictions-jsonl "${predictions_jsonl}" |
| --qa-root "${qa_root}" |
| --split "${SPLIT_NAME}" |
| --output-json "${score_json}" |
| ) |
| if [[ "${USE_LLM_JUDGE}" == "1" ]]; then |
| score_args+=(--llm-judge --llm-concurrency "${LLM_CONCURRENCY}") |
| fi |
| "${score_args[@]}" || echo "[warn] scoring failed for ${predictions_jsonl}" |
| fi |
| fi |
| done |
| done |
|
|
| echo "" |
| echo "===========================================================" |
| echo "All requested (model, split) combinations finished." |
| echo "Predictions live under each run's bench/<split>/<ckpt>/predictions.jsonl" |
| echo "===========================================================" |
|
|