ai-forever/Kandinsky-2

Jupyter Notebook

Kandinsky 2 — multilingual text2image latent diffusion model

image-generationtext-to-imagediffusionimage2imageinpaintingipython-notebookkandinskyoutpaintingtext2image
스타 성장
스타
2.8k
포크
319
주간 성장
+-1
이슈
78
1k2k
2022년 11월2024년 2월2025년 5월2026년 9월
README

Kandinsky 2.2

Open In Colab — Inference example

Open In Colab — Fine-tuning with LoRA

Description:

Kandinsky 2.2 brings substantial improvements upon its predecessor, Kandinsky 2.1, by introducing a new, more powerful image encoder - CLIP-ViT-G and the ControlNet support.

The switch to CLIP-ViT-G as the image encoder significantly increases the model's capability to generate more aesthetic pictures and better understand text, thus enhancing the model's overall performance.

The addition of the ControlNet mechanism allows the model to effectively control the process of generating images. This leads to more accurate and visually appealing outputs and opens new possibilities for text-guided image manipulation.

Architecture details:

  • Text encoder (XLM-Roberta-Large-Vit-L-14) - 560M
  • Diffusion Image Prior — 1B
  • CLIP image encoder (ViT-bigG-14-laion2B-39B-b160k) - 1.8B
  • Latent Diffusion U-Net - 1.22B
  • MoVQ encoder/decoder - 67M

Сheckpoints:

  • Prior: A prior diffusion model mapping text embeddings to image embeddings
  • Text-to-Image / Image-to-Image: A decoding diffusion model mapping image embeddings to images
  • Inpainting: A decoding diffusion model mapping image embeddings and masked images to images
  • ControlNet-depth: A decoding diffusion model mapping image embedding and additional depth condition to images

Inference regimes

How to use:

Check our jupyter notebooks with examples in ./notebooks folder

1. text2image

from kandinsky2 import get_kandinsky2
model = get_kandinsky2('cuda', task_type='text2img', model_version='2.2')
images = model.generate_text2img(
    "red cat, 4k photo", 
    decoder_steps=50,
    batch_size=1, 
    h=1024,
    w=768,
)

Kandinsky 2.1

Framework: PyTorch Huggingface space Open In Colab

Habr post

Demo

pip install "git+https://github.com/ai-forever/Kandinsky-2.git"

Model architecture:

Kandinsky 2.1 inherits best practicies from Dall-E 2 and Latent diffusion, while introducing some new ideas.

As text and image encoder it uses CLIP model and diffusion image prior (mapping) between latent spaces of CLIP modalities. This approach increases the visual performance of the model and unveils new horizons in blending images and text-guided image manipulation.

For diffusion mapping of latent spaces we use transformer with num_layers=20, num_heads=32 and hidden_size=2048.

Other architecture parts:

  • Text encoder (XLM-Roberta-Large-Vit-L-14) - 560M
  • Diffusion Image Prior — 1B
  • CLIP image encoder (ViT-L/14) - 427M
  • Latent Diffusion U-Net - 1.22B
  • MoVQ encoder/decoder - 67M

Kandinsky 2.1 was trained on a large-scale image-text dataset LAION HighRes and fine-tuned on our internal datasets.

How to use:

Check our jupyter notebooks with examples in ./notebooks folder

1. text2image

from kandinsky2 import get_kandinsky2
model = get_kandinsky2('cuda', task_type='text2img', model_version='2.1', use_flash_attention=False)
images = model.generate_text2img(
    "red cat, 4k photo", 
    num_steps=100,
    batch_size=1, 
    guidance_scale=4,
    h=768, w=768,
    sampler='p_sampler', 
    prior_cf_scale=4,
    prior_steps="5"
)

prompt: "Einstein in space around the logarithm scheme"

2. image fuse

from kandinsky2 import get_kandinsky2
from PIL import Image
model = get_kandinsky2('cuda', task_type='text2img', model_version='2.1', use_flash_attention=False)
images_texts = ['red cat', Image.open('img1.jpg'), Image.open('img2.jpg'), 'a man']
weights = [0.25, 0.25, 0.25, 0.25]
images = model.mix_images(
    images_texts, 
    weights, 
    num_steps=150,
    batch_size=1, 
    guidance_scale=5,
    h=768, w=768,
    sampler='p_sampler', 
    prior_cf_scale=4,
    prior_steps="5"
)

3. inpainting

from kandinsky2 import get_kandinsky2
from PIL import Image
import numpy as np

model = get_kandinsky2('cuda', task_type='inpainting', model_version='2.1', use_flash_attention=False)
init_image = Image.open('img.jpg')
mask = np.ones((768, 768), dtype=np.float32)
mask[:,:550] =  0
images = model.generate_inpainting(
    'man 4k photo', 
    init_image, 
    mask, 
    num_steps=150,
    batch_size=1, 
    guidance_scale=5,
    h=768, w=768,
    sampler='p_sampler', 
    prior_cf_scale=4,
    prior_steps="5"
)

Kandinsky 2.0

Framework: PyTorch Huggingface space Open In Colab

Habr post

Demo

pip install "git+https://github.com/ai-forever/Kandinsky-2.git"

