Run one copy of the model per GPU and split the prompts between them: four GPUs make roughly four times as many images per hour at the same cost per image. Use accelerate or one process per GPU for diffusers, or one ComfyUI instance per GPU. Splitting one image across GPUs (xDiT) only cuts latency.
- Best method for throughput
- Data parallel: one model copy per GPU
- Scaling (data parallel)
- Close to linear; cost per image unchanged
- diffusers launcher
- accelerate launch --num_processes=N
- ComfyUI per GPU
- python main.py --cuda-device N --port 8188+N
- Fit a model across GPUs
- device_map="balanced" in diffusers
- Cut latency of one image
- xDiT (sequence and patch parallelism)
- Our machines
- 1, 2, 4 or 8 of the same GPU
There are two reasons to put more than one GPU on image generation: to make more images per hour, or to make one image arrive sooner. They need different techniques, and mixing them up is the most common mistake. For bulk work, the answer is almost always the simple one: a full copy of the model on each GPU, each working through its own share of the prompts. This guide shows that approach for diffusers and ComfyUI, then the more specialised options for splitting one model or one image across cards.
The single-GPU setup these build on is in how to run Stable Diffusion on a cloud GPU.
What are the ways to use multiple GPUs for image generation?
There are three: replicate the model (data parallelism), split the model (to fit it), or split the image (to cut latency). Pick by your goal.
| Goal | Technique | Speed-up | Difficulty | Needs fast GPU links? |
|---|---|---|---|---|
| More images per hour | One model copy per GPU (data parallel) | Close to N× throughput | Easy | No |
| Fit a model too big for one card | Split components across GPUs (device_map) | None; may be slightly slower | Easy | Helps, not required |
| One image sooner | Split the image's work (xDiT sequence or patch parallelism) | Lower latency, sub-linear | Hard | Yes, ideally |
If the GPUs are in one machine, all three work. What multi-GPU computing is explains the underlying ideas; this article sticks to image models.
Method 1: One worker per GPU with a shard of the prompts
The simplest reliable method is to start one Python process per GPU, pin each to a GPU with CUDA_VISIBLE_DEVICES, and give each process every Nth prompt. No framework is needed.
# gen_shard.py
import sys, pathlib, torch
from diffusers import StableDiffusionXLPipeline
shard, n_shards = int(sys.argv[1]), int(sys.argv[2])
prompts = [p.strip() for p in open("prompts.txt") if p.strip()]
mine = list(enumerate(prompts))[shard::n_shards] # every Nth (index, prompt)
pipe = StableDiffusionXLPipeline.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0",
torch_dtype=torch.float16, variant="fp16").to("cuda") # "cuda" = the one visible GPU
out = pathlib.Path("out"); out.mkdir(exist_ok=True)
BATCH = 4
for i in range(0, len(mine), BATCH):
chunk = mine[i:i + BATCH]
images = pipe([p for _, p in chunk], num_inference_steps=30).images
for (idx, _), img in zip(chunk, images):
img.save(out / f"{idx:05d}.png") # keep the original numberingLaunch one per GPU:
N=$(nvidia-smi -L | wc -l)
for i in $(seq 0 $((N-1))); do
CUDA_VISIBLE_DEVICES=$i python gen_shard.py $i $N > log_$i.txt 2>&1 &
done
waitEach process sees exactly one GPU as cuda:0, so the model code is unchanged from the single-GPU version. Watch all cards with nvidia-smi -l 2; each should sit near 100% utilisation.
Use a shared queue when jobs vary in length
Static shards are fine when every prompt takes the same time. When they do not (mixed resolutions, mixed models), let each GPU pull the next job from a shared queue so no card finishes early and sits idle:
# gen_queue.py
import torch, torch.multiprocessing as mp
def worker(gpu, q):
from diffusers import StableDiffusionXLPipeline
pipe = StableDiffusionXLPipeline.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0",
torch_dtype=torch.float16, variant="fp16").to(f"cuda:{gpu}")
while (job := q.get()) is not None:
idx, prompt = job
pipe(prompt, num_inference_steps=30).images[0].save(f"out/{idx:05d}.png")
if __name__ == "__main__":
mp.set_start_method("spawn")
prompts = [p.strip() for p in open("prompts.txt") if p.strip()]
n = torch.cuda.device_count()
q = mp.Queue()
for job in enumerate(prompts):
q.put(job)
for _ in range(n):
q.put(None) # one stop signal per worker
procs = [mp.Process(target=worker, args=(g, q)) for g in range(n)]
for p in procs: p.start()
for p in procs: p.join()The spawn start method matters: CUDA cannot be initialised safely in processes created with the default fork on Linux. Each worker loads its own copy of the model onto its own GPU, then loops until it receives the stop signal. The same pull-based pattern, with Redis or a database in place of the in-memory queue, is what production image services use.
Method 2: accelerate's distributed inference
Hugging Face accelerate does the process launching and prompt splitting for you. It is the approach shown in the diffusers distributed inference guide.
# gen_accel.py
import torch
from accelerate import PartialState
from diffusers import FluxPipeline
state = PartialState()
pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell",
torch_dtype=torch.bfloat16)
pipe.to(state.device)
prompts = [p.strip() for p in open("prompts.txt") if p.strip()]
with state.split_between_processes(prompts) as my_prompts:
for k, prompt in enumerate(my_prompts):
img = pipe(prompt, guidance_scale=0.0, num_inference_steps=4,
max_sequence_length=256).images[0]
img.save(f"out/rank{state.process_index}_{k:05d}.png")pip install -U accelerate
mkdir -p out
accelerate launch --num_processes=4 gen_accel.pyThis example puts FLUX.1 [schnell] in full BF16 on each GPU, so each card needs about 34 GB plus headroom: use L40S or larger. On 24 GB cards, use SDXL, or FP8 or 4-bit FLUX as in how to run FLUX on a cloud GPU.
Method 3: One ComfyUI instance per GPU
ComfyUI uses one GPU per instance, so you start one per card on different ports and spread jobs across them.
cd ~/ComfyUI
for i in 0 1 2 3; do
tmux new -d -s comfy$i "python main.py --listen 127.0.0.1 --cuda-device $i --port $((8188+i))"
doneAll four share the same models/ folder, so you download models once. For interactive use, tunnel the port you want (ssh -N -L 8188:127.0.0.1:8188 -L 8189:127.0.0.1:8189 -p PORT USER@HOST). For batch work, send API-format workflows to each instance in turn:
import itertools, json, requests
ports = itertools.cycle([8188, 8189, 8190, 8191])
wf = json.load(open("workflow_api.json"))
prompts = [p.strip() for p in open("prompts.txt") if p.strip()]
for i, text in enumerate(prompts):
wf["6"]["inputs"]["text"] = text # your prompt node's id
wf["3"]["inputs"]["seed"] = i
port = next(ports)
requests.post(f"http://127.0.0.1:{port}/prompt", json={"prompt": wf}).raise_for_status()Each instance queues what it receives and works through it. Round-robin is fine when all jobs take the same time; for mixed jobs, check each instance's /queue endpoint and send to the shortest. Full ComfyUI set-up is in how to run ComfyUI on a cloud GPU.
Method 4: Split one pipeline across GPUs to fit it
If a model does not fit on one card, diffusers can place its components on different GPUs. This is about memory, not speed.
import torch
from diffusers import FluxPipeline
pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev",
torch_dtype=torch.bfloat16,
device_map="balanced")
print(pipe.hf_device_map) # e.g. text encoders on GPU 0, transformer on GPU 1
image = pipe("a brass telescope on a windowsill at night",
guidance_scale=3.5, num_inference_steps=28).images[0]On two 24 GB RTX 4090s this runs FLUX.1 [dev] in full BF16 (about 34 GB of weights) without quantising. Only one GPU works at any moment, so it is no faster than one large card; an L40S with 48 GB does the same job on one card. Use it when two smaller cards are what you have.
Method 5: Split one image across GPUs to cut latency
To make a single image arrive sooner, the work inside each denoising step has to be split across GPUs. xDiT is an open-source engine for exactly this: it implements sequence parallelism (splitting the image's tokens between GPUs), PipeFusion (patch-level pipelining) and related methods for diffusion transformers including FLUX.1, SD 3 and several video models. See the xDiT repository for supported models and launch commands.
Expect sub-linear gains: GPUs exchange activations every step, so two GPUs do not halve the time, and the benefit grows with resolution (more tokens to split) and with fast links between cards. Use it for latency-critical services or very high resolutions, not for bulk throughput, where Methods 1–3 are simpler and more efficient.
Video models are the exception where splitting one job is normal, because one clip can take many minutes. Wan 2.1's own scripts, for example, run a single generation across 8 GPUs with torchrun; how to run open-source AI video models in the cloud shows the commands.
How much faster, and what does it cost?
With data parallelism, N GPUs give about N times the images per hour and the same cost per image. You pay to finish sooner, not to pay less.
Worked example: 10,000 SDXL images at 30 steps on RTX 4090s, at our estimated 4.5 seconds per image per GPU (an estimate scaled from published community figures, not our measurement). GPU-hours = 10,000 × 4.5 ÷ 3,600 = 12.5.
| GPUs | Images per hour (est.) | Wall-clock time | Total GPU-hours | Our cost |
|---|---|---|---|---|
| 1 × RTX 4090 | ~800 | ~12.5 h | 12.5 | 12.5 × $1.59/hr ≈ $19.88 |
| 2 × RTX 4090 | ~1,600 | ~6.3 h | 12.5 | 12.5 × $1.59/hr ≈ $19.88 |
| 4 × RTX 4090 | ~3,200 | ~3.1 h | 12.5 | 12.5 × $1.59/hr ≈ $19.88 |
| 8 × RTX 4090 | ~6,400 | ~1.6 h | 12.5 | 12.5 × $1.59/hr ≈ $19.88 |
Add a few minutes per run for model loading, which every GPU does in parallel. The same sum for FLUX.1 [dev] on H100 PCIe (estimated 9 s per image) is 25 GPU-hours: about 25 hours on one card or about 3.1 hours on eight, at 25 × $4.99/hr ≈ $124.75 either way. More budgets at this scale are in what it costs to generate 10,000 AI images.
What stops multi-GPU generation scaling?
When eight GPUs give you five times the speed, the bottleneck is usually outside the GPUs.
- Model loading. Each process reads the weights from disk into its own GPU. Eight processes loading 24 GB at once stresses disk and RAM; stagger start-up by a few seconds if loads time out.
- System RAM. Each process may hold a copy of the weights in CPU memory while loading. Eight FLUX processes can need well over 100 GB of RAM at peak.
- CPU-side work. Saving PNGs, prompt tokenisation and image post-processing run on the CPU. With fast models such as FLUX.1 [schnell], PNG encoding can become the limit; save as JPEG or WebP, or hand saving to a thread pool.
- Uneven shards. If some prompts are much slower (higher resolution, more steps), static shards finish at different times. A shared queue that each worker pulls from fixes this.
- Output storage. At 6,400 images an hour, at a few megabytes each, you write tens of gigabytes per hour. Check free disk first.
For running this permanently as a service, with a queue that workers pull from, read how to build a scalable AI image and video generation platform.
Should you use several small GPUs or one big one?
For bulk image throughput, several cheaper GPUs usually beat one expensive one on price per image. For big models and low latency, one large GPU is simpler.
| Choose | When |
|---|---|
| Several RTX 4090s | SDXL or FP8 FLUX at volume; best price per image in most cases |
| Several L40S | BF16 FLUX or SD 3.5 Large at volume |
| One H100 or RTX PRO 6000 | Low latency per image, big models, many models resident |
| 8 × large GPUs | Video generation, where one clip is split across cards |
Our multi-GPU cloud servers guide compares providers that offer multi-GPU machines.
When does renting from Wandering Giants Compute fit?
Renting from us fits batch image work that needs more than one card for a few hours. You can launch 1, 2, 4 or 8 of the same GPU in one machine, from RTX 4090s to H100s and RTX PRO 6000s, with root access, Ubuntu, CUDA and PyTorch ready. Run the shard script, let it finish, stop the machine, and you have paid by the minute for the GPU time you used. Prepaid credit means a runaway job stops when the credit does.
We do not offer multi-node clusters, InfiniBand or autoscaling serverless workers; if you need dozens of GPUs across machines or scale-to-zero endpoints, other providers specialise in that. For up to eight GPUs in one box, see the multi-GPU options and prices.
Frequently asked questions
Can Stable Diffusion use multiple GPUs?
Yes, most simply by running one copy of the model on each GPU and giving each a share of the prompts. That multiplies throughput almost linearly. Splitting a single image across GPUs is possible with tools such as xDiT but is more complex and mainly reduces latency.
Does ComfyUI support multiple GPUs?
A single ComfyUI instance uses one GPU. The standard approach is to start one instance per GPU with --cuda-device and a different --port for each, then send jobs to them in turn through their APIs or a load balancer. Some custom nodes add multi-GPU features within one graph.
Is it cheaper to use more GPUs?
Not per image. With data parallelism, four GPUs finish four times sooner but use the same total GPU-hours, so the bill is about the same. You pay for more GPUs to finish faster, not to pay less.
Do I need NVLink to generate images on multiple GPUs?
No. Data-parallel image generation sends almost nothing between GPUs, so PCIe is fine. NVLink matters for splitting one model or one image across GPUs, where layers or activations move between cards every step.
Can I split FLUX across two 24 GB GPUs?
Yes. diffusers can place pipeline components on different GPUs with device_map="balanced", for example the T5 encoder on one card and the transformer on the other, so BF16 FLUX fits without quantising. It does not make a single image faster.
How many images per hour can 8 GPUs make?
Multiply single-GPU throughput by eight. At an estimated 4.5 seconds per SDXL image on an RTX 4090, one card makes about 800 images an hour, so eight make about 6,400, provided your CPU, disk and data pipeline keep up.
Rent the GPU for this, by the minute.
Launch 2, 4 or 8 of the same GPU in one machine, run a worker on each, and finish a 10,000-image batch in a fraction of the time for about the same cost.
Prepaid credit, billed by the minute, stops itself when credit runs out. Prices in £, $, €, ¥, CA$, A$, CHF and S$; UK prices include VAT.
Keep reading
- Complete guideHow to Run Stable Diffusion on a Cloud GPU
- GuideWhat Is Multi-GPU Computing and When Do You Need It?
- ComparisonBest Cloud Providers for Multi-GPU Servers
- GuideHow to Build a Scalable AI Image and Video Generation Platform
- Cost breakdownHow Much Does It Cost to Generate 10,000 AI Images?
- TutorialHow to Run FLUX Locally or on Cloud GPU Infrastructure
About this article. Written by the Wandering Giants Compute team, the people who run Wandering Giants Compute. Hardware figures are the manufacturers’ published specifications. Speeds and costs marked as estimates are worked out from those specifications and our current prices, with the method shown; they are not measured benchmarks. Wandering Giants prices are taken live from our price list each time this page is built.
Last reviewed 25 November 2026.