Stable Diffusion 3.5: Generation & Upscaling

NF4-quantised SD 3.5 Large on consumer GPUs: 512² generation pushed to crisp 2048² with the X4 upscaler.

ML / DL2025All work

Fig. 01Stable Diffusion 3.5 title graphic
NF4-quantised SD 3.5 Large on consumer GPUs: 512² generation pushed to crisp 2048² with the X4 upscaler.

What it is

What it does

A practical recipe for running SD 3.5 Large where it nominally doesn't fit: the transformer loads in 4-bit NF4 through bitsandbytes, the heavy T5 encoder uses a pre-quantised NF4 checkpoint, components split across two GPUs with CPU offload bridging the rest, then the SD X4 upscaler takes 512×512 output to 2048×2048.

Why it exists

SD 3.5 Large didn't fit on my card, and naive CPU offloading made it crawl. I kept the parts that affect prompt fidelity at full precision and quantised only the heavy transformer and T5. It fits now, and still looks right.

2048²
Output
NF4
4-bit weights
2
GPUs + offload

Repo Amit-kr26/Stable-Diffusion-3-Image-Generation-and-UpscalingStack Stable Diffusion 3.5 · T5 Encoder · diffusers · bitsandbytes · PyTorch

Build5decisions

How it is built

Selective NF4 quantisation

SD3Transformer2DModel loads via BitsAndBytesConfig(load_in_4bit, nf4, fp16 compute); the third text encoder swaps for diffusers' pre-quantised t5-nf4 checkpoint.

Multi-GPU placement

Transformer pins to cuda:0, T5 to cuda:1, with enable_model_cpu_offload() chaining the remaining components through available memory.

Allocator tuning

PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True fights fragmentation during long generation sessions.

Two-stage resolution

Generation runs 512×512 at 50 steps / guidance 7.5; StableDiffusionUpscalePipeline (fp16, safetensors) finishes at 2048×2048 in 30 steps.

Artifact pipeline

Each run saves the raw 512² generation and the 2048² upscaled result as separate PNGs, wrapped in an interactive prompt loop for iterating on photorealistic prompts.

How the pieces connect

Generate Upscale Text prompt CLIP stays fp16 Text encoders CLIP fp16, T5 NF4 SD 3.5 transformer NF4 MMDiT, cuda:0 CPU offload one GPU at a time 512 × 512 50 steps, cfg 7.5 Upscaler CLIP re-encodes the prompt X4 upscaler UNet fp16, 30 steps 2048 × 2048 4 × 512 Two PNGs raw + upscaled Matplotlib preview the 2048² result 8.15B parameters in 4 bits