| #!/bin/bash |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| SLURM_ARRAY_TASK_ID=3 |
| |
| |
| set -e |
|
|
| |
| BASE_OUTPUT_DIR="/work/jf381/data/icl_jay" |
| RAW_DATA_DIR="/work/jf381/data/raw_datasets" |
| NUM_PROMPTS=1000 |
| SAMPLES_PER_CLASS=50 |
| IMAGE_SIZE="256 256" |
| NUM_WORKERS=8 |
|
|
| |
| mkdir -p "$BASE_OUTPUT_DIR" |
| mkdir -p "$RAW_DATA_DIR" |
| mkdir -p "/work/jf381/code/code/ICL_LOG/dataset_generation" |
|
|
| |
| log_message() { |
| echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" |
| } |
|
|
| |
| prepare_dataset() { |
| local dataset_type=$1 |
| local output_dir="$BASE_OUTPUT_DIR/$dataset_type" |
| |
| log_message "Starting preparation of $dataset_type dataset..." |
| log_message "SLURM Job ID: $SLURM_JOB_ID" |
| log_message "Array Task ID: $SLURM_ARRAY_TASK_ID" |
| log_message "Output directory: $output_dir" |
| log_message "Using $NUM_WORKERS worker threads" |
| |
| |
| start_time=$(date +%s) |
| |
| |
| python /work/jf381/code/code/ICL_Jay/data/prepare_datasets.py \ |
| --dataset "$dataset_type" \ |
| --data_dir "$RAW_DATA_DIR" \ |
| --output_dir "$output_dir" \ |
| --num_prompts $NUM_PROMPTS \ |
| --samples_per_class $SAMPLES_PER_CLASS \ |
| --image_size $IMAGE_SIZE \ |
| --num_workers $NUM_WORKERS \ |
| --force |
| |
| |
| if [ $? -eq 0 ]; then |
| |
| end_time=$(date +%s) |
| duration=$((end_time - start_time)) |
| |
| log_message "β
$dataset_type preparation completed successfully!" |
| log_message "β±οΈ Processing time: ${duration} seconds ($(($duration / 60)) minutes)" |
| |
| |
| log_message "π Running verification for $dataset_type..." |
| python /work/jf381/code/code/ICL_Jay/data/prepare_datasets.py \ |
| --dataset "$dataset_type" \ |
| --output_dir "$output_dir" \ |
| --verify |
| |
| if [ $? -eq 0 ]; then |
| log_message "β
$dataset_type verification passed!" |
| else |
| log_message "β $dataset_type verification failed!" |
| return 1 |
| fi |
| |
| |
| log_message "π Dataset statistics for $dataset_type:" |
| if [ -f "$output_dir/dataset_metadata.json" ]; then |
| python3 -c " |
| import json |
| import os |
| |
| try: |
| with open('$output_dir/dataset_metadata.json', 'r') as f: |
| meta = json.load(f) |
| |
| print(f' Total prompts: {meta.get(\"num_prompts\", \"N/A\")}') |
| print(f' Training prompts: {len(meta.get(\"train_prompts\", []))}') |
| print(f' Test prompts: {len(meta.get(\"test_prompts\", []))}') |
| print(f' Classes used: {len(meta.get(\"train_classes_used\", []))}') |
| |
| if 'data_split_info' in meta: |
| split_info = meta['data_split_info'] |
| print(f' Train split: {split_info.get(\"train_split_used\", \"N/A\")}') |
| print(f' Test split: {split_info.get(\"test_split_used\", \"N/A\")}') |
| print(f' No data leakage: {split_info.get(\"no_data_leakage\", False)}') |
| |
| if 'processing_stats' in meta: |
| stats = meta['processing_stats'] |
| print(f' Completed tasks: {stats.get(\"completed_tasks\", \"N/A\")}') |
| print(f' Failed tasks: {stats.get(\"failed_tasks\", \"N/A\")}') |
| |
| except Exception as e: |
| print(f' Error reading metadata: {e}') |
| " |
| fi |
| |
| |
| dataset_size=$(du -sh "$output_dir" 2>/dev/null | cut -f1 || echo 'N/A') |
| log_message " Dataset size: $dataset_size" |
| |
| return 0 |
| else |
| log_message "β $dataset_type preparation failed!" |
| return 1 |
| fi |
| } |
|
|
| |
| log_message "===================================================" |
| log_message "SLURM Array Dataset Generation Job" |
| log_message "===================================================" |
| log_message "SLURM_JOB_ID: $SLURM_JOB_ID" |
| log_message "SLURM_ARRAY_JOB_ID: $SLURM_ARRAY_JOB_ID" |
| log_message "SLURM_ARRAY_TASK_ID: $SLURM_ARRAY_TASK_ID" |
| log_message "HOSTNAME: $(hostname)" |
| log_message "GPU INFO: $(nvidia-smi --query-gpu=name --format=csv,noheader | head -1)" |
| log_message "===================================================" |
|
|
| |
| log_message "Checking Python dependencies..." |
| python3 -c " |
| import sys |
| required_packages = ['datasets', 'torch', 'torchvision', 'PIL', 'numpy', 'tqdm'] |
| missing_packages = [] |
| |
| for package in required_packages: |
| try: |
| if package == 'PIL': |
| import PIL |
| else: |
| __import__(package) |
| print(f'β
{package}') |
| except ImportError: |
| missing_packages.append(package) |
| print(f'β {package}') |
| |
| if missing_packages: |
| print(f'Missing packages: {missing_packages}') |
| sys.exit(1) |
| else: |
| print('All dependencies satisfied!') |
| " |
|
|
| if [ $? -ne 0 ]; then |
| log_message "β Dependency check failed!" |
| exit 1 |
| fi |
|
|
| |
| case $SLURM_ARRAY_TASK_ID in |
| 0) |
| DATASET_TYPE="cifar10" |
| log_message "π Task 0: Preparing CIFAR-10 dataset" |
| log_message " - 10 classes with automatic train/test split" |
| log_message " - Fast processing, good for initial testing" |
| ;; |
| 1) |
| DATASET_TYPE="cifar100" |
| log_message "π Task 1: Preparing CIFAR-100 dataset" |
| log_message " - 100 classes with automatic train/test split" |
| log_message " - Moderate complexity, comprehensive testing" |
| ;; |
| 2) |
| DATASET_TYPE="imagenet10" |
| log_message "π Task 2: Preparing ImageNet10 dataset" |
| log_message " - 10 carefully selected classes from ImageNet100" |
| log_message " - Optimized for in-context learning performance" |
| log_message " - Uses HuggingFace ilee0022/ImageNet100 dataset" |
| ;; |
| 3) |
| DATASET_TYPE="imagenet100" |
| log_message "π Task 3: Preparing ImageNet100 dataset" |
| log_message " - 100 classes from HuggingFace dataset" |
| log_message " - Comprehensive evaluation dataset" |
| log_message " - Proper train/validation split from HuggingFace" |
| ;; |
| *) |
| log_message "β Invalid SLURM_ARRAY_TASK_ID: $SLURM_ARRAY_TASK_ID" |
| log_message "Valid IDs are 0-3 (cifar10, cifar100, imagenet10, imagenet100)" |
| exit 1 |
| ;; |
| esac |
|
|
| |
| log_message "Starting dataset preparation for $DATASET_TYPE..." |
| prepare_dataset "$DATASET_TYPE" |
|
|
| if [ $? -eq 0 ]; then |
| log_message "===================================================" |
| log_message "β
SUCCESS: $DATASET_TYPE dataset preparation completed!" |
| log_message "===================================================" |
| log_message "Dataset location: $BASE_OUTPUT_DIR/$DATASET_TYPE" |
| log_message "" |
| log_message "To use this dataset in your training script:" |
| log_message "python your_training_script.py \\" |
| log_message " --data_type image_data \\" |
| log_message " --dataset_type $DATASET_TYPE \\" |
| log_message " --image_dir $BASE_OUTPUT_DIR/$DATASET_TYPE \\" |
| log_message " --use_vgg_features \\" |
| log_message " --image_noise_level 0.1" |
| log_message "" |
| log_message "For combined manifolds:" |
| log_message "python your_training_script.py \\" |
| log_message " --data_type combine_manifold \\" |
| log_message " --manifold_list swiss_roll,sphere,image_data \\" |
| log_message " --dataset_type $DATASET_TYPE \\" |
| log_message " --image_dir $BASE_OUTPUT_DIR/$DATASET_TYPE \\" |
| log_message " --use_vgg_features" |
| log_message "===================================================" |
| else |
| log_message "===================================================" |
| log_message "β FAILURE: $DATASET_TYPE dataset preparation failed!" |
| log_message "===================================================" |
| log_message "Check the error logs above for details." |
| log_message "Common issues:" |
| log_message " - Network connectivity for HuggingFace datasets" |
| log_message " - Insufficient disk space" |
| log_message " - Missing Python dependencies" |
| log_message " - GPU memory issues" |
| log_message "===================================================" |
| exit 1 |
| fi |
|
|
| log_message "Job completed at $(date)" |
| log_message "SLURM_ARRAY_TASK_ID $SLURM_ARRAY_TASK_ID finished successfully" |