Workflows · November 14, 2026 · 3 min read
Batch jobs: processing a million images overnight
Learn how to orchestrate high-throughput GPU batch jobs to process millions of images using Python, Docker, and Podstack's per-second billing.
Modern machine learning workflows often hit a wall when transitioning from prototype to production. Running inference on a few dozen images in a Jupyter notebook is trivial, but processing a million images for a new feature or a data re-training pipeline is a massive engineering hurdle.
If you try to run this on a single instance, it will take weeks. If you try to manage a massive cluster manually, you’ll spend more time on infrastructure orchestration than on your model. The solution lies in high-throughput batch jobs that leverage per-second billing and massive parallelism.
The Architecture of a Million-Image Job
To process a million images overnight, you shouldn't think about "one big server." Instead, think about a fleet of ephemeral workers. The core requirements for this scale are:
- Decoupled Storage: Your images should live in S3-compatible storage.
- Message Queueing: Use a simple queue (like SQS or Redis) to distribute image URLs to workers.
- Stateless Workers: Each GPU worker pulls a batch, processes it, saves the result, and repeats.
- Auto-scaling Logic: You need the ability to spin up 100+ GPUs simultaneously and shut them down the millisecond the queue is empty.
Step 1: Containerize Your Inference Engine
First, wrap your model in a lightweight Python script. Avoid loading the model for every image; instead, load it once into the GPU VRAM and process images in batches of 32, 64, or 128 depending on your VRAM overhead.
import os
import torch
from PIL import Image
from my_model import ImageClassifier
# Initialize model once
model = ImageClassifier().to("cuda").eval()
def process_batch(image_paths):
images = [Image.open(p).convert("RGB") for p in image_paths]
inputs = torch.stack([transform(i) for i in images]).to("cuda")
with torch.no_grad():
results = model(inputs)
# Save results to a database or object storage
save_results(results)
def main():
while True:
# Pull batch from your queue
batch = queue.get_next_batch(size=64)
if not batch:
break
process_batch(batch)
if __name__ == "__main__":
main()
Step 2: Defining the Job
With Podstack, you don’t need to manage Kubernetes manifests. You define a GPU function or a job that points to your container. Because Podstack bills per second, you can scale horizontally without worrying about "rounding up" to the nearest hour, which is often where the hidden costs of batch processing lie.
Using the Podstack API, you can trigger a job that scales based on the intensity of your workload. Ensure your PODSTACK_API_KEY is exported in your environment.
Podstack does not ship a command-line interface. Use the console, the Python package `podstack-sdk`, or the API at https://podstack.ai/api/v1 with a `ps_live_` key.
Step 3: Optimization for Throughput
When processing a million images, "micro-optimizations" become "macro-savings."
- Pre-fetching: While the GPU is busy performing inference on Batch A, your CPU should be downloading and decoding Batch B. Use a multi-threaded data loader to ensure the GPU never sits idle.
- Mixed Precision: Use
torch.cuda.amp.autocast(). For most inference tasks, FP16 or BF16 provides a 2x speedup with negligible accuracy loss. - Locality: Ensure your GPU workers are in the same region as your data bucket to minimize egress costs and latency.
Managing Costs
The "overnight" requirement implies a window of roughly 8 to 10 hours. To process 1,000,000 images in 8 hours, you need to process ~125,000 images per hour, or ~35 images per second.
If a single A100 can process 20 images per second with a ResNet-based architecture, you only need two or three GPUs to finish the task. However, for more complex transformer-based models (like CLIP or a large ViT), you might only get 2 images per second. In that case, you’d spin up 20 replicas. On Podstack, the cost is the same whether you run 1 GPU for 20 hours or 20 GPUs for 1 hour. The latter gets you the data faster.
Why Podstack for Large Batches?
Handling a million images is a test of infrastructure stability. Podstack is built for this specific high-concurrency lifecycle:
- Serverless Inference: If your workload is bursty, use GPU functions that spin up on demand when messages hit the queue.
- On-Demand Availability: When you need 50 GPUs now, Podstack’s fleet management ensures you aren't stuck in a "pending" state.
- Python-First Workflow: You can trigger these jobs directly from your training scripts using the Python SDK, making it easy to integrate into a CI/CD pipeline for ML.
By decoupling your compute from your long-running instances and using podstack to orchestrate ephemeral GPU workers, you turn a "million-image nightmare" into a routine automated task that finishes before your morning coffee is ready.