> ## Documentation Index
> Fetch the complete documentation index at: https://runcrate.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Train a Stable Diffusion LoRA on Cloud GPU

> Fine-tune SDXL with LoRA on a cloud GPU using diffusers. Upload training images, train, and download weights.

export const RuncrateStyles = () => {
  if (typeof document !== 'undefined' && !document.getElementById('runcrate-overrides')) {
    const s = document.createElement('style');
    s.id = 'runcrate-overrides';
    s.textContent = `
      /* Match Runcrate's rounding scale (--radius: 0.75rem) */
      .rounded-sm { border-radius: 0.5rem !important; }   /* 8px */
      .rounded-md { border-radius: 0.625rem !important; } /* 10px */
      .rounded-lg { border-radius: 0.75rem !important; }  /* 12px */
      .rounded-l-sm { border-top-left-radius: 0.5rem !important; border-bottom-left-radius: 0.5rem !important; }
      .rounded-r-sm { border-top-right-radius: 0.5rem !important; border-bottom-right-radius: 0.5rem !important; }
      .rounded-l-md { border-top-left-radius: 0.625rem !important; border-bottom-left-radius: 0.625rem !important; }
      .rounded-r-md { border-top-right-radius: 0.625rem !important; border-bottom-right-radius: 0.625rem !important; }
      .rounded-l-lg { border-top-left-radius: 0.75rem !important; border-bottom-left-radius: 0.75rem !important; }
      .rounded-r-lg { border-top-right-radius: 0.75rem !important; border-bottom-right-radius: 0.75rem !important; }

      /* Cards: never pure white in light mode */
      .card { background-color: #fcfcfc !important; border-radius: 0.75rem !important; }
      html.dark .card { background-color: #141414 !important; }

      /* Docs hero box */
      .rc-hero { background-color: #fcfcfc; border: 1px solid #e0e0e0; }
      html.dark .rc-hero { background-color: #141414; border-color: #242424; }
      html.dark .rc-hero h1 { color: #f5f5f5; }

      /* Runcrate scrollbar — thin, transparent track, hide-until-hover thumb */
      ::-webkit-scrollbar { width: 6px; height: 6px; background-color: transparent; }
      ::-webkit-scrollbar-track { background-color: transparent; }
      ::-webkit-scrollbar-thumb { background-color: rgba(155, 155, 155, 0.5); border-radius: 10px; transition: opacity 0.3s ease; opacity: 0; }
      ::-webkit-scrollbar-thumb:hover { background-color: rgba(155, 155, 155, 0.7); }
      *:hover::-webkit-scrollbar-thumb,
      *:focus::-webkit-scrollbar-thumb,
      *:active::-webkit-scrollbar-thumb { opacity: 1; }
      * { scrollbar-width: thin; scrollbar-color: rgba(155, 155, 155, 0.5) transparent; }
    `;
    document.head.appendChild(s);
  }
  return null;
};

<RuncrateStyles />

Train a LoRA adapter for SDXL on a cloud GPU. LoRA lets you teach SDXL new styles, characters, or concepts with 10-30 training images in under an hour on an RTX 4090.

## GPU requirements

| Task             | GPU        | Training time (20 images, 1500 steps) |
| ---------------- | ---------- | ------------------------------------- |
| SDXL LoRA (FP16) | RTX 4090   | \~30 min                              |
| SDXL LoRA (FP16) | A100 80 GB | \~15 min                              |

***

## 1. Deploy and upload images

```bash theme={"theme":"github-dark"}
runcrate instances create --name lora-train --gpu RTX4090 --template ubuntu-train
runcrate instances status lora-train

runcrate cp ./training_images/ lora-train:/workspace/training_images/
```

## 2. Install dependencies

```bash theme={"theme":"github-dark"}
runcrate ssh lora-train -- "pip install diffusers transformers accelerate peft safetensors pillow"
```

## 3. Run training

```bash theme={"theme":"github-dark"}
runcrate ssh lora-train -- "accelerate launch diffusers/examples/dreambooth/train_dreambooth_lora_sdxl.py \
  --pretrained_model_name_or_path='stabilityai/stable-diffusion-xl-base-1.0' \
  --instance_data_dir='/workspace/training_images' \
  --instance_prompt='a photo of sks person' \
  --output_dir='/workspace/lora-output' \
  --resolution=1024 \
  --train_batch_size=1 \
  --gradient_accumulation_steps=4 \
  --learning_rate=1e-4 \
  --max_train_steps=1500 \
  --mixed_precision='fp16' \
  --seed=42"
```

## 4. Monitor

```bash theme={"theme":"github-dark"}
runcrate ssh lora-train -- nvidia-smi
runcrate ssh lora-train -- "ls -la /workspace/lora-output/"
```

## 5. Test the LoRA

```bash theme={"theme":"github-dark"}
runcrate ssh lora-train -- "python -c \"
from diffusers import DiffusionPipeline
import torch
pipe = DiffusionPipeline.from_pretrained(
    'stabilityai/stable-diffusion-xl-base-1.0', torch_dtype=torch.float16).to('cuda')
pipe.load_lora_weights('/workspace/lora-output')
image = pipe('a photo of sks person in a garden', num_inference_steps=30).images[0]
image.save('/workspace/test_output.png')
print('Generated test image.')
\""
```

## 6. Download weights

```bash theme={"theme":"github-dark"}
runcrate cp lora-train:/workspace/lora-output/ ./my-sdxl-lora/
runcrate cp lora-train:/workspace/test_output.png ./test_output.png
```

## Tips

* Use high-quality, consistent images — same subject, varied backgrounds and angles.
* The `sks` token is a rare identifier used as the trigger word. Replace with any uncommon string.
* Lower learning rates (5e-5) = subtle adaptations. Higher rates (2e-4) = stronger style shifts.
* Add `--checkpointing_steps=500` to resume interrupted runs.

## Cleanup

```bash theme={"theme":"github-dark"}
runcrate instances delete lora-train
```