Model architecture:

It is a latent diffusion model with two multilingual text encoders:

  • mCLIP-XLMR 560M parameters
  • mT5-encoder-small 146M parameters

These encoders and multilingual training datasets unveil the real multilingual text-to-image generation experience!

Kandinsky 2.0 was trained on a large 1B multilingual set, including samples that we used to train Kandinsky.

In terms of diffusion architecture Kandinsky 2.0 implements UNet with 1.2B parameters.

Kandinsky 2.0 architecture overview:

How to use:

Check our jupyter notebooks with examples in ./notebooks folder

1. text2img

from kandinsky2 import get_kandinsky2

model = get_kandinsky2('cuda', task_type='text2img')
images = model.generate_text2img('A teddy bear на красной площади', batch_size=4, h=512, w=512, num_steps=75, denoised_type='dynamic_threshold', dynamic_threshold_v=99.5, sampler='ddim_sampler', ddim_eta=0.05, guidance_scale=10)

prompt: "A teddy bear на красной площади"

2. inpainting

from kandinsky2 import get_kandinsky2
from PIL import Image
import numpy as np

model = get_kandinsky2('cuda', task_type='inpainting')
init_image = Image.open('image.jpg')
mask = np.ones((512, 512), dtype=np.float32)
mask[100:] =  0
images = model.generate_inpainting('Девушка в красном платье', init_image, mask, num_steps=50, denoised_type='dynamic_threshold', dynamic_threshold_v=99.5, sampler='ddim_sampler', ddim_eta=0.05, guidance_scale=10)

prompt: "Девушка в красном платье"

3. img2img

from kandinsky2 import get_kandinsky2
from PIL import Image

model = get_kandinsky2('cuda', task_type='img2img')
init_image = Image.open('image.jpg')
images = model.generate_img2img('кошка', init_image, strength=0.8, num_steps=50, denoised_type='dynamic_threshold', dynamic_threshold_v=99.5, sampler='ddim_sampler', ddim_eta=0.05, guidance_scale=10)

Authors

관련 저장소
AUTOMATIC1111/stable-diffusion-webui

Stable Diffusion web UI

PythonPyPIGNU Affero General Public License v3.0deep-learningdiffusion
164.9k30.5k
unslothai/unsloth

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4, MiniMax-H3, Gemma 4, FLUX and more.

PythonPyPIApache License 2.0fine-tuningllama
unsloth.ai/docs
75.9k6.9k
calesthio/OpenMontage

World's first open-source, agentic video production system. 12 production pipelines, 100+ tools, 700+ agent skill and production-knowledge files. Turn your AI coding assistant into a full video production studio.

PythonPyPIGNU Affero General Public License v3.0agentagentic-ai
openmontage.video
56.7k7.1k
mudler/LocalAI

LocalAI is the open-source AI engine. Run any model - LLMs, vision, voice, image, video - on any hardware. No GPU required.

GoGo ModuleslibraryMIT Licensellamaai
localai.io
49k4.4k
khoj-ai/khoj

Your AI second brain. Self-hostable. Get answers from the web or your docs. Build custom agents, schedule automations, do deep research. Turn any online or local LLM into your personal, autonomous AI (gpt, claude, gemini, llama, qwen, mistral). Get started - free.

PythonPyPIGNU Affero General Public License v3.0semantic-searchemacs
khoj.dev
37.2k2.5k
huggingface/diffusers

🤗 Diffusers: State-of-the-art diffusion models for image, video, and audio generation in PyTorch.

PythonPyPIApache License 2.0deep-learningdiffusion
huggingface.co/docs/diffusers
34.5k7.3k
invoke-ai/InvokeAI

Invoke is a leading creative engine for Stable Diffusion models, empowering professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry leading WebUI, and serves as the foundation for multiple commercial products.

PythonPyPIApache License 2.0ai-artartificial-intelligence
invoke-ai.github.io/InvokeAI/
28.2k3k
ATH-MaaS/Pixelle-Video

🚀 AI 全自动短视频引擎 | AI Fully Automated Short Video Engine

PythonPyPIApache License 2.0aigccomfyui
aidc-ai.github.io/Pixelle-Video/zh
27.9k4.1k
op7418/guizang-ppt-skill

AI-agent Skill for generating polished HTML slide decks: editorial magazine and Swiss layouts, image prompts, social covers, and a WebGL/low-power presentation runtime.

HTMLskillGNU Affero General Public License v3.0ai-agentclaude-code
25.9k1.8k
junyanz/pytorch-CycleGAN-and-pix2pix

Image-to-Image Translation in PyTorch

PythonPyPIOtherpytorchgan
25.2k6.6k
EvoLinkAI/awesome-gpt-image-2-API-and-Prompts

GPT-Image-2 API and Prompts

PythonPyPIawesomeCreative Commons Zero v1.0 Universalawesome-listimage-generation
evolink.ai/gpt-image-2-prompts
17.1k1.7k
camenduru/stable-diffusion-webui-colab

stable diffusion webui colab

Jupyter NotebookThe Unlicensestable-diffusionstable-diffusion-web-ui
15.9k2.6k