1+ #! /bin/bash
2+ # SBATCH --job-name=embed_images_job # [REQUIRED] Set a descriptive job name
3+ # SBATCH --nodes=NUM_NODES # [REQUIRED] Number of nodes to use
4+ # SBATCH --ntasks-per-node=TASKS_PER_NODE # [RECOMMENDED] Number of tasks per node
5+ # SBATCH --gpus-per-task=1 # [REQUIRED] Number of GPUs per task (set to 1)
6+ # SBATCH --cpus-per-task=CPUS_PER_TASK # [RECOMMENDED] Number of CPU cores per task (e.g., 48)
7+ # SBATCH --partition=PARTITION_NAME # [REQUIRED] Partition/queue name (e.g., gpu, gpu-exp)
8+ # SBATCH --time=HH:MM:SS # [REQUIRED] Walltime limit (e.g., 6:00:00)
9+ # SBATCH --output=logs/embed_images_%j.out # [OPTIONAL] Stdout log file (%j = job ID)
10+ # SBATCH --error=logs/embed_images_%j.err # [OPTIONAL] Stderr log file
11+ # SBATCH --account=ACCOUNT_NAME # [REQUIRED] Project account for allocation
12+ # SBATCH --mail-type=ALL # [OPTIONAL] Email notifications (BEGIN, END, FAIL, ALL)
13+ # SBATCH --mail-user=YOUR_EMAIL@domain.edu # [OPTIONAL] Email address for notifications
14+
15+ # === Load modules and activate environment ===
16+ module load cuda/VERSION # [REQUIRED] Load CUDA module (e.g., cuda/12.4.1)
17+ source /path/to/your/venv/bin/activate # [REQUIRED] Activate your Python virtual environment
18+
19+ # === Ensure package is installed ===
20+ # Make sure hpc-inference package is installed in your environment
21+ which python # Print Python path for debugging
22+
23+ # === Set data paths ===
24+ TARGET_DIR=" /path/to/your/image_directory" # [REQUIRED] Directory containing input images
25+ OUTPUT_DIR=" /path/to/your/output_dir" # [REQUIRED] Directory to save output embeddings
26+
27+ # === Choose your configuration method ===
28+ # Option 1: Use config file (RECOMMENDED for production)
29+ CONFIG_FILE=" /path/to/your/images_config.yaml" # Path to YAML config file
30+
31+ srun python -m hpc_inference.inference.embed.open_clip_embed \
32+ " ${TARGET_DIR} " \
33+ " ${OUTPUT_DIR} " \
34+ --input_type images \
35+ --config " ${CONFIG_FILE} "
36+
37+ # Option 2: Use command line arguments (for quick testing)
38+ # Uncomment and modify the lines below, comment out the config version above
39+ #
40+ # srun python -m hpc_inference.inference.embed.open_clip_embed \
41+ # "${TARGET_DIR}" \
42+ # "${OUTPUT_DIR}" \
43+ # --input_type images \
44+ # --model_name "ViT-B-32" \
45+ # --pretrained "openai" \
46+ # --batch_size 32 \
47+ # --num_workers 28 \
48+ # --prefetch_factor 32 \
49+ # --max_rows_per_file 10000 \
50+ # --out_prefix "embed_results" \
51+ # --uuid_mode filename \
52+ # --evenly_distribute \
53+ # --stagger \
54+ # --validate_images
55+
56+
57+ # -------------------------------
58+ # IMAGE FOLDER-SPECIFIC PARAMETERS
59+ # -------------------------------
60+ # --input_type images: Tells the script to process image files from a directory
61+ # --uuid_mode: How to generate unique IDs from image paths:
62+ # - "filename": Use just the filename (image001.jpg)
63+ # - "relative": Use relative path from TARGET_DIR (subfolder/image001.jpg)
64+ # - "fullpath": Use full absolute path (/full/path/to/image001.jpg)
65+ # - "hash": Use MD5 hash of the full path (a1b2c3d4e5f6g7h8)
66+ # --validate_images: [OPTIONAL] Validate that all images can be opened with PIL
67+ # Slower but safer - catches corrupted files before processing
68+ # --file_list: NOT applicable for image folders (will cause error)
69+
70+ # SUPPORTED IMAGE FORMATS:
71+ # .jpg, .jpeg, .png, .bmp, .tif, .tiff, .webp
72+ # Images are automatically converted to RGB mode for model processing
73+
74+ # DIRECTORY STRUCTURE:
75+ # TARGET_DIR can contain:
76+ # - Flat structure: /images/img1.jpg, /images/img2.jpg, ...
77+ # - Nested structure: /images/class1/img1.jpg, /images/class2/img2.jpg, ...
78+ # All .jpg, .jpeg, .png, etc. files will be found recursively
79+
80+ # -------------------------------
81+ # SLURM Template Field Explanations
82+ # -------------------------------
83+ # --job-name: Name for your job in the queue/monitoring system.
84+ # --nodes: Number of nodes to allocate for the job.
85+ # --gpus-per-task: Number of GPUs per task (set to 1 unless using model parallelism).
86+ # --cpus-per-task: Number of CPU cores per task (should match or exceed your data loader workers).
87+ # --ntasks-per-node: Number of parallel tasks per node.
88+ # For image processing, balance between available GPUs and I/O capacity.
89+ # --partition: Cluster partition/queue to submit to (e.g., gpu, gpu-exp).
90+ # --time: Maximum walltime for the job (format: HH:MM:SS).
91+ # --output: Path for standard output log file (use %j for job ID).
92+ # --error: Path for standard error log file.
93+ # --account: Your allocation/project account for resource usage.
94+
95+ # PERFORMANCE TIPS FOR IMAGE FOLDERS:
96+ # - Use --evenly_distribute for better load balancing when file sizes vary
97+ # - Use --validate_images if you suspect corrupted files (adds startup time)
98+ # - Consider --uuid_mode based on your downstream analysis needs
99+ # - Use --stagger to reduce file system stress during startup
100+ # - For large datasets, consider converting to Parquet format first for better performance
0 commit comments