#!/usr/bin/env bash ############################################################################### # StepProbe โ€” Quick Sanity Test (no GPU needed for most tests) # # Validates that all modules work correctly before running the full pipeline. # # Usage: # bash scripts/test_sanity.sh ############################################################################### set -euo pipefail PROJECT_DIR="$(cd "$(dirname "$0")/.." && pwd)" cd "$PROJECT_DIR" PASS=0 FAIL=0 check() { local name=$1; shift echo -n " Testing: $name ... " if eval "$@" &>/dev/null; then echo "โœ…" ((PASS++)) else echo "โŒ" ((FAIL++)) fi } echo "==================================================================" echo " StepProbe โ€” Sanity Tests" echo "==================================================================" echo "" # 1. Python imports echo "๐Ÿ“ฆ Module Imports:" check "stepprobe.segment" "python -c 'from stepprobe.segment import segment_cot'" check "stepprobe.align" "python -c 'from stepprobe.align import align_steps'" check "stepprobe.diagnose" "python -c 'from stepprobe.diagnose import diagnose_single_problem, LLMJudge, RuleBasedJudge'" check "stepprobe.metrics" "python -c 'from stepprobe.metrics import compute_first_failure_step, compute_error_cascade_rate, compute_step_survival_rate, aggregate_metrics'" check "stepprobe.restore" "python -c 'from stepprobe.restore import build_silver_bullet_dataset, format_for_sft, format_for_dpo'" check "stepprobe.utils" "python -c 'from stepprobe.utils import check_answer, normalize_answer, extract_number, extract_gsm8k_answer'" echo "" # 2. Dependencies echo "๐Ÿ“š Key Dependencies:" check "torch" "python -c 'import torch; print(torch.__version__)'" check "transformers" "python -c 'import transformers; print(transformers.__version__)'" check "peft" "python -c 'import peft; print(peft.__version__)'" check "datasets" "python -c 'import datasets; print(datasets.__version__)'" check "matplotlib" "python -c 'import matplotlib; print(matplotlib.__version__)'" check "numpy" "python -c 'import numpy; print(numpy.__version__)'" echo "" # 3. GPU echo "๐Ÿ–ฅ GPU:" check "CUDA available" "python -c 'import torch; assert torch.cuda.is_available()'" check "GPU memory" "python -c 'import torch; m=torch.cuda.get_device_properties(0).total_mem/1e9; print(f\"{m:.0f}GB\"); assert m >= 20'" echo "" # 4. Core functionality echo "๐Ÿงช Core Functions:" check "Segmentation" "python -c \" from stepprobe.segment import segment_cot seg = segment_cot('t1', 'Step 1: compute 2+2=4\nStep 2: answer is 4\n\\\\boxed{4}') assert len(seg.steps) >= 2 assert seg.final_answer == '4' \"" check "Alignment (DTW)" "python -c \" from stepprobe.align import align_steps ref = [{'index': 0, 'text': 'step A'}, {'index': 1, 'text': 'step B'}] hyp = [{'index': 0, 'text': 'step A'}, {'index': 1, 'text': 'step C'}] aligns = align_steps(ref, hyp, method='dtw') assert len(aligns) == 2 \"" check "Answer checking" "python -c \" from stepprobe.utils import check_answer assert check_answer('42', '42') assert check_answer('42.0', '42') assert not check_answer('43', '42') assert check_answer('\\\\boxed{7}', '7') \"" check "FFS computation" "python -c \" from stepprobe.metrics import compute_first_failure_step steps = [{'index':0,'is_correct':True},{'index':1,'is_correct':False},{'index':2,'is_correct':False}] assert compute_first_failure_step(steps) == 1 \"" check "ECR computation" "python -c \" from stepprobe.metrics import compute_error_cascade_rate steps = [{'index':0,'is_correct':True},{'index':1,'is_correct':False},{'index':2,'is_correct':False}] ecr = compute_error_cascade_rate(steps) assert ecr == 1.0 \"" check "SSR computation" "python -c \" from stepprobe.metrics import compute_step_survival_rate all_steps = [[{'index':0,'is_correct':True},{'index':1,'is_correct':False}]] * 10 ssr = compute_step_survival_rate(all_steps, max_depth=3) assert ssr[0] == 1.0 and ssr[1] == 0.0 \"" check "Rule-based judge" "python -c \" from stepprobe.diagnose import RuleBasedJudge j = RuleBasedJudge() etype = j.classify_error('prob', '5 x 8 = 40', '5 x 8 = 42') assert etype in ['conceptual','methodological','executional','logical'] \"" check "Silver Bullet build" "python -c \" from stepprobe.restore import build_silver_bullet_dataset, RestorationSample diag = [{'problem_id':'p1','is_correct_final':False,'raw_output':'wrong','steps':[{'index':0,'is_correct':False,'error_type':'executional'}]}] ref = [{'problem_id':'p1','raw_output':'correct','steps':[{'index':0,'text':'right'}]}] probs = [{'problem_id':'p1','question':'q','answer':'a'}] samples, stats = build_silver_bullet_dataset(diag, ref, probs, max_samples=10) assert len(samples) >= 1 \"" check "Figure generation (demo)" "python scripts/make_figures.py --demo --output /tmp/stepprobe_test_figs" echo "" # 5. Script entry points echo "๐Ÿ“œ Script Entry Points:" check "run_inference.py --help" "python scripts/run_inference.py --help" check "run_eval.py --help" "python scripts/run_eval.py --help" check "make_figures.py --help" "python scripts/make_figures.py --help" echo "" # Summary echo "==================================================================" echo " Results: $PASS passed, $FAIL failed" echo "==================================================================" if [[ $FAIL -gt 0 ]]; then echo " โš ๏ธ Some tests failed. Fix issues before running the pipeline." exit 1 else echo " โœ… All tests passed! Ready to run: bash run_all.sh --quick" fi