tahamajs's picture
download
raw
7.17 kB
#!/bin/bash
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PYTHON="python3"
PIP="pip3"
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
echo -e "${BLUE}================================================${NC}"
echo -e "${BLUE} NEURAL PROGRAM SYNTHESIS PIPELINE${NC}"
echo -e "${BLUE}================================================${NC}"
print_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
check_python() {
print_info "Checking Python installation..."
if ! command -v $PYTHON &> /dev/null; then
print_error "Python 3 is required but not installed. Please install Python 3."
exit 1
fi
PYTHON_VERSION=$($PYTHON --version 2>&1 | cut -d' ' -f2 | cut -d'.' -f1,2)
print_success "Python $PYTHON_VERSION found"
}
install_dependencies() {
print_info "Installing dependencies..."
if [ ! -f "requirements.txt" ]; then
print_error "requirements.txt not found!"
exit 1
fi
$PIP install -r requirements.txt
print_success "Dependencies installed successfully"
}
run_training() {
print_info "Starting training pipeline..."
local train_args=""
if [ ! -z "$TASK" ]; then
train_args="$train_args --task $TASK"
fi
if [ ! -z "$MODEL_TYPE" ]; then
train_args="$train_args --model_type $MODEL_TYPE"
fi
if [ ! -z "$EPOCHS" ]; then
train_args="$train_args --num_epochs $EPOCHS"
fi
if [ ! -z "$BATCH_SIZE" ]; then
train_args="$train_args --batch_size $BATCH_SIZE"
fi
$PYTHON main.py --mode train $train_args --output_dir ./training_results
}
run_evaluation() {
print_info "Starting evaluation pipeline..."
local eval_args=""
if [ ! -z "$CHECKPOINT" ]; then
eval_args="$eval_args --checkpoint $CHECKPOINT"
fi
if [ ! -z "$TASK" ]; then
eval_args="$eval_args --task $TASK"
fi
$PYTHON main.py --mode eval $eval_args --output_dir ./evaluation_results
}
run_generation() {
print_info "Starting program generation..."
if [ -z "$SPECIFICATION" ]; then
print_error "Please provide a specification with --specification parameter"
exit 1
fi
local gen_args=""
if [ ! -z "$CHECKPOINT" ]; then
gen_args="$gen_args --checkpoint $CHECKPOINT"
fi
if [ ! -z "$MODEL_TYPE" ]; then
gen_args="$gen_args --model_type $MODEL_TYPE"
fi
gen_args="$gen_args --specification \"$SPECIFICATION\""
$PYTHON main.py --mode generate $gen_args --output_dir ./generated_programs
}
run_full_pipeline() {
print_info "Starting complete neural program synthesis pipeline..."
run_training
CHECKPOINT="./training_results/best_model.pt"
if [ ! -f "$CHECKPOINT" ]; then
print_warning "Best model checkpoint not found, using latest checkpoint"
CHECKPOINT="./training_results/final_model.pt"
fi
run_evaluation
if [ -z "$SPECIFICATION" ]; then
SPECIFICATION="add two numbers"
fi
run_generation
print_success "Complete pipeline finished successfully!"
}
cleanup() {
print_info "Cleaning up old results..."
rm -rf ./training_results ./evaluation_results ./generated_programs
print_success "Cleanup completed"
}
show_help() {
echo "Neural Program Synthesis Pipeline Runner"
echo ""
echo "Usage: $0 [OPTIONS] [MODE]"
echo ""
echo "MODES:"
echo " setup Setup environment and install dependencies"
echo " train Train the neural program synthesis model"
echo " eval Evaluate trained model"
echo " generate Generate programs from natural language"
echo " full Run complete training + evaluation + generation pipeline"
echo " cleanup Remove old result directories"
echo " help Show this help message"
echo ""
echo "OPTIONS:"
echo " --task ARITHMETIC Task type (arithmetic, string, list_ops)"
echo " --model_type SEQ2SEQ Model architecture (seq2seq, transformer, graph)"
echo " --epochs 100 Number of training epochs"
echo " --batch_size 32 Training batch size"
echo " --checkpoint PATH Path to model checkpoint"
echo " --specification TEXT Natural language specification for generation"
echo " --learning_rate 0.001 Learning rate for training"
echo " --vocab_size 1000 Vocabulary size"
echo ""
echo "EXAMPLES:"
echo " $0 setup"
echo " $0 train --task arithmetic --epochs 50"
echo " $0 eval --checkpoint ./models/best_model.pt"
echo " $0 generate --specification \"multiply two numbers\""
echo " $0 full --task arithmetic --epochs 100"
}
main() {
cd "$SCRIPT_DIR"
MODE=""
TASK="arithmetic"
MODEL_TYPE="seq2seq"
EPOCHS="100"
BATCH_SIZE="32"
CHECKPOINT=""
SPECIFICATION=""
LEARNING_RATE="0.001"
VOCAB_SIZE="1000"
while [[ $
case $1 in
setup|train|eval|generate|full|cleanup|help)
MODE="$1"
shift
;;
--task)
TASK="$2"
shift 2
;;
--model_type)
MODEL_TYPE="$2"
shift 2
;;
--epochs)
EPOCHS="$2"
shift 2
;;
--batch_size)
BATCH_SIZE="$2"
shift 2
;;
--checkpoint)
CHECKPOINT="$2"
shift 2
;;
--specification)
SPECIFICATION="$2"
shift 2
;;
--learning_rate)
LEARNING_RATE="$2"
shift 2
;;
--vocab_size)
VOCAB_SIZE="$2"
shift 2
;;
*)
print_error "Unknown option: $1"
show_help
exit 1
;;
esac
done
if [ -z "$MODE" ]; then
print_error "Please specify a mode"
show_help
exit 1
fi
case $MODE in
setup)
check_python
install_dependencies
print_success "Setup completed successfully!"
;;
train)
check_python
run_training
;;
eval)
check_python
run_evaluation
;;
generate)
check_python
run_generation
;;
full)
check_python
run_full_pipeline
;;
cleanup)
cleanup
;;
help)
show_help
;;
*)
print_error "Unknown mode: $MODE"
show_help
exit 1
;;
esac
}
main "$@"

Xet Storage Details

Size:
7.17 kB
·
Xet hash:
6e50bf3c9690e75936f18095fb68b4efc2dc0dede5eeb3a0472dc1c55ee96357

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.