Generate images in batch with a diffusion model
This tutorial walks you through running high-throughput batch image
generation on a JSONL file of prompts using a diffusion model. You
submit the
text-to-image batch job bundle on GitHub
Each selected line in the JSONL becomes a generation task. The
scheduler distributes tasks across available GPU workers, and each
worker loads the diffusion pipeline once and reuses it for every task
it runs. When a line carries a caption field, or a
generated_text field chained from the vLLM batch inference
bundle's output, the job composites the text over the generated image
as crisp typography. Lines without a caption produce pure imagery, so
the bundle works equally well as a plain text-to-image batch
generator.
Estimated time: 30–60 minutes, including farm setup. The first run also downloads about 13 GB of model weights per worker.
Running this tutorial incurs charges for the GPU worker instances that process the job.
Overview
To complete this tutorial, follow these steps:
-
Set up your farm.
-
Prepare the input file.
-
Submit the image generation job.
-
Download and browse the gallery.
-
Clean up resources.
Set up your farm
You need a service-managed fleet with NVIDIA GPUs and at least
32 GB RAM, and a queue with a conda queue environment attached that
reads CondaPackages and CondaChannels job
parameters. FLUX.2 Klein 4B fits comfortably on 16 GB and larger GPUs
(for example, L4 or A10G) thanks to CPU offloading.
The fastest way to get a compatible farm is to deploy the
CUDA farm CloudFormation template on GitHubCREATE_COMPLETE, configure the
Deadline Cloud CLI to use the new farm:
deadline config set defaults.farm_idFarmId-from-stack-outputsdeadline config set defaults.queue_idCUDAQueueId-from-stack-outputs
Note
The bundle includes an InstallDeps job environment
that installs PyTorch and the latest diffusers library from git on
top of the queue's conda environment on every session, plus
downloads four small Google Fonts for the caption overlay. Expect
30–90 seconds of additional setup time per worker on first
use, plus the model download on first run. If your fleet runs in a
network-restricted VPC, you need to either pre-bake the
dependencies into a custom AMI or conda channel, or open
egress.
Prepare the input file
The input is a JSONL file with one JSON object per line. Each
line must have either a prompt field or a
generated_text field chained from the vLLM batch
inference bundle's output:
{"prompt": "A golden hour photo of a sourdough loaf on a linen-covered table", "id": "loaf_01"} {"prompt": "A bakery storefront at sunrise, photorealistic", "caption": "OPEN AT DAWN", "id": "shop_01"} {"prompt": "Write a slogan for sourdough", "id": "001", "generated_text": "Real grain. Real fermentation. Real you.", "style": "rustic flat lay, warm tones"}
Optional per-line fields include caption for overlay
text, style to override the job-level style suffix,
font, width and height,
steps, and seed. The bundle includes the
same zero-dependency prompt builder tool as the vLLM batch bundle.
Open tools/prompt_builder.html to build input
files, import a JSONL by drag and drop, and add per-prompt
overrides.
The bundled sample_prompts.jsonl file is a
10-image bakery campaign demo: bakery slogans generated by the vLLM
batch inference bundle, with style hints layered on for evocative
visuals.
Submit the image generation job
To submit with the GUI submitter
-
From the
text_to_image_batchbundle directory, open the submitter:deadline bundle gui-submit . -
Pick your input JSONL file. Try
sample_prompts.jsonlfor the bakery campaign demo. -
Set the Prompt Range (for example,
1-10for the first 10 prompts) and pick an output directory. -
Optionally tweak StyleSuffix, Width, and Height. Leave Overlay Caption at
trueif your JSONL has captions or slogans, or set it tofalsefor pure image generation. -
Choose Submit.
Alternatively, submit with the CLI:
deadline bundle submit . \ --parameter InputFile=$PWD/sample_prompts.jsonl \ --parameter Prompts=1-10 \ --parameter OutputDir=$PWD/output
The Prompts and ChunkSize parameters
work the same way as in the vLLM batch inference bundle, using the
Deadline Cloud task chunking feature. For more information, see
Task chunking for job templates.
The ModelName parameter accepts anything the diffusers
library can load, including SDXL Turbo and Stable Diffusion 3.5. For
the full parameter list and the settings for other models, see
the parameters table in the sample README on GitHub
Download and browse the gallery
To download and browse the results
-
After the job completes, run the download command from the same directory you used at submit time, so the
OutputDirpath resolves to the same place:deadline job download-output --job-idjob-id -
Every artifact lands under an
output/subdirectory of the path you set asOutputDir. The raw PNGs are inoutput/images/, the combined metadata is inoutput/output.jsonl, andoutput/gallery.htmlis a static gallery viewer with search and CSV export. -
If the gallery's images don't load when you open
gallery.htmldirectly, that's a browser security restriction onfile://URLs. Serve the directory instead:cdOutputDir/output && python3 -m http.server 8080 # open http://localhost:8080/gallery.html
Chain from vLLM batch inference
The classic flow pairs this bundle with the vLLM batch inference bundle:
-
Generate text with the vLLM batch inference bundle: slogans, captions, scene descriptions, or alt-text. The output is
output.jsonlwith agenerated_textfield per line. See Run batch LLM inference with vLLM. -
(Optional) Open
tools/prompt_builder.html, drop inoutput.jsonl, add or edit per-prompt captions, styles, or visual descriptions, and re-export. -
Submit this bundle with the JSONL as
InputFile. The per-task script automatically usesgenerated_textas the overlay caption.
When a line has both a generated_text slogan and the
original LLM prompt, the task script tries to pull the
subject out of the request and use it as the visual prompt for the
diffusion model, because slogans are often too abstract to give the
model a concrete subject. The worker logs the visual prompt source
per task so you can spot misextractions.
Clean up
To avoid ongoing charges, clean up the resources that you created for this tutorial:
To clean up tutorial resources
-
If you deployed the CUDA farm CloudFormation template, delete the CloudFormation stack from the CloudFormation console.
-
If you used an existing farm and created a GPU fleet specifically for this tutorial, stop or delete that fleet. If you used a pre-existing shared fleet, leave it in place.
-
Remove local output files if you no longer need them.
Related resources
The following resources provide additional information: