> 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/andere-workloads/kandinsky.md).

# Kandinsky

Erstelle Bilder mit Kandinskys mehrsprachigem Modell auf Clore.ai

Bilder mit leistungsstarkem mehrsprachigem Textverständnis generieren.

{% 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 %}

## Was ist Kandinsky?

Kandinsky ist ein von Sber AI entwickeltes Bildgenerierungsmodell:

* Starkes mehrsprachiges Textverständnis
* Hochwertige Bildgenerierung
* Bildmischung und Interpolation
* Unterstützung für Inpainting und Outpainting
* Open-Source-Gewichte

## Ressourcen

* **GitHub:** [ai-forever/Kandinsky-3](https://github.com/ai-forever/Kandinsky-3)
* **HuggingFace:** [kandinsky-community](https://huggingface.co/kandinsky-community)
* **Paper:** [Kandinsky-Paper](https://arxiv.org/abs/2310.03502)

## Modellversionen

| Version       | Auflösung | Qualität  | Geschwindigkeit |
| ------------- | --------- | --------- | --------------- |
| Kandinsky 2.1 | 768x768   | Gut       | Schnell         |
| Kandinsky 2.2 | 1024x1024 | Besser    | Mittel          |
| Kandinsky 3   | 1024x1024 | Am besten | Langsamer       |

## Hardware-Anforderungen

| Modell                       | VRAM  | Empfohlene GPU |
| ---------------------------- | ----- | -------------- |
| Kandinsky 2.2                | 8 GB  | RTX 3070       |
| Kandinsky 3                  | 12 GB | RTX 3090       |
| Kandinsky 3 (hohe Auflösung) | 16 GB | RTX 4090       |

## Schnell bereitstellen

**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(
    'kandinsky-community/kandinsky-3',
    variant='fp16',
    torch_dtype=torch.float16
).to('cuda')

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

gr.Interface(
    fn=generate,
    inputs=[
        gr.Textbox(label='Prompt'),
        gr.Textbox(label='Negativ-Prompt', value='niedrige Qualität, verschwommen'),
        gr.Slider(10, 100, value=50, label='Schritte'),
        gr.Slider(1, 20, value=4, label='Guidance-Skala'),
        gr.Number(value=-1, label='Seed')
    ],
    outputs=gr.Image(),
    title='Kandinsky 3'
).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.

## Installation

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

## Grundlegende Verwendung

### Kandinsky 3

```python
import torch
from diffusers import AutoPipelineForText2Image

pipe = AutoPipelineForText2Image.from_pretrained(
    "kandinsky-community/kandinsky-3",
    variant="fp16",
    torch_dtype=torch.float16
)
pipe.to("cuda")

image = pipe(
    prompt="Ein Katzenastronaut schwebt im Weltraum, digitale Kunst, lebendige Farben",
    num_inference_steps=50,
    guidance_scale=4.0
).images[0]

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

### Kandinsky 2.2

```python
import torch
from diffusers import KandinskyV22Pipeline, KandinskyV22PriorPipeline

# Prior laden (Text-Encoder)
prior = KandinskyV22PriorPipeline.from_pretrained(
    "kandinsky-community/kandinsky-2-2-prior",
    torch_dtype=torch.float16
).to("cuda")

# Decoder laden
decoder = KandinskyV22Pipeline.from_pretrained(
    "kandinsky-community/kandinsky-2-2-decoder",
    torch_dtype=torch.float16
).to("cuda")

# Bild-Embeddings generieren
prompt = "Ein wunderschöner Sonnenuntergang über Bergen, im Stil eines Ölgemäldes"
image_embeds, negative_embeds = prior(
    prompt=prompt,
    guidance_scale=1.0
).to_tuple()

# Bild generieren
image = decoder(
    image_embeds=image_embeds,
    negative_image_embeds=negative_embeds,
    height=768,
    width=768,
    num_inference_steps=50
).images[0]

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

## Mehrsprachige Prompts

Kandinsky unterstützt mehrere Sprachen:

```python
import torch
from diffusers import AutoPipelineForText2Image

pipe = AutoPipelineForText2Image.from_pretrained(
    "kandinsky-community/kandinsky-3",
    variant="fp16",
    torch_dtype=torch.float16
).to("cuda")

# Englisch
image_en = pipe("Ein roter Fuchs in einem verschneiten Wald").images[0]

# Russisch
image_ru = pipe("Ein roter Fuchs in einem verschneiten Wald").images[0]

# Chinesisch
image_zh = pipe("Ein roter Fuchs in einem verschneiten Wald").images[0]

# Deutsch
image_de = pipe("Ein roter Fuchs im verschneiten Wald").images[0]

# Alle erzeugen ähnliche Bilder!
```

## Bildmischung

```python
import torch
from diffusers import KandinskyV22PriorPipeline, KandinskyV22Pipeline
from diffusers.utils import load_image

prior = KandinskyV22PriorPipeline.from_pretrained(
    "kandinsky-community/kandinsky-2-2-prior",
    torch_dtype=torch.float16
).to("cuda")

decoder = KandinskyV22Pipeline.from_pretrained(
    "kandinsky-community/kandinsky-2-2-decoder",
    torch_dtype=torch.float16
).to("cuda")

# Zwei Prompts zum Mischen
prompt1 = "Eine Katze"
prompt2 = "Ein Hund"

# Embeddings für beide abrufen
embeds1, neg1 = prior(prompt1).to_tuple()
embeds2, neg2 = prior(prompt2).to_tuple()

# Embeddings mischen (je 50 %)
mixed_embeds = 0.5 * embeds1 + 0.5 * embeds2
mixed_neg = 0.5 * neg1 + 0.5 * neg2

# Gemischtes Bild generieren
image = decoder(
    image_embeds=mixed_embeds,
    negative_image_embeds=mixed_neg,
    height=768,
    width=768
).images[0]

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

## Bereichsfüllung

```python
import torch
from diffusers import AutoPipelineForInpainting
from diffusers.utils import load_image

pipe = AutoPipelineForInpainting.from_pretrained(
    "kandinsky-community/kandinsky-2-2-decoder-inpaint",
    torch_dtype=torch.float16
).to("cuda")

# Bild und Maske laden
image = load_image("photo.png")
mask = load_image("mask.png")

# Inpainten
result = pipe(
    prompt="Eine goldene Krone",
    image=image,
    mask_image=mask,
    num_inference_steps=50
).images[0]

result.save("inpainted.png")
```

## Bild-zu-Bild

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

pipe = AutoPipelineForImage2Image.from_pretrained(
    "kandinsky-community/kandinsky-3",
    variant="fp16",
    torch_dtype=torch.float16
).to("cuda")

init_image = load_image("sketch.png")

image = pipe(
    prompt="Ein detailliertes digitales Gemälde einer Burg, Fantasy-Kunst",
    image=init_image,
    strength=0.75,
    num_inference_steps=50
).images[0]

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

## Batch-Generierung

```python
import torch
from diffusers import AutoPipelineForText2Image
import os

pipe = AutoPipelineForText2Image.from_pretrained(
    "kandinsky-community/kandinsky-3",
    variant="fp16",
    torch_dtype=torch.float16
).to("cuda")

prompts = [
    "Ein ruhiger japanischer Garten mit Kirschblüten",
    "Eine Cyberpunk-Stadt bei Nacht mit Neonlichtern",
    "Eine antike Bibliothek voller magischer Bücher",
    "Eine gemütliche Hütte in den Bergen im Winter"
]

os.makedirs("outputs", exist_ok=True)

for i, prompt in enumerate(prompts):
    image = pipe(
        prompt=prompt,
        num_inference_steps=50,
        guidance_scale=4.0
    ).images[0]

    image.save(f"outputs/image_{i}.png")
    print(f"Generiert: {prompt[:30]}...")

    torch.cuda.empty_cache()
```

## Gradio-Oberfläche

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

pipe = AutoPipelineForText2Image.from_pretrained(
    "kandinsky-community/kandinsky-3",
    variant="fp16",
    torch_dtype=torch.float16
).to("cuda")

def generate(prompt, negative_prompt, steps, guidance, width, height, seed):
    generator = torch.Generator("cuda").manual_seed(seed) if seed > 0 else None

    image = pipe(
        prompt=prompt,
        negative_prompt=negative_prompt,
        num_inference_steps=steps,
        guidance_scale=guidance,
        width=width,
        height=height,
        generator=generator
    ).images[0]

    return image

demo = gr.Interface(
    fn=generate,
    inputs=[
        gr.Textbox(label="Prompt", placeholder="Beschreiben Sie Ihr Bild..."),
        gr.Textbox(label="Negativ-Prompt", value="niedrige Qualität, verschwommen, verzerrt"),
        gr.Slider(10, 100, value=50, step=5, label="Schritte"),
        gr.Slider(1, 20, value=4, step=0.5, label="Guidance-Skala"),
        gr.Slider(512, 1024, value=1024, step=64, label="Breite"),
        gr.Slider(512, 1024, value=1024, step=64, label="Höhe"),
        gr.Number(value=-1, label="Seed (-1 für zufällig)")
    ],
    outputs=gr.Image(label="Generiertes Bild"),
    title="Kandinsky 3 - Bildgenerierung",
    description="Bilder mit mehrsprachigen Prompts generieren. Läuft auf CLORE.AI."
)

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

## Speicheroptimierung

```python
import torch
from diffusers import AutoPipelineForText2Image

pipe = AutoPipelineForText2Image.from_pretrained(
    "kandinsky-community/kandinsky-3",
    variant="fp16",
    torch_dtype=torch.float16
)

# Speicheroptimierungen aktivieren
pipe.enable_model_cpu_offload()

# Oder für sehr wenig VRAM
pipe.enable_sequential_cpu_offload()

# Attention-Slicing aktivieren
pipe.enable_attention_slicing()

image = pipe(
    prompt="Eine wunderschöne Landschaft",
    num_inference_steps=50
).images[0]
```

## Leistung

| Modell        | Auflösung | GPU      | Zeit |
| ------------- | --------- | -------- | ---- |
| Kandinsky 3   | 1024x1024 | RTX 3090 | 15 s |
| Kandinsky 3   | 1024x1024 | RTX 4090 | 10 s |
| Kandinsky 2.2 | 768x768   | RTX 3090 | 8 s  |
| Kandinsky 2.2 | 768x768   | RTX 4090 | 5 s  |

## Fehlerbehebung

### Speicher erschöpft

**Problem:** CUDA-OOM beim Generieren

**Lösungen:**

* CPU-Offloading aktivieren
* Auflösung reduzieren
* Verwenden Sie Kandinsky 2.2 statt 3
* Attention Slicing aktivieren

```python
pipe.enable_model_cpu_offload()
pipe.enable_attention_slicing()
```

### Schlechte Textdarstellung

**Problem:** Text in Bildern sieht falsch aus

**Lösungen:**

* Kandinsky hat Schwierigkeiten mit der Textdarstellung (wie die meisten Diffusionsmodelle)
* Text in der Nachbearbeitung hinzufügen
* Prompts verwenden, die Text vermeiden

### Farben wirken falsch

**Problem:** Die Bildfarben sind ausgewaschen oder übersättigt

**Lösungen:**

* Guidance-Skala anpassen (Bereich 3–6 ausprobieren)
* Farbvorlieben im Prompt angeben
* Mit Farbkorrektur nachbearbeiten

### Langsame Generierung

**Problem:** Die Generierung dauert zu lange

**Lösungen:**

* Inferenzschritte reduzieren (30 reichen oft aus)
* fp16-Präzision verwenden
* Kandinsky 2.2 für schnellere Ergebnisse verwenden
* Auflösung für Vorschauen reduzieren

## Vergleich mit anderen Modellen

| Funktion        | Kandinsky 3  | SDXL      | FLUX        |
| --------------- | ------------ | --------- | ----------- |
| Mehrsprachig    | Hervorragend | Begrenzt  | Begrenzt    |
| Bildqualität    | Hoch         | Sehr hoch | Am höchsten |
| Geschwindigkeit | Mittel       | Mittel    | Langsam     |
| VRAM            | 12 GB        | 12 GB     | 24 GB       |
| Bereichsfüllung | Ja           | Ja        | Begrenzt    |

## Kostenschätzung

Übliche CLORE.AI-Marktplatzpreise (Stand 2024):

| GPU       | Stundensatz | Tagessatz | 4-Stunden-Sitzung |
| --------- | ----------- | --------- | ----------------- |
| RTX 3060  | \~$0.03     | \~$0.70   | \~$0.12           |
| RTX 3090  | \~$0.06     | \~$1.50   | \~$0.25           |
| RTX 4090  | \~$0.10     | \~$2.30   | \~$0.40           |
| A100 40GB | \~$0.17     | \~$4.00   | \~$0.70           |
| A100 80GB | \~$0.25     | \~$6.00   | \~$1.00           |

*Die Preise variieren je nach Anbieter. Prüfen Sie* [*CLORE.AI-Marktplatz*](https://clore.ai/marketplace) *für aktuelle Preise.*

## Nächste Schritte

* FLUX Generation - Bilder höchster Qualität
* Stable Diffusion - beliebteste Option
* [PixArt](/guides/guides_v2-de/bildgenerierung/pixart-image-gen.md) - Schnelle Generierung
* ComfyUI - Erweiterte Workflows


---

# 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/andere-workloads/kandinsky.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.
