Skip to main content

Stable Diffusion on a Rented GPU: Setup and Cost

A hands-on guide to running image generation in the cloud, with a simple way to work out what it will actually cost.

Updated 6 min readMarkdown
Part of seriesCloud Infrastructure
Stable Diffusion on a Rented GPU: Setup and Cost

Running Stable Diffusion on your own laptop works until it doesn't. A mid-range machine can take a minute or more per image, and higher resolutions or newer models can run out of memory entirely. Renting a GPU in the cloud solves that: you pay only while it runs, and you can pick hardware that fits the job.

This guide covers what to rent, how to set it up, and how to estimate the bill before you start.

What you actually need to run Stable Diffusion

The one spec that matters most is VRAM, the memory on the GPU. Rough guidance:

Model family Comfortable VRAM Notes Stable Diffusion 1.5 6-8 GB Light and fast, great for learning SDXL 12-16 GB Better quality at 1024x1024 Newer, larger models 24 GB or more Check the model card for its exact requirement

Beyond VRAM, you need modest CPU and RAM (8 GB of system RAM is a workable floor) and enough disk for model files. A single checkpoint is often 2-7 GB, and you will accumulate several, so plan for 50 GB or more of storage.

Treat these numbers as starting points and always confirm the requirement on the model's own page.

Step 1: Choose the right instance

Match the GPU to the work:

Experimenting or learning: a smaller GPU with 12-16 GB VRAM is usually enough and cheapest. Batch generation or SDXL at high resolution: step up to 24 GB. Fine-tuning or training LoRAs: you want more VRAM and faster storage, since training is far heavier than generating.

Also look at billing granularity. Per-second or per-minute billing suits bursty image work much better than hourly rounding. Antryk, for example, lists per-second billing and spot and reserved options on its platform, and you can review GPU offerings on its GPU application service pricing page.

Step 2: Prepare the environment

Whatever provider you use, the process is similar. Launch a GPU instance with a recent Ubuntu image, then confirm the GPU is visible:

bash nvidia-smi

You should see your GPU model and its VRAM. If you don't, the instance image is missing drivers, so pick an image with CUDA preinstalled or a prebuilt ML image.

Next, create an isolated Python environment:

bash sudo apt update && sudo apt install -y python3-venv git python3 -m venv sd-env source sd-env/bin/activate pip install --upgrade pip Step 3: Install the libraries

The simplest route is Hugging Face's diffusers library:

bash pip install torch torchvision --index-url https://download.pytorch.org/whl/cu121 pip install diffusers transformers accelerate safetensors

Match the CUDA build in the PyTorch URL to what your instance provides. Check PyTorch's install page if nvidia-smi shows a different CUDA version.

Step 4: Generate your first image

Create a file called generate.py:

python import torch from diffusers import StableDiffusionXLPipeline

pipe = StableDiffusionXLPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True, ).to("cuda")

prompt = "a lighthouse on a cliff at sunrise, soft light, detailed, photorealistic" image = pipe(prompt, num_inference_steps=30, guidance_scale=7.0).images[0] image.save("lighthouse.png") print("saved lighthouse.png")

Run it:

bash python generate.py

The first run downloads the model weights, which takes a few minutes. After that, generation should take seconds per image on a capable GPU. Check the licence terms on any model before using its output commercially.

Step 5: Make it faster and cheaper to run

A few habits pay for themselves quickly:

Use half precision (float16). It roughly halves memory use and speeds up inference with little visible quality loss. Keep the pipeline loaded. Loading a model is the slowest part. Load it once and generate many images in one session instead of restarting a script each time. Batch your prompts. Generating several images per call uses the GPU more fully than one at a time. Reduce steps where you can. Going from 50 to 25-30 steps often has a small effect on quality and a large one on time. Enable memory savers if VRAM is tight. Calling pipe.enable_attention_slicing() can let a smaller GPU handle larger images, at some cost in speed. Step 6: Expose it as a simple API (optional)

If other people or apps need to use your setup, wrap the pipeline in a small web service rather than sharing SSH access. A minimal FastAPI app that loads the pipeline once and exposes a /generate endpoint is enough for most projects. Platforms with git-based deployment can run it for you, and Antryk's documentation covers deploying Python and FastAPI services.

How much does it actually cost?

Prices vary by provider, GPU model, region and billing type, and they change often, so any figure printed in a blog goes stale. Instead of memorising a number, use a formula you can rerun with current prices:

Monthly cost = (hourly rate x hours of use) + storage + data transfer

Here is a worked example with placeholder numbers. Replace the rate with the live price from your provider.

Item Assumption Calculation GPU rate R per hour (from the pricing page) Usage 3 hours a day, 20 days a month 60 hours GPU cost 60 x R Storage 100 GB persistent disk provider's per-GB rate x 100 Transfer Mostly small image downloads usually minor

A few things that change the bill more than people expect:

Idle time is the biggest leak. A GPU left running overnight bills the same as one generating images. Stop or delete instances when you finish. Per-second billing rewards short sessions. If you only work in bursts, it can be far cheaper than hourly rounding. Spot or interruptible instances can cost much less than on-demand, but they can be reclaimed, so save outputs to persistent storage as you go. Storage keeps billing when the GPU is off. Delete model files and images you no longer need. Compare against buying. If you generate images all day every day, owning a GPU may eventually win. For occasional or bursty use, renting almost always does.

To compare real numbers, check current rates on the Antryk pricing page alongside other providers, and calculate the same 60-hour scenario for each.

A quick cost-control checklist [ ] Pick the smallest GPU that fits your model's VRAM [ ] Choose per-second or per-minute billing where available [ ] Set a budget alert before you start [ ] Save outputs to persistent storage, not only the instance disk [ ] Stop the instance the moment you're done [ ] Review the bill after your first week and adjust Wrapping up

Running Stable Diffusion on a rented GPU is straightforward: choose a GPU with enough VRAM, install PyTorch and diffusers, load the model once, and generate in batches. The part that catches beginners out is cost, and nearly all of it comes down to idle time and billing granularity. Estimate with the formula above, set a budget alert, and shut things down when you're finished.

If you want to try it on a platform built for GPU workloads, you can start on Antryk and follow our docs to launch your first instance.

Disclosure: I work with the team at Antryk.

About the author

  • Antryk is a cloud infrastructure platform offering scalable, affordable, and developer-friendly solutions for web hosting, GPU computing, managed databases, and application deployment.

No comments yet. Be the first to comment.