Buckets:
| set -e | |
| RED='\033[0;31m' | |
| GREEN='\033[0;32m' | |
| YELLOW='\033[1;33m' | |
| BLUE='\033[0;34m' | |
| NC='\033[0m' | |
| PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |
| RESULTS_DIR="${PROJECT_DIR}/results" | |
| VISUALIZATIONS_DIR="${PROJECT_DIR}/visualizations" | |
| LOGS_DIR="${PROJECT_DIR}/logs" | |
| CONFIG_FILE="${PROJECT_DIR}/config.yaml" | |
| EXPERIMENT_TYPE="rlvr" | |
| NUM_EPOCHS=5 | |
| BATCH_SIZE=4 | |
| NUM_EVAL_EPISODES=20 | |
| MODEL_NAME="gpt2" | |
| DEVICE="auto" | |
| SEED=42 | |
| USE_ADVANCED_ALGORITHMS=false | |
| USE_META_LEARNING=false | |
| USE_DISTRIBUTED_TRAINING=false | |
| USE_CURRICULUM_LEARNING=false | |
| USE_NEURAL_ARCHITECTURE_SEARCH=false | |
| USE_FEDERATED_LEARNING=false | |
| NUM_GPUS=1 | |
| META_LEARNING_ROUNDS=10 | |
| NAS_GENERATIONS=20 | |
| FEDERATED_CLIENTS=5 | |
| print_status() { | |
| 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" | |
| } | |
| create_directories() { | |
| print_status "Creating necessary directories..." | |
| mkdir -p "${RESULTS_DIR}" | |
| mkdir -p "${VISUALIZATIONS_DIR}" | |
| mkdir -p "${LOGS_DIR}" | |
| print_success "Directories created" | |
| } | |
| check_dependencies() { | |
| print_status "Checking dependencies..." | |
| if ! command -v python3 &> /dev/null; then | |
| print_error "Python3 is not installed" | |
| exit 1 | |
| fi | |
| if [ ! -d "${PROJECT_DIR}/venv" ]; then | |
| print_warning "Virtual environment not found, creating one..." | |
| python3 -m venv "${PROJECT_DIR}/venv" | |
| fi | |
| source "${PROJECT_DIR}/venv/bin/activate" | |
| if [ -f "${PROJECT_DIR}/requirements.txt" ]; then | |
| print_status "Installing requirements..." | |
| pip install -r "${PROJECT_DIR}/requirements.txt" | |
| else | |
| print_warning "requirements.txt not found" | |
| fi | |
| print_success "Dependencies checked" | |
| } | |
| run_tests() { | |
| print_status "Running component tests..." | |
| if [ -f "${PROJECT_DIR}/tests/test_components.py" ]; then | |
| cd "${PROJECT_DIR}" | |
| python tests/test_components.py | |
| print_success "Tests completed" | |
| else | |
| print_warning "Test file not found, skipping tests" | |
| fi | |
| } | |
| create_default_config() { | |
| if [ ! -f "${CONFIG_FILE}" ]; then | |
| print_status "Creating default configuration..." | |
| cat > "${CONFIG_FILE}" << EOF | |
| model: | |
| model_name: "${MODEL_NAME}" | |
| device: "${DEVICE}" | |
| max_length: 512 | |
| temperature: 0.7 | |
| top_p: 0.9 | |
| rl: | |
| num_epochs: ${NUM_EPOCHS} | |
| batch_size: ${BATCH_SIZE} | |
| learning_rate: 1e-4 | |
| gamma: 0.99 | |
| lambda_: 0.95 | |
| clip_ratio: 0.2 | |
| value_loss_coef: 0.5 | |
| entropy_coef: 0.01 | |
| environment: | |
| difficulty_levels: ["easy", "medium", "hard"] | |
| problem_types: ["arithmetic", "algebra", "geometry", "calculus"] | |
| max_problem_length: 200 | |
| reward_scale: 1.0 | |
| experiment: | |
| experiment_type: "${EXPERIMENT_TYPE}" | |
| output_dir: "${RESULTS_DIR}" | |
| seed: ${SEED} | |
| save_checkpoints: true | |
| log_level: "INFO" | |
| EOF | |
| print_success "Default configuration created" | |
| else | |
| print_status "Using existing configuration: ${CONFIG_FILE}" | |
| fi | |
| if [ "$USE_ADVANCED_ALGORITHMS" = true ] || [ "$USE_META_LEARNING" = true ] || | |
| [ "$USE_DISTRIBUTED_TRAINING" = true ] || [ "$USE_CURRICULUM_LEARNING" = true ] || | |
| [ "$USE_NEURAL_ARCHITECTURE_SEARCH" = true ] || [ "$USE_FEDERATED_LEARNING" = true ]; then | |
| ADVANCED_CONFIG="${PROJECT_DIR}/config_advanced.yaml" | |
| if [ -f "${ADVANCED_CONFIG}" ]; then | |
| print_status "Using advanced configuration: ${ADVANCED_CONFIG}" | |
| CONFIG_FILE="${ADVANCED_CONFIG}" | |
| else | |
| print_warning "Advanced configuration not found, using default config" | |
| fi | |
| fi | |
| } | |
| run_training() { | |
| print_status "Starting training..." | |
| cd "${PROJECT_DIR}" | |
| TRAIN_CMD="python scripts/train.py \ | |
| --experiment_type \"${EXPERIMENT_TYPE}\" \ | |
| --config \"${CONFIG_FILE}\" \ | |
| --num_epochs \"${NUM_EPOCHS}\" \ | |
| --batch_size \"${BATCH_SIZE}\" \ | |
| --model_name \"${MODEL_NAME}\" \ | |
| --output_dir \"${RESULTS_DIR}\" \ | |
| --device \"${DEVICE}\" \ | |
| --seed \"${SEED}\" \ | |
| --save_checkpoints" | |
| if [ "$USE_ADVANCED_ALGORITHMS" = true ]; then | |
| TRAIN_CMD="$TRAIN_CMD --advanced_algorithms" | |
| fi | |
| if [ "$USE_META_LEARNING" = true ]; then | |
| TRAIN_CMD="$TRAIN_CMD --meta_learning --meta_rounds ${META_LEARNING_ROUNDS}" | |
| fi | |
| if [ "$USE_DISTRIBUTED_TRAINING" = true ]; then | |
| TRAIN_CMD="$TRAIN_CMD --distributed_training --num_gpus ${NUM_GPUS}" | |
| fi | |
| if [ "$USE_CURRICULUM_LEARNING" = true ]; then | |
| TRAIN_CMD="$TRAIN_CMD --curriculum_learning" | |
| fi | |
| if [ "$USE_NEURAL_ARCHITECTURE_SEARCH" = true ]; then | |
| TRAIN_CMD="$TRAIN_CMD --neural_architecture_search --nas_generations ${NAS_GENERATIONS}" | |
| fi | |
| if [ "$USE_FEDERATED_LEARNING" = true ]; then | |
| TRAIN_CMD="$TRAIN_CMD --federated_learning --federated_clients ${FEDERATED_CLIENTS}" | |
| fi | |
| eval $TRAIN_CMD 2>&1 | tee "${LOGS_DIR}/training.log" | |
| if [ ${PIPESTATUS[0]} -eq 0 ]; then | |
| print_success "Training completed successfully" | |
| else | |
| print_error "Training failed" | |
| exit 1 | |
| fi | |
| } | |
| run_evaluation() { | |
| print_status "Running evaluation..." | |
| cd "${PROJECT_DIR}" | |
| MODEL_PATH="${RESULTS_DIR}/best_model.pt" | |
| if [ ! -f "${MODEL_PATH}" ]; then | |
| MODEL_PATH="${RESULTS_DIR}/checkpoint_epoch_${NUM_EPOCHS}_*.pt" | |
| MODEL_PATH=$(ls ${MODEL_PATH} 2>/dev/null | head -1) | |
| fi | |
| if [ -z "${MODEL_PATH}" ] || [ ! -f "${MODEL_PATH}" ]; then | |
| print_warning "No model checkpoint found, using untrained model" | |
| MODEL_PATH="" | |
| fi | |
| python scripts/evaluate.py \ | |
| --model_path "${MODEL_PATH}" \ | |
| --config "${CONFIG_FILE}" \ | |
| --num_episodes "${NUM_EVAL_EPISODES}" \ | |
| --output_dir "${RESULTS_DIR}/evaluation" \ | |
| --device "${DEVICE}" \ | |
| --compare_difficulties \ | |
| --compare_types \ | |
| --statistical_analysis \ | |
| 2>&1 | tee "${LOGS_DIR}/evaluation.log" | |
| if [ ${PIPESTATUS[0]} -eq 0 ]; then | |
| print_success "Evaluation completed successfully" | |
| else | |
| print_error "Evaluation failed" | |
| exit 1 | |
| fi | |
| } | |
| run_visualization() { | |
| print_status "Creating visualizations..." | |
| cd "${PROJECT_DIR}" | |
| VIZ_CMD="python scripts/visualize.py \ | |
| --results_dir \"${RESULTS_DIR}\" \ | |
| --output_dir \"${VISUALIZATIONS_DIR}\" \ | |
| --plot_types all" | |
| if [ "$USE_ADVANCED_ALGORITHMS" = true ]; then | |
| VIZ_CMD="$VIZ_CMD --advanced_algorithms" | |
| fi | |
| if [ "$USE_META_LEARNING" = true ]; then | |
| VIZ_CMD="$VIZ_CMD --meta_learning" | |
| fi | |
| if [ "$USE_DISTRIBUTED_TRAINING" = true ]; then | |
| VIZ_CMD="$VIZ_CMD --distributed_training" | |
| fi | |
| if [ "$USE_CURRICULUM_LEARNING" = true ]; then | |
| VIZ_CMD="$VIZ_CMD --curriculum_learning" | |
| fi | |
| if [ "$USE_NEURAL_ARCHITECTURE_SEARCH" = true ]; then | |
| VIZ_CMD="$VIZ_CMD --neural_architecture_search" | |
| fi | |
| if [ "$USE_FEDERATED_LEARNING" = true ]; then | |
| VIZ_CMD="$VIZ_CMD --federated_learning" | |
| fi | |
| eval $VIZ_CMD 2>&1 | tee "${LOGS_DIR}/visualization.log" | |
| if [ ${PIPESTATUS[0]} -eq 0 ]; then | |
| print_success "Basic visualizations created successfully" | |
| else | |
| print_error "Basic visualization failed" | |
| exit 1 | |
| fi | |
| if [ "$USE_ADVANCED_ALGORITHMS" = true ] || [ "$USE_META_LEARNING" = true ] || | |
| [ "$USE_DISTRIBUTED_TRAINING" = true ] || [ "$USE_CURRICULUM_LEARNING" = true ] || | |
| [ "$USE_NEURAL_ARCHITECTURE_SEARCH" = true ] || [ "$USE_FEDERATED_LEARNING" = true ]; then | |
| print_status "Creating advanced visualizations..." | |
| ADVANCED_VIZ_CMD="python scripts/visualize_advanced.py \ | |
| --results_dir \"${RESULTS_DIR}\" \ | |
| --output_dir \"${VISUALIZATIONS_DIR}\" \ | |
| --plot_types all" | |
| if [ "$USE_ADVANCED_ALGORITHMS" = true ]; then | |
| ADVANCED_VIZ_CMD="$ADVANCED_VIZ_CMD --advanced_algorithms" | |
| fi | |
| if [ "$USE_META_LEARNING" = true ]; then | |
| ADVANCED_VIZ_CMD="$ADVANCED_VIZ_CMD --meta_learning" | |
| fi | |
| if [ "$USE_DISTRIBUTED_TRAINING" = true ]; then | |
| ADVANCED_VIZ_CMD="$ADVANCED_VIZ_CMD --distributed_training" | |
| fi | |
| if [ "$USE_CURRICULUM_LEARNING" = true ]; then | |
| ADVANCED_VIZ_CMD="$ADVANCED_VIZ_CMD --curriculum_learning" | |
| fi | |
| if [ "$USE_NEURAL_ARCHITECTURE_SEARCH" = true ]; then | |
| ADVANCED_VIZ_CMD="$ADVANCED_VIZ_CMD --neural_architecture_search" | |
| fi | |
| if [ "$USE_FEDERATED_LEARNING" = true ]; then | |
| ADVANCED_VIZ_CMD="$ADVANCED_VIZ_CMD --federated_learning" | |
| fi | |
| eval $ADVANCED_VIZ_CMD 2>&1 | tee "${LOGS_DIR}/advanced_visualization.log" | |
| if [ ${PIPESTATUS[0]} -eq 0 ]; then | |
| print_success "Advanced visualizations created successfully" | |
| else | |
| print_warning "Advanced visualization failed, but basic visualizations completed" | |
| fi | |
| fi | |
| } | |
| run_demo() { | |
| print_status "Running demo..." | |
| cd "${PROJECT_DIR}" | |
| python scripts/demo.py \ | |
| --config "${CONFIG_FILE}" \ | |
| --model_name "${MODEL_NAME}" \ | |
| --num_problems 3 \ | |
| --difficulty "medium" \ | |
| --problem_type "arithmetic" \ | |
| --device "${DEVICE}" \ | |
| --show_solutions \ | |
| 2>&1 | tee "${LOGS_DIR}/demo.log" | |
| if [ ${PIPESTATUS[0]} -eq 0 ]; then | |
| print_success "Demo completed successfully" | |
| else | |
| print_error "Demo failed" | |
| exit 1 | |
| fi | |
| } | |
| generate_report() { | |
| print_status "Generating final report..." | |
| REPORT_FILE="${RESULTS_DIR}/experiment_report.txt" | |
| cat > "${REPORT_FILE}" << EOF | |
| RL-LLM Experiment Report | |
| ======================== | |
| Experiment Configuration: | |
| - Type: ${EXPERIMENT_TYPE} | |
| - Model: ${MODEL_NAME} | |
| - Epochs: ${NUM_EPOCHS} | |
| - Batch Size: ${BATCH_SIZE} | |
| - Device: ${DEVICE} | |
| - Seed: ${SEED} | |
| Results Directory: ${RESULTS_DIR} | |
| Visualizations Directory: ${VISUALIZATIONS_DIR} | |
| Logs Directory: ${LOGS_DIR} | |
| Generated Files: | |
| EOF | |
| if [ -d "${RESULTS_DIR}" ]; then | |
| echo "Results:" >> "${REPORT_FILE}" | |
| find "${RESULTS_DIR}" -type f -name "*.json" -o -name "*.pt" -o -name "*.yaml" | sort >> "${REPORT_FILE}" | |
| fi | |
| if [ -d "${VISUALIZATIONS_DIR}" ]; then | |
| echo -e "\nVisualizations:" >> "${REPORT_FILE}" | |
| find "${VISUALIZATIONS_DIR}" -type f -name "*.png" -o -name "*.pdf" -o -name "*.svg" | sort >> "${REPORT_FILE}" | |
| fi | |
| if [ -d "${LOGS_DIR}" ]; then | |
| echo -e "\nLogs:" >> "${REPORT_FILE}" | |
| find "${LOGS_DIR}" -type f -name "*.log" | sort >> "${REPORT_FILE}" | |
| fi | |
| print_success "Report generated: ${REPORT_FILE}" | |
| } | |
| show_help() { | |
| cat << EOF | |
| RL-LLM Comprehensive Run Script | |
| Usage: $0 [OPTIONS] [COMMANDS] | |
| Commands: | |
| all Run all components (default) | |
| train Run training only | |
| eval Run evaluation only | |
| visualize Create visualizations only | |
| demo Run demo only | |
| test Run tests only | |
| help Show this help message | |
| Options: | |
| --experiment-type TYPE Experiment type (rlvr, rlhf, comparison) [default: rlvr] | |
| --epochs N Number of training epochs [default: 5] | |
| --batch-size N Batch size [default: 4] | |
| --eval-episodes N Number of evaluation episodes [default: 20] | |
| --model MODEL Model name [default: gpt2] | |
| --device DEVICE Device to use (auto, cpu, cuda) [default: auto] | |
| --seed N Random seed [default: 42] | |
| --advanced-algorithms Enable advanced RL algorithms (SAC, TD3, etc.) | |
| --meta-learning Enable meta-learning capabilities | |
| --distributed-training Enable distributed training across GPUs | |
| --curriculum-learning Enable curriculum learning | |
| --neural-architecture-search Enable neural architecture search | |
| --federated-learning Enable federated learning | |
| --num-gpus N Number of GPUs for distributed training [default: 1] | |
| --meta-rounds N Number of meta-learning rounds [default: 10] | |
| --nas-generations N Number of NAS generations [default: 20] | |
| --federated-clients N Number of federated clients [default: 5] | |
| --no-tests Skip running tests | |
| --no-demo Skip running demo | |
| Examples: | |
| $0 | |
| $0 train | |
| $0 --epochs 10 --batch-size 8 | |
| $0 --advanced-algorithms --meta-learning | |
| $0 --distributed-training --num-gpus 4 | |
| $0 --neural-architecture-search --nas-generations 50 | |
| $0 --federated-learning --federated-clients 10 | |
| $0 eval visualize | |
| EOF | |
| } | |
| COMMANDS=() | |
| SKIP_TESTS=false | |
| SKIP_DEMO=false | |
| while [[ $ | |
| case $1 in | |
| --experiment-type) | |
| EXPERIMENT_TYPE="$2" | |
| shift 2 | |
| ;; | |
| --epochs) | |
| NUM_EPOCHS="$2" | |
| shift 2 | |
| ;; | |
| --batch-size) | |
| BATCH_SIZE="$2" | |
| shift 2 | |
| ;; | |
| --eval-episodes) | |
| NUM_EVAL_EPISODES="$2" | |
| shift 2 | |
| ;; | |
| --model) | |
| MODEL_NAME="$2" | |
| shift 2 | |
| ;; | |
| --device) | |
| DEVICE="$2" | |
| shift 2 | |
| ;; | |
| --seed) | |
| SEED="$2" | |
| shift 2 | |
| ;; | |
| --advanced-algorithms) | |
| USE_ADVANCED_ALGORITHMS=true | |
| shift | |
| ;; | |
| --meta-learning) | |
| USE_META_LEARNING=true | |
| shift | |
| ;; | |
| --distributed-training) | |
| USE_DISTRIBUTED_TRAINING=true | |
| shift | |
| ;; | |
| --curriculum-learning) | |
| USE_CURRICULUM_LEARNING=true | |
| shift | |
| ;; | |
| --neural-architecture-search) | |
| USE_NEURAL_ARCHITECTURE_SEARCH=true | |
| shift | |
| ;; | |
| --federated-learning) | |
| USE_FEDERATED_LEARNING=true | |
| shift | |
| ;; | |
| --num-gpus) | |
| NUM_GPUS="$2" | |
| shift 2 | |
| ;; | |
| --meta-rounds) | |
| META_LEARNING_ROUNDS="$2" | |
| shift 2 | |
| ;; | |
| --nas-generations) | |
| NAS_GENERATIONS="$2" | |
| shift 2 | |
| ;; | |
| --federated-clients) | |
| FEDERATED_CLIENTS="$2" | |
| shift 2 | |
| ;; | |
| --no-tests) | |
| SKIP_TESTS=true | |
| shift | |
| ;; | |
| --no-demo) | |
| SKIP_DEMO=true | |
| shift | |
| ;; | |
| --help|-h) | |
| show_help | |
| exit 0 | |
| ;; | |
| train|eval|visualize|demo|test|all) | |
| COMMANDS+=("$1") | |
| shift | |
| ;; | |
| *) | |
| print_error "Unknown option: $1" | |
| show_help | |
| exit 1 | |
| ;; | |
| esac | |
| done | |
| if [ ${ | |
| COMMANDS=("all") | |
| fi | |
| main() { | |
| print_status "Starting RL-LLM Comprehensive Run" | |
| print_status "Project directory: ${PROJECT_DIR}" | |
| print_status "Commands to run: ${COMMANDS[*]}" | |
| print_status "Advanced features enabled:" | |
| [ "$USE_ADVANCED_ALGORITHMS" = true ] && print_status " ✓ Advanced Algorithms (SAC, TD3, etc.)" | |
| [ "$USE_META_LEARNING" = true ] && print_status " ✓ Meta-Learning (${META_LEARNING_ROUNDS} rounds)" | |
| [ "$USE_DISTRIBUTED_TRAINING" = true ] && print_status " ✓ Distributed Training (${NUM_GPUS} GPUs)" | |
| [ "$USE_CURRICULUM_LEARNING" = true ] && print_status " ✓ Curriculum Learning" | |
| [ "$USE_NEURAL_ARCHITECTURE_SEARCH" = true ] && print_status " ✓ Neural Architecture Search (${NAS_GENERATIONS} generations)" | |
| [ "$USE_FEDERATED_LEARNING" = true ] && print_status " ✓ Federated Learning (${FEDERATED_CLIENTS} clients)" | |
| create_directories | |
| check_dependencies | |
| create_default_config | |
| for cmd in "${COMMANDS[@]}"; do | |
| case $cmd in | |
| all) | |
| if [ "$SKIP_TESTS" = false ]; then | |
| run_tests | |
| fi | |
| run_training | |
| run_evaluation | |
| run_visualization | |
| if [ "$SKIP_DEMO" = false ]; then | |
| run_demo | |
| fi | |
| ;; | |
| train) | |
| run_training | |
| ;; | |
| eval) | |
| run_evaluation | |
| ;; | |
| visualize) | |
| run_visualization | |
| ;; | |
| demo) | |
| run_demo | |
| ;; | |
| test) | |
| run_tests | |
| ;; | |
| *) | |
| print_error "Unknown command: $cmd" | |
| exit 1 | |
| ;; | |
| esac | |
| done | |
| generate_report | |
| print_success "All requested operations completed successfully!" | |
| print_status "Results saved to: ${RESULTS_DIR}" | |
| print_status "Visualizations saved to: ${VISUALIZATIONS_DIR}" | |
| print_status "Logs saved to: ${LOGS_DIR}" | |
| } | |
| main "$@" | |
Xet Storage Details
- Size:
- 17.1 kB
- Xet hash:
- 71a5a84240e63a4ed9d1300221ac57f54c0e28f44b58970393236be67c3bf5b6
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.