View a markdown version of this page

Generate images in batch with a diffusion model - Deadline Cloud

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 to a GPU fleet on your Deadline Cloud farm. The default model is FLUX.2 Klein 4B on Hugging Face, which is Apache 2.0 licensed, ungated, distilled to 4 steps, and needs about 13 GB of video RAM (VRAM).

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:

  1. Set up your farm.

  2. Prepare the input file.

  3. Submit the image generation job.

  4. Download and browse the gallery.

  5. 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 GitHub, which is the same template the vLLM batch inference bundle uses. After the stack reaches CREATE_COMPLETE, configure the Deadline Cloud CLI to use the new farm:

deadline config set defaults.farm_id FarmId-from-stack-outputs deadline config set defaults.queue_id CUDAQueueId-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
  1. From the text_to_image_batch bundle directory, open the submitter:

    deadline bundle gui-submit .
  2. Pick your input JSONL file. Try sample_prompts.jsonl for the bakery campaign demo.

  3. Set the Prompt Range (for example, 1-10 for the first 10 prompts) and pick an output directory.

  4. Optionally tweak StyleSuffix, Width, and Height. Leave Overlay Caption at true if your JSONL has captions or slogans, or set it to false for pure image generation.

  5. 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
  1. After the job completes, run the download command from the same directory you used at submit time, so the OutputDir path resolves to the same place:

    deadline job download-output --job-id job-id
  2. Every artifact lands under an output/ subdirectory of the path you set as OutputDir. The raw PNGs are in output/images/, the combined metadata is in output/output.jsonl, and output/gallery.html is a static gallery viewer with search and CSV export.

  3. If the gallery's images don't load when you open gallery.html directly, that's a browser security restriction on file:// URLs. Serve the directory instead:

    cd OutputDir/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:

  1. Generate text with the vLLM batch inference bundle: slogans, captions, scene descriptions, or alt-text. The output is output.jsonl with a generated_text field per line. See Run batch LLM inference with vLLM.

  2. (Optional) Open tools/prompt_builder.html, drop in output.jsonl, add or edit per-prompt captions, styles, or visual descriptions, and re-export.

  3. Submit this bundle with the JSONL as InputFile. The per-task script automatically uses generated_text as 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
  1. If you deployed the CUDA farm CloudFormation template, delete the CloudFormation stack from the CloudFormation console.

  2. 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.

  3. Remove local output files if you no longer need them.

The following resources provide additional information: