> For the complete documentation index, see [llms.txt](https://docs.clore.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.clore.ai/guides/guides_v2-de/bildgenerierung/sdxl-turbo.md).

# SDXL Turbo & LCM

Generiere Bilder in 1-4 Schritten mit SDXL Turbo und LCM auf Clore.ai

Erzeuge Bilder in 1-4 Schritten mit SDXL Turbo und Latent Consistency Models auf CLORE.AI GPUs.

{% hint style="success" %}
Alle Beispiele können auf GPU-Servern ausgeführt werden, die gemietet wurden über [CLORE.AI-Marktplatz](https://clore.ai/marketplace).
{% endhint %}

## Warum SDXL Turbo / LCM?

* **Echtzeitgeschwindigkeit** - Erzeuge Bilder in 1-4 Schritten statt 30-50
* **Gleiche Qualität** - Vergleichbar mit dem vollständigen SDXL bei 10x weniger Schritten
* **Interaktiv** - Schnell genug für Echtzeitanwendungen
* **Geringer VRAM** - Effiziente Speichernutzung
* **LoRA-kompatibel** - Mit vorhandenen SDXL-LoRAs verwenden

## Modellvarianten

| Modell          | Schritte | Geschwindigkeit | Qualität     | VRAM  |
| --------------- | -------- | --------------- | ------------ | ----- |
| SDXL Turbo      | 1-4      | Am schnellsten  | Gut          | 8 GB  |
| SDXL Lightning  | 2-8      | Sehr schnell    | Großartig    | 8 GB  |
| LCM-SDXL        | 4-8      | Schnell         | Großartig    | 8 GB  |
| LCM-LoRA + SDXL | 4-8      | Schnell         | Hervorragend | 10 GB |
| SD Turbo (1.5)  | 1-4      | Am schnellsten  | Gut          | 4 GB  |

## Schnellbereitstellung auf CLORE.AI

**Docker-Image:**

```
pytorch/pytorch:2.11.0-cuda12.8-cudnn9-devel
```

**Ports:**

```
22/tcp
7860/http
```

**Befehl:**

```bash
pip install diffusers transformers accelerate gradio && \
python -c "
import gradio as gr
import torch
from diffusers import AutoPipelineForText2Image

pipe = AutoPipelineForText2Image.from_pretrained(
    'stabilityai/sdxl-turbo',
    torch_dtype=torch.float16,
    variant='fp16'
).to('cuda')

def generate(prompt, steps, seed):
    generator = torch.Generator('cuda').manual_seed(seed) if seed > 0 else None
    image = pipe(prompt, num_inference_steps=steps, guidance_scale=0.0, generator=generator).images[0]
    return image

gr.Interface(
    fn=generate,
    inputs=[
        gr.Textbox(label='Prompt'),
        gr.Slider(1, 4, value=1, step=1, label='Schritte'),
        gr.Number(value=-1, label='Seed')
    ],
    outputs=gr.Image(),
    title='SDXL Turbo - Echtzeitgenerierung'
).launch(server_name='0.0.0.0', server_port=7860)
"
```

## Auf deinen Dienst zugreifen

Nach der Bereitstellung findest du deine `http_pub` URL in **Meine Bestellungen**:

1. Gehe zu **Meine Bestellungen** Seite
2. Klicke auf deine Bestellung
3. Finde die `http_pub` URL (z. B. `abc123.clorecloud.net`)

Verwende `https://YOUR_HTTP_PUB_URL` anstelle von `localhost` in den folgenden Beispielen.

## Hardware-Anforderungen

| Modell         | Minimale GPU  | Empfohlen |
| -------------- | ------------- | --------- |
| SD Turbo       | RTX 3060 8GB  | RTX 3070  |
| SDXL Turbo     | RTX 3070 8GB  | RTX 3080  |
| SDXL Lightning | RTX 3070 8GB  | RTX 3090  |
| LCM-SDXL       | RTX 3080 10GB | RTX 4090  |

## Installation

```bash
pip install diffusers transformers accelerate torch
```

## SDXL Turbo

### Grundlegende Verwendung

```python
import torch
from diffusers import AutoPipelineForText2Image

pipe = AutoPipelineForText2Image.from_pretrained(
    "stabilityai/sdxl-turbo",
    torch_dtype=torch.float16,
    variant="fp16"
)
pipe.to("cuda")

# In 1 Schritt generieren!
image = pipe(
    prompt="Eine filmische Aufnahme eines Waschbärenbabys in einem kunstvollen italienischen Priestergewand",
    num_inference_steps=1,
    guidance_scale=0.0  # Turbo verwendet kein CFG
).images[0]

image.save("raccoon.png")
```

### Beste Einstellungen

```python
# 1 Schritt - am schnellsten, gute Qualität
image = pipe(prompt, num_inference_steps=1, guidance_scale=0.0).images[0]

# 2 Schritte - bessere Details
image = pipe(prompt, num_inference_steps=2, guidance_scale=0.0).images[0]

# 4 Schritte - beste Qualität für Turbo
image = pipe(prompt, num_inference_steps=4, guidance_scale=0.0).images[0]
```

## SDXL Lightning

### 2-Schritt-Generierung

```python
import torch
from diffusers import StableDiffusionXLPipeline, EulerDiscreteScheduler
from huggingface_hub import hf_hub_download

base = "stabilityai/stable-diffusion-xl-base-1.0"
repo = "ByteDance/SDXL-Lightning"
ckpt = "sdxl_lightning_2step_unet.safetensors"

# Basismodell laden
pipe = StableDiffusionXLPipeline.from_pretrained(
    base,
    torch_dtype=torch.float16,
    variant="fp16"
).to("cuda")

# Lightning-UNet laden
pipe.unet.load_state_dict(
    torch.load(hf_hub_download(repo, ckpt), map_location="cuda")
)

# Scheduler konfigurieren
pipe.scheduler = EulerDiscreteScheduler.from_config(
    pipe.scheduler.config,
    timestep_spacing="trailing"
)

# In 2 Schritten generieren
image = pipe(
    "Ein Mädchen lächelt in einem Garten",
    num_inference_steps=2,
    guidance_scale=0.0
).images[0]

image.save("lightning.png")
```

### 4-Schritt (höhere Qualität)

```python
ckpt = "sdxl_lightning_4step_unet.safetensors"
# ... gleiche Einrichtung ...

image = pipe(
    prompt,
    num_inference_steps=4,
    guidance_scale=0.0
).images[0]
```

## LCM-LoRA

Mit jedem SDXL-Modell für schnelle Generierung verwenden:

```python
import torch
from diffusers import DiffusionPipeline, LCMScheduler

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

# LCM-LoRA laden
pipe.load_lora_weights("latent-consistency/lcm-lora-sdxl")

# LCM-Scheduler einstellen
pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)

# In 4 Schritten generieren
image = pipe(
    "Astronaut im Dschungel, kalte Farbpalette, gedämpfte Farben, detailliert, 8k",
    num_inference_steps=4,
    guidance_scale=1.0  # LCM verwendet niedrige CFG
).images[0]

image.save("lcm_lora.png")
```

### Mit benutzerdefinierten LoRAs

```python
# Basis + LCM-LoRA + Style-LoRA laden
pipe.load_lora_weights("latent-consistency/lcm-lora-sdxl", adapter_name="lcm")
pipe.load_lora_weights("your-style-lora", adapter_name="style")

# Adapter kombinieren
pipe.set_adapters(["lcm", "style"], adapter_weights=[1.0, 0.8])

image = pipe(prompt, num_inference_steps=4, guidance_scale=1.5).images[0]
```

## SD Turbo (SD 1.5)

Für geringere VRAM-Anforderungen:

```python
import torch
from diffusers import AutoPipelineForText2Image

pipe = AutoPipelineForText2Image.from_pretrained(
    "stabilityai/sd-turbo",
    torch_dtype=torch.float16,
    variant="fp16"
)
pipe.to("cuda")

image = pipe(
    "Ein Foto einer Katze",
    num_inference_steps=1,
    guidance_scale=0.0
).images[0]
```

## Bild-zu-Bild

### SDXL Turbo Img2Img

```python
from diffusers import AutoPipelineForImage2Image
from diffusers.utils import load_image

pipe = AutoPipelineForImage2Image.from_pretrained(
    "stabilityai/sdxl-turbo",
    torch_dtype=torch.float16,
    variant="fp16"
)
pipe.to("cuda")

init_image = load_image("input.jpg").resize((512, 512))

image = pipe(
    prompt="Katzenzauberer, Gandalf, Herr der Ringe, detailliert, Fantasy",
    image=init_image,
    num_inference_steps=2,
    strength=0.5,
    guidance_scale=0.0
).images[0]
```

## Batch-Generierung

```python
import torch
from diffusers import AutoPipelineForText2Image

pipe = AutoPipelineForText2Image.from_pretrained(
    "stabilityai/sdxl-turbo",
    torch_dtype=torch.float16
).to("cuda")

prompts = [
    "Ein Sonnenuntergang über Bergen",
    "Eine futuristische Stadt bei Nacht",
    "Ein süßer Roboter in einem Garten",
    "Ein alter Tempel im Nebel"
]

# Stapelweise generieren
images = pipe(
    prompts,
    num_inference_steps=1,
    guidance_scale=0.0
).images

for i, img in enumerate(images):
    img.save(f"batch_{i}.png")
```

## Echtzeit-Streaming

```python
import gradio as gr
import torch
from diffusers import AutoPipelineForText2Image

pipe = AutoPipelineForText2Image.from_pretrained(
    "stabilityai/sdxl-turbo",
    torch_dtype=torch.float16
).to("cuda")

def generate_realtime(prompt):
    if not prompt:
        return None
    image = pipe(
        prompt,
        num_inference_steps=1,
        guidance_scale=0.0,
        width=512,
        height=512
    ).images[0]
    return image

demo = gr.Interface(
    fn=generate_realtime,
    inputs=gr.Textbox(label="Eingabe"),
    outputs=gr.Image(label="Generiert"),
    live=True,  # Beim Tippen aktualisieren
    title="Echtzeit-SDXL Turbo"
)

demo.launch(server_name="0.0.0.0", server_port=7860)
```

## Leistungsvergleich

| Modell         | Schritte | Auflösung | RTX 3090 | RTX 4090 | A100  |
| -------------- | -------- | --------- | -------- | -------- | ----- |
| SDXL (Basis)   | 30       | 1024x1024 | 8 s      | 5 s      | 4 s   |
| SDXL Turbo     | 1        | 512x512   | 0.3s     | 0.2s     | 0.15s |
| SDXL Turbo     | 4        | 512x512   | 0.8s     | 0.5s     | 0.4s  |
| SDXL Lightning | 2        | 1024x1024 | 0.8s     | 0.5s     | 0.4s  |
| SDXL Lightning | 4        | 1024x1024 | 1.2s     | 0.8s     | 0.6s  |
| LCM-SDXL       | 4        | 1024x1024 | 1.5s     | 1.0s     | 0.7s  |

## Qualitätsvergleich

| Aspekt          | SDXL 30 Schritte | Turbo 4 Schritte | Lightning 4 Schritte |
| --------------- | ---------------- | ---------------- | -------------------- |
| Details         | Hervorragend     | Gut              | Großartig            |
| Textdarstellung | Gut              | Schlecht         | Schlecht             |
| Gesichter       | Großartig        | Gut              | Gut                  |
| Konsistenz      | Hervorragend     | Gut              | Großartig            |
| Stilvielfalt    | Hervorragend     | Gut              | Großartig            |

## Wann was verwenden

| Anwendungsfall                | Empfohlen      | Schritte |
| ----------------------------- | -------------- | -------- |
| Echtzeitvorschau              | SDXL Turbo     | 1        |
| Interaktive Anwendungen       | SDXL Turbo     | 1-2      |
| Schnelle Iterationen          | SDXL Lightning | 2-4      |
| Mit benutzerdefinierten LoRAs | LCM-LoRA       | 4-8      |
| Maximale Qualität             | SDXL Lightning | 8        |
| Geringer VRAM                 | SD Turbo       | 1-2      |

## Kostenschätzung

Übliche CLORE.AI-Marktplatzpreise:

| GPU            | Stundensatz | Bilder/Stunde (1 Schritt) |
| -------------- | ----------- | ------------------------- |
| RTX 3060 12 GB | \~$0.03     | \~3,000                   |
| RTX 3090 24 GB | \~$0.06     | \~8,000                   |
| RTX 4090 24GB  | \~$0.10     | \~12,000                  |
| A100 40GB      | \~$0.17     | \~15,000                  |

*Preise variieren. Prüfe* [*CLORE.AI-Marktplatz*](https://clore.ai/marketplace) *für aktuelle Preise.*

## Fehlerbehebung

### Unscharfe Ergebnisse

* SDXL Turbo gibt nativ 512x512 aus
* Verwende SDXL Lightning für 1024x1024
* Füge einen Upscaling-Post-Processing-Schritt hinzu

### guidance\_scale-Fehler

```python
# SDXL Turbo: immer 0.0 verwenden
image = pipe(prompt, guidance_scale=0.0).images[0]

# LCM: 1.0-2.0 verwenden
image = pipe(prompt, guidance_scale=1.5).images[0]

# Lightning: 0.0 verwenden
image = pipe(prompt, guidance_scale=0.0).images[0]
```

### LoRA funktioniert nicht

```python
# Für LCM-LoRA muss LCMScheduler verwendet werden
from diffusers import LCMScheduler

pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
pipe.load_lora_weights("latent-consistency/lcm-lora-sdxl")
```

### Speicher erschöpft

```python
# Speicheroptimierungen aktivieren
pipe.enable_model_cpu_offload()
pipe.enable_vae_slicing()

# Oder ein kleineres Modell verwenden
# SD Turbo statt SDXL Turbo
```

## Nächste Schritte

* [FLUX.1](/guides/guides_v2-de/bildgenerierung/flux.md) - Generierung höchster Qualität
* [Stable Diffusion WebUI](/guides/guides_v2-de/bildgenerierung/stable-diffusion-webui.md) - Vollständige Benutzeroberfläche
* [ComfyUI](/guides/guides_v2-de/bildgenerierung/comfyui.md) - Node-basierte Workflows
* [Real-ESRGAN](/guides/guides_v2-de/bildverarbeitung/real-esrgan-upscaling.md) - Ergebnisse hochskalieren


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.clore.ai/guides/guides_v2-de/bildgenerierung/sdxl-turbo.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
