Skip to content

Commit 59362da

Browse files
committed
updated slurm & config templates for different embedding use cases
1 parent 25b6c64 commit 59362da

7 files changed

Lines changed: 596 additions & 157 deletions
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# =============================================================================
2+
# Configuration File for Batch Image Embedding from Image Folders
3+
# =============================================================================
4+
# This configuration is optimized for processing image files directly from
5+
# a directory structure.
6+
# -----------------------------------------------------------------------------
7+
8+
# ---------------------------
9+
# Model Configurations
10+
# ---------------------------
11+
# List one or more models to use for embedding.
12+
# For OpenCLIP models, see: https://github.com/mlfoundations/open_clip#pretrained-models
13+
models:
14+
vit_b_32:
15+
name: ViT-B-32
16+
pretrained: openai
17+
# Uncomment to add more models for multi-model processing
18+
# vit_l_14:
19+
# name: ViT-L-14
20+
# pretrained: laion2b_s32b_b82k
21+
# bioclip:
22+
# name: hf-hub:imageomics/bioclip
23+
# pretrained: null
24+
25+
# ---------------------------
26+
# DataLoader Configurations
27+
# ---------------------------
28+
batch_size: 32 # Number of images per batch (adjust based on GPU memory)
29+
num_workers: 28 # Number of worker processes for data loading
30+
prefetch_factor: 32 # Number of batches prefetched by each worker
31+
32+
# ---------------------------
33+
# Image Processing Settings
34+
# ---------------------------
35+
validate_images: false # Set to true to validate all images can be opened with PIL
36+
# Slower startup but catches corrupted files
37+
38+
# How to generate unique IDs from image file paths
39+
uuid_mode: filename # Options:
40+
# - "filename": image001.jpg
41+
# - "relative": subfolder/image001.jpg
42+
# - "fullpath": /full/path/to/image001.jpg
43+
# - "hash": MD5 hash of full path
44+
45+
# ---------------------------
46+
# Distributed Processing
47+
# ---------------------------
48+
evenly_distribute: true # Distribute files based on size for load balancing
49+
stagger: false # Stagger worker start times to reduce file system load
50+
51+
# ---------------------------
52+
# Output Configurations
53+
# ---------------------------
54+
max_rows_per_file: 50000 # Maximum number of embeddings per output file
55+
out_prefix: image_embeds # Prefix for output files
56+
57+
# =============================================================================
58+
# IMAGE DIRECTORY REQUIREMENTS:
59+
# =============================================================================
60+
# Your image directory can have any structure:
61+
#
62+
# Flat structure:
63+
# /images/
64+
# ├── image001.jpg
65+
# ├── image002.png
66+
# └── image003.jpeg
67+
#
68+
# Nested structure:
69+
# /images/
70+
# ├── category1/
71+
# │ ├── img1.jpg
72+
# │ └── img2.png
73+
# └── category2/
74+
# ├── img3.jpg
75+
# └── img4.png
76+
#
77+
# Supported formats: .jpg, .jpeg, .png, .bmp, .tif, .tiff, .webp
78+
# All images are automatically converted to RGB mode for processing.
79+
#
80+
# UUID GENERATION MODES:
81+
# - filename: Good for flat directories with unique filenames
82+
# - relative: Good for nested directories where path info is important
83+
# - fullpath: Good when you need absolute path traceability
84+
# - hash: Good for very long paths or when you want anonymized IDs
85+
# =============================================================================
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# =============================================================================
2+
# Configuration File for Batch Image Embedding from Parquet Files
3+
# =============================================================================
4+
# This configuration is optimized for processing Parquet files containing
5+
# encoded image data with metadata.
6+
# -----------------------------------------------------------------------------
7+
8+
# ---------------------------
9+
# Model Configurations
10+
# ---------------------------
11+
# List one or more models to use for embedding.
12+
# For OpenCLIP models, see: https://github.com/mlfoundations/open_clip#pretrained-models
13+
models:
14+
bioclip:
15+
name: hf-hub:imageomics/bioclip
16+
pretrained: null
17+
# Uncomment to add more models for multi-model processing
18+
# vit_b_32:
19+
# name: ViT-B-32
20+
# pretrained: openai
21+
# vit_l_14:
22+
# name: ViT-L-14
23+
# pretrained: laion2b_s32b_b82k
24+
25+
# ---------------------------
26+
# DataLoader Configurations
27+
# ---------------------------
28+
batch_size: 32 # Number of images per batch (adjust based on GPU memory)
29+
num_workers: 28 # Number of worker processes for data loading
30+
prefetch_factor: 32 # Number of batches prefetched by each worker
31+
32+
# ---------------------------
33+
# Parquet-Specific Settings
34+
# ---------------------------
35+
read_batch_size: 256 # Number of rows to read from Parquet at a time
36+
# Larger values = more memory usage but potentially faster I/O
37+
38+
# Columns to read from Parquet files (must exist in your data)
39+
read_columns:
40+
- uuid # [REQUIRED] Unique identifier for each image
41+
- image # [REQUIRED] Encoded image bytes (JPEG, PNG, etc.)
42+
- original_size # [OPTIONAL] Original image dimensions
43+
- resized_size # [OPTIONAL] Resized image dimensions
44+
45+
# ---------------------------
46+
# Distributed Processing
47+
# ---------------------------
48+
evenly_distribute: true # Distribute files based on size for load balancing
49+
stagger: false # Stagger worker start times to reduce I/O congestion
50+
51+
# ---------------------------
52+
# Output Configurations
53+
# ---------------------------
54+
max_rows_per_file: 50000 # Maximum number of embeddings per output file
55+
out_prefix: parquet_embeds # Prefix for output files
56+
57+
# =============================================================================
58+
# PARQUET DATA REQUIREMENTS:
59+
# =============================================================================
60+
# Your Parquet files must contain:
61+
# 1. 'uuid' column: Unique string identifier for each image
62+
# 2. 'image' column: Image data encoded as bytes (from PIL Image.save() to BytesIO)
63+
# 3. Optional metadata columns as specified in read_columns
64+
#
65+
# Example of creating compatible Parquet data:
66+
# ```python
67+
# import io
68+
# from PIL import Image
69+
# import pandas as pd
70+
# import pyarrow.parquet as pq
71+
#
72+
# # Encode image to bytes
73+
# img = Image.open('image.jpg')
74+
# img_bytes = io.BytesIO()
75+
# img.save(img_bytes, format='JPEG')
76+
# img_bytes = img_bytes.getvalue()
77+
#
78+
# # Create DataFrame
79+
# df = pd.DataFrame({
80+
# 'uuid': ['img_001'],
81+
# 'image': [img_bytes],
82+
# 'original_size': [(1024, 768)],
83+
# 'resized_size': [(224, 224)]
84+
# })
85+
#
86+
# # Save to Parquet
87+
# df.to_parquet('images.parquet')
88+
# ```
89+
# =============================================================================

configs/config_embed_template.yaml

Lines changed: 0 additions & 52 deletions
This file was deleted.
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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

Comments
 (0)