File size: 6,395 Bytes
3742716 | 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 | #!/bin/bash
# Automatic Model Analysis Script
# Runs evaluation and generation analysis after training
set -e
# Colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
print_status() { echo -e "${GREEN}[INFO]${NC} $1"; }
print_header() { echo -e "\n${BLUE}========================================\n$1\n========================================${NC}\n"; }
# Parameters
MODEL_PATH="${1:-./output/Se124M_700K_infix}"
DATA_COLUMN="${2:-i_prompt_n}"
DATASET_REPO="augustocsc/sintetico_natural"
DATA_DIR="700K"
NUM_SAMPLES=500
NUM_GENERATIONS=100
# Directories
PROJECT_DIR="/home/ubuntu/seriguela"
OUTPUT_DIR="$HOME/analysis_results_$(date +%Y%m%d_%H%M%S)"
mkdir -p "$OUTPUT_DIR"
cd "$PROJECT_DIR"
source venv/bin/activate
print_header "Automatic Model Analysis"
print_status "Model: $MODEL_PATH"
print_status "Output: $OUTPUT_DIR"
echo ""
# =============================================================================
# 1. EVALUATE MODEL
# =============================================================================
print_header "Step 1: Model Evaluation"
print_status "Running evaluation on $NUM_SAMPLES samples..."
python scripts/evaluate.py \
--model_path "$MODEL_PATH" \
--dataset_repo_id "$DATASET_REPO" \
--data_dir "$DATA_DIR" \
--data_column "$DATA_COLUMN" \
--num_samples "$NUM_SAMPLES" \
--output_dir "$OUTPUT_DIR/evaluation" \
--temperature 0.7 \
--seed 42 \
2>&1 | tee "$OUTPUT_DIR/evaluation.log"
if [ $? -eq 0 ]; then
print_status "โ
Evaluation completed"
else
print_status "โ ๏ธ Evaluation had issues"
fi
# =============================================================================
# 2. GENERATE SAMPLES
# =============================================================================
print_header "Step 2: Sample Generation & Validation"
print_status "Generating $NUM_GENERATIONS samples with validation..."
python scripts/generate.py \
--model_path "$MODEL_PATH" \
--num_generations "$NUM_GENERATIONS" \
--validate \
--output_file "$OUTPUT_DIR/generations.txt" \
--temperature 0.8 \
--top_p 0.95 \
--seed 42 \
2>&1 | tee "$OUTPUT_DIR/generation.log"
if [ $? -eq 0 ]; then
print_status "โ
Generation completed"
else
print_status "โ ๏ธ Generation had issues"
fi
# =============================================================================
# 3. ANALYZE TRAINING LOGS
# =============================================================================
print_header "Step 3: Training Log Analysis"
print_status "Extracting training metrics..."
TRAINING_LOG="$HOME/training_success.log"
if [ -f "$TRAINING_LOG" ]; then
# Extract loss values
grep -E "'loss':|train_loss|eval_loss" "$TRAINING_LOG" > "$OUTPUT_DIR/training_metrics.txt" 2>/dev/null || true
# Extract epoch summaries
grep -E "epoch.*loss" "$TRAINING_LOG" | tail -20 > "$OUTPUT_DIR/epoch_summary.txt" 2>/dev/null || true
# Count total steps
TOTAL_STEPS=$(grep -E "[0-9]+/21882" "$TRAINING_LOG" | tail -1 | sed 's/.*\([0-9]\+\)\/21882.*/\1/' || echo "0")
print_status "Total training steps: $TOTAL_STEPS"
fi
# =============================================================================
# 4. CREATE SUMMARY REPORT
# =============================================================================
print_header "Step 4: Creating Analysis Report"
cat > "$OUTPUT_DIR/ANALYSIS_REPORT.md" << 'EOFREPORT'
# Training Analysis Report
**Generated:** $(date)
## ๐ Model Information
- **Architecture:** GPT-2 Small (124M parameters)
- **Training Method:** LoRA (294K trainable parameters, 0.24%)
- **Dataset:** 700K samples (infix notation)
- **Training Duration:** $(grep "Training Duration:" $HOME/training_notification.txt 2>/dev/null | head -1 || echo "N/A")
## ๐ Training Metrics
### Loss Progression
```
$(tail -20 $OUTPUT_DIR/training_metrics.txt 2>/dev/null || echo "No metrics available")
```
### Epoch Summary
```
$(cat $OUTPUT_DIR/epoch_summary.txt 2>/dev/null || echo "No epoch data available")
```
## ๐ฏ Evaluation Results
### Performance Metrics
```
$(grep -E "Accuracy|Loss|Perplexity" $OUTPUT_DIR/evaluation.log 2>/dev/null || echo "Check evaluation.log for details")
```
### Sample Predictions
```
$(head -50 $OUTPUT_DIR/evaluation/*.txt 2>/dev/null | head -20 || echo "No evaluation samples found")
```
## ๐ฎ Generation Quality
### Validation Results
```
$(grep -E "Valid:|Success|Failed" $OUTPUT_DIR/generation.log | head -20 || echo "Check generation.log")
```
### Sample Generations
```
$(head -30 $OUTPUT_DIR/generations.txt 2>/dev/null || echo "No generations file found")
```
## ๐ Output Files
- Evaluation results: `evaluation/`
- Generated samples: `generations.txt`
- Full logs: `evaluation.log`, `generation.log`
- Training metrics: `training_metrics.txt`
## ๐ Resources
- **Wandb Dashboard:** https://wandb.ai/symbolic-gression/seriguela_700K_test
- **HuggingFace Model:** https://huggingface.co/augustocsc/Se124M_700K_infix
- **Analysis Directory:** $OUTPUT_DIR
---
*Generated automatically by analyze_model.sh*
EOFREPORT
# Evaluate the report with actual values
eval "cat > \"$OUTPUT_DIR/ANALYSIS_REPORT.md\" << 'EOFREPORT'
$(cat "$OUTPUT_DIR/ANALYSIS_REPORT.md")
EOFREPORT"
print_status "Report created: $OUTPUT_DIR/ANALYSIS_REPORT.md"
# =============================================================================
# 5. FINAL SUMMARY
# =============================================================================
print_header "Analysis Complete!"
echo ""
print_status "All results saved to: $OUTPUT_DIR"
print_status "Main report: $OUTPUT_DIR/ANALYSIS_REPORT.md"
echo ""
print_status "Key files:"
echo " - Evaluation: $OUTPUT_DIR/evaluation.log"
echo " - Generation: $OUTPUT_DIR/generation.log"
echo " - Metrics: $OUTPUT_DIR/training_metrics.txt"
echo " - Report: $OUTPUT_DIR/ANALYSIS_REPORT.md"
echo ""
print_status "View the full report with:"
echo " cat $OUTPUT_DIR/ANALYSIS_REPORT.md"
echo ""
# Create a quick summary
EVAL_SUCCESS=$(grep -c "โ
" "$OUTPUT_DIR/evaluation.log" 2>/dev/null || echo "0")
GEN_SUCCESS=$(grep -c "Valid" "$OUTPUT_DIR/generation.log" 2>/dev/null || echo "0")
print_header "Quick Summary"
echo "Evaluation samples processed: $NUM_SAMPLES"
echo "Generations created: $NUM_GENERATIONS"
echo "Check logs for detailed metrics and quality assessment"
echo ""
print_status "Done!"
|