#!/bin/bash # Liquid Neural Network Hyperparameter Tuning - 30 Trials # Mission: Optimize Liquid NN for ODE integration, sparsity, and inference speed # Expected Duration: 4-6 hours # Combined Objective: sharpe_ratio - 0.1 * log(inference_ms) set -euo pipefail # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Configuration SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="${SCRIPT_DIR}" TUNING_CONFIG="${PROJECT_ROOT}/services/ml_training_service/tuning_config.yaml" OUTPUT_DIR="${PROJECT_ROOT}/ml/trained_models/tuning/liquid_nn" LOG_FILE="${OUTPUT_DIR}/tuning_execution.log" # Tuning parameters MODEL_TYPE="LIQUID" NUM_TRIALS=30 MAX_EPOCHS_PER_TRIAL=100 # Validation symbols (high-frequency trading suitable assets) SYMBOLS=("6E.FUT" "ZN.FUT" "ES.FUT" "NQ.FUT") # Hardware configuration USE_GPU=true GPU_DEVICE=0 echo -e "${BLUE}╔════════════════════════════════════════════════════════════╗${NC}" echo -e "${BLUE}║ Liquid Neural Network Hyperparameter Tuning ║${NC}" echo -e "${BLUE}║ 30 Trials - ODE Integration & Inference Speed Optimized ║${NC}" echo -e "${BLUE}╚════════════════════════════════════════════════════════════╝${NC}" echo "" # Function to print section headers print_section() { echo -e "\n${GREEN}═══ $1 ═══${NC}\n" } # Function to check prerequisites check_prerequisites() { print_section "Checking Prerequisites" # Check if tuning config exists if [ ! -f "${TUNING_CONFIG}" ]; then echo -e "${RED}✗ Tuning config not found: ${TUNING_CONFIG}${NC}" exit 1 fi echo -e "${GREEN}✓ Tuning configuration loaded${NC}" # Verify LIQUID configuration exists in tuning_config.yaml if ! grep -q "LIQUID:" "${TUNING_CONFIG}"; then echo -e "${RED}✗ LIQUID model not configured in ${TUNING_CONFIG}${NC}" exit 1 fi echo -e "${GREEN}✓ LIQUID model configuration verified${NC}" # Check GPU availability if command -v nvidia-smi &> /dev/null; then echo -e "${GREEN}✓ GPU detected:${NC}" nvidia-smi --query-gpu=name,memory.total,driver_version --format=csv,noheader # Check CUDA availability for RTX 3050 Ti local gpu_name gpu_name=$(nvidia-smi --query-gpu=name --format=csv,noheader) if [[ "${gpu_name}" == *"3050"* ]]; then echo -e "${GREEN}✓ RTX 3050 Ti detected - CUDA acceleration enabled${NC}" fi else echo -e "${YELLOW}⚠ GPU not detected, will use CPU (slower)${NC}" USE_GPU=false fi # Check if services are running if ! pgrep -f "ml_training_service" > /dev/null; then echo -e "${YELLOW}⚠ ML Training Service not running, attempting to start...${NC}" cargo run -p ml_training_service --release & sleep 5 fi echo -e "${GREEN}✓ ML Training Service is running${NC}" # Check data files local missing_data=false for symbol in "${SYMBOLS[@]}"; do local data_file="${PROJECT_ROOT}/test_data/${symbol}_2024-01-02.dbn.zst" if [ ! -f "${data_file}" ]; then echo -e "${YELLOW}⚠ Missing data file: ${symbol} (will use available data)${NC}" else echo -e "${GREEN}✓ Data file found: ${symbol}${NC}" fi done } # Function to create output directory prepare_output_directory() { print_section "Preparing Output Directory" mkdir -p "${OUTPUT_DIR}" mkdir -p "${OUTPUT_DIR}/logs" mkdir -p "${OUTPUT_DIR}/checkpoints" mkdir -p "${OUTPUT_DIR}/plots" mkdir -p "${OUTPUT_DIR}/analysis" echo -e "${GREEN}✓ Output directory prepared: ${OUTPUT_DIR}${NC}" # Initialize log file cat > "${LOG_FILE}" <