Skip to content

Add Kandinsky 2.1 #3308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 188 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
188 commits
Select commit Hold shift + click to select a range
e09866e
add prior
May 1, 2023
f28ad03
add conversion script
May 1, 2023
09da58a
fix file name
May 3, 2023
6c95524
add unet + text_proj
May 4, 2023
14b3f9d
Merge remote-tracking branch 'origin/main' into kandinsky
May 6, 2023
fee1bba
soft dependency on m-clip
May 6, 2023
06499f7
add dynamic thresholding to unclip
May 6, 2023
2e93e81
Revert "soft dependency on m-clip"
May 7, 2023
a6bacf2
fix a bug in text_proj
May 7, 2023
3888b2d
add PipelineKandinsky
May 8, 2023
ac123e5
[WIP] add Kandinsky image encoder and Multi-clip model (#3373)
ayushtues May 10, 2023
e093722
add image_encoder to prior
May 10, 2023
ca2b15d
add mclip text encoder/tokenizer
May 10, 2023
d3465f0
add
May 10, 2023
f6c55a5
remove comments about batch_size
May 10, 2023
755f026
refactor dynamic threholding
May 10, 2023
843a4d6
put prior pipeline into a seperate file
May 10, 2023
9be8887
add more copy from methods
May 10, 2023
e3ee4a3
make style
May 10, 2023
5a57f23
fix _execution_device for prior pipeline
May 10, 2023
b90b1a9
make fix-copies
May 10, 2023
d177366
make style
May 10, 2023
a122d31
fix some doc string
May 10, 2023
ce2ffb3
style
May 10, 2023
a7a4a55
Update src/diffusers/pipelines/kandinsky/__init__.py
yiyixuxu May 11, 2023
7303cb5
Update src/diffusers/pipelines/kandinsky/pipeline_kandinsky_prior.py
yiyixuxu May 11, 2023
dc219b8
Update src/diffusers/pipelines/kandinsky/pipeline_kandinsky_prior.py
yiyixuxu May 11, 2023
55adf82
Update src/diffusers/pipelines/kandinsky/pipeline_kandinsky_prior.py
yiyixuxu May 11, 2023
54cf752
Update src/diffusers/pipelines/kandinsky/pipeline_kandinsky_prior.py
yiyixuxu May 11, 2023
d63b210
Update src/diffusers/pipelines/kandinsky/pipeline_kandinsky_prior.py
yiyixuxu May 11, 2023
e956043
fix the module names
May 11, 2023
bfa172b
fix height and width arg
May 12, 2023
0568706
add inpaint
May 12, 2023
323aee6
refactor text2imge pipeline
May 12, 2023
faa08f9
add a note about batch_size argument
May 12, 2023
28eb816
finish inpaint pipeline first draft
May 12, 2023
0272da9
add post-processing to inpaint
May 12, 2023
3a5fbf8
Merge remote-tracking branch 'origin/main' into kandinsky
May 12, 2023
e74c173
[WIP] Add Kandinsky decoder (#3330)
ayushtues May 12, 2023
f0a7497
Revert "[WIP] Add Kandinsky decoder (#3330)"
May 12, 2023
ce965b9
ayusha's PR to add MoVQ
May 12, 2023
4f5f380
adapt attention_processor for movq
May 13, 2023
32e1144
add movq module
May 13, 2023
0ba8a62
make style
May 13, 2023
dd218a7
add vq_emb and spatial_norm step bo attnprocessor2.0
May 13, 2023
3adde2c
image_embeds and negative_image_embeds arguments are required
May 15, 2023
3699be5
add tests
May 15, 2023
913ffde
fix
May 15, 2023
a27267f
fix image_embeds dtype
May 15, 2023
333697a
fix cpu offload
May 15, 2023
1080a13
fix batch consistent
May 15, 2023
6aec2d0
remove print line
May 15, 2023
9fbcff1
fix inpaint pipeline
May 15, 2023
7170530
refactor image and mask pre-processing
May 16, 2023
14bb0e9
fix
May 16, 2023
bde29e5
refactor adding movq_scale_factor
May 16, 2023
16dd10c
fix mask dtype
May 16, 2023
b160f89
fix mask shape
May 16, 2023
383c934
add inpaint test
May 16, 2023
793e408
make style
May 16, 2023
a63c272
prior_num_inference_steps -> num_inference_steps
May 16, 2023
a1ddc29
clean up prior pipeline args
May 16, 2023
9aa256a
remove the hardcoded clip image size
May 16, 2023
fed9116
output
May 16, 2023
7ce5c05
add tests for prior
May 16, 2023
795411d
add slow test for text2img
May 16, 2023
faa0145
more tests
May 16, 2023
95efab2
Update src/diffusers/pipelines/kandinsky/text_encoder.py
yiyixuxu May 16, 2023
8eea5a0
Update src/diffusers/pipelines/kandinsky/text_encoder.py
yiyixuxu May 16, 2023
c5c2135
Update src/diffusers/pipelines/kandinsky/text_encoder.py
yiyixuxu May 16, 2023
e261139
fix
May 17, 2023
ff0fe4b
make style
May 17, 2023
3c3e679
fix tokenizer max_length + fix fast tests for text2img
May 17, 2023
3e8d31a
fix inpaint fast test
May 17, 2023
6557f28
make style
May 17, 2023
da35ddf
fix
May 17, 2023
f05c3ac
add doc
May 17, 2023
89319f8
doc
May 17, 2023
88efed5
[WIP] Add img2img (#3426)
ayushtues May 17, 2023
a05cc4f
Revert "[WIP] Add img2img (#3426)"
May 17, 2023
5b0736c
ayush's PR to add img2img #3426
May 17, 2023
012f87f
img2img with ddim
May 18, 2023
af57bea
remove a manual random seed
May 18, 2023
2754aa4
fix
May 18, 2023
d27257e
make batch_size latents, instead of x2
May 18, 2023
4b5538e
more clean up
May 18, 2023
52ae7d9
fix image pre-processing
May 18, 2023
01a05e5
fix batching
May 18, 2023
bbf54dc
add slow test for img2img
May 18, 2023
66ea062
fix slow tests
May 18, 2023
f6e0d2f
make style
May 18, 2023
fac5121
Merge branch 'main' into kandinsky
yiyixuxu May 18, 2023
94dc73b
make style
May 18, 2023
3f5c86b
add doc
May 18, 2023
40247e8
Refactor Kadinsky
patrickvonplaten May 19, 2023
413982d
Remove text_proj
patrickvonplaten May 19, 2023
49f2ef7
Remove text proj class
patrickvonplaten May 19, 2023
ed3d92e
Apply suggestions from code review
yiyixuxu May 20, 2023
38fb834
fix
May 20, 2023
0d28355
add interpolate method
May 20, 2023
419e466
make style
May 20, 2023
52d6944
fix
May 20, 2023
bd65d64
add docstring and post-processing to text2img
May 20, 2023
6bc0aea
fix doc string for inpaint
May 20, 2023
332cb27
more docstring fix
May 20, 2023
214af07
return a tuple in prior
May 20, 2023
d7c8c2e
clean up
May 21, 2023
506e0d1
fix copies
May 21, 2023
e301190
make style
May 21, 2023
056e304
Update src/diffusers/pipelines/kandinsky/pipeline_kandinsky_inpaint.py
yiyixuxu May 21, 2023
b691b63
Update src/diffusers/models/vae.py
yiyixuxu May 21, 2023
5877942
Update src/diffusers/pipelines/kandinsky/pipeline_kandinsky_img2img.py
yiyixuxu May 21, 2023
0fac553
fix copies + testing removing batch_size
May 21, 2023
440a279
update post-processing for prior pipeline
May 21, 2023
74a6be8
update tests (specify steps and cfg arguments)
May 21, 2023
6e3e6af
add back batch_size
May 21, 2023
71fa2bf
update tests
May 21, 2023
550be36
make style
May 21, 2023
391adbf
Update src/diffusers/pipelines/kandinsky/text_encoder.py
yiyixuxu May 22, 2023
67e09da
Update tests/pipelines/kandinsky/test_kandinsky_img2img.py
yiyixuxu May 22, 2023
4257cc7
Update tests/pipelines/kandinsky/test_kandinsky_inpaint.py
yiyixuxu May 22, 2023
003902c
Update tests/pipelines/kandinsky/test_kandinsky_inpaint.py
yiyixuxu May 22, 2023
f1aa660
Update src/diffusers/pipelines/kandinsky/pipeline_kandinsky_prior.py
yiyixuxu May 22, 2023
7f76b45
Merge remote-tracking branch 'origin/main' into kandinsky
May 22, 2023
e2cb50f
fix
May 22, 2023
8f7b7e4
refactor the cfg
May 22, 2023
325b1eb
fix
May 22, 2023
1c5ad4b
refactor for ddim
May 23, 2023
ed24072
add a note about ddpm scheduler
May 23, 2023
8e0a37c
unclip scheduler -> ddim
May 23, 2023
8906756
refactor the cfg in inpaint
May 23, 2023
67c3381
scheduler step_offset =1 for img2img
May 23, 2023
6d9b649
update test_inference_batch_consistent test: output_type ='np'
May 23, 2023
976f47a
update tests
May 23, 2023
c19cb18
update valueerror
May 23, 2023
e3964ce
style
May 23, 2023
89f0cef
update doc
May 23, 2023
acfa8d3
fix
May 23, 2023
7d5635d
make style
May 23, 2023
bec700f
slow test
May 24, 2023
7fea921
style
May 24, 2023
a740352
Update docs/source/en/api/pipelines/kandinsky.mdx
yiyixuxu May 24, 2023
457845e
Update docs/source/en/api/pipelines/kandinsky.mdx
yiyixuxu May 24, 2023
ae9887f
Update docs/source/en/api/pipelines/kandinsky.mdx
yiyixuxu May 24, 2023
5d5fc8b
Update docs/source/en/api/pipelines/kandinsky.mdx
yiyixuxu May 24, 2023
08d123d
Update docs/source/en/api/pipelines/kandinsky.mdx
yiyixuxu May 24, 2023
10f47aa
Update docs/source/en/api/pipelines/kandinsky.mdx
yiyixuxu May 24, 2023
5a12a12
update img2img slow test
May 24, 2023
19c6f3e
style
May 24, 2023
19ea15e
Merge branch 'kandinsky' of https://github.com/huggingface/diffusers …
May 24, 2023
c0957cf
refactor inpaintpipeline to use ddim
May 24, 2023
fd94d17
update tests for inpaint
May 24, 2023
72ca4b1
make style
May 24, 2023
f75796c
Update docs/source/en/api/pipelines/kandinsky.mdx
yiyixuxu May 24, 2023
ae00c84
Update docs/source/en/api/pipelines/kandinsky.mdx
yiyixuxu May 24, 2023
bab4c51
Update docs/source/en/api/pipelines/kandinsky.mdx
yiyixuxu May 24, 2023
7b0a3fc
Update docs/source/en/api/pipelines/kandinsky.mdx
yiyixuxu May 24, 2023
ab41007
Update docs/source/en/api/pipelines/kandinsky.mdx
yiyixuxu May 24, 2023
416c922
Update docs/source/en/api/pipelines/kandinsky.mdx
yiyixuxu May 24, 2023
2e2c0ba
Update docs/source/en/api/pipelines/kandinsky.mdx
yiyixuxu May 24, 2023
47852a9
Update docs/source/en/api/pipelines/kandinsky.mdx
yiyixuxu May 24, 2023
f9fcf47
Update docs/source/en/api/pipelines/kandinsky.mdx
yiyixuxu May 24, 2023
e719e60
Update docs/source/en/api/pipelines/kandinsky.mdx
yiyixuxu May 24, 2023
2228f27
Update src/diffusers/pipelines/kandinsky/pipeline_kandinsky.py
yiyixuxu May 24, 2023
9939627
Update src/diffusers/pipelines/kandinsky/pipeline_kandinsky_prior.py
yiyixuxu May 24, 2023
7ee49a3
Update src/diffusers/pipelines/kandinsky/pipeline_kandinsky_prior.py
yiyixuxu May 24, 2023
a9802aa
remove torchvision transform
May 24, 2023
ac74788
fix test for prior
May 24, 2023
87faa11
style
May 24, 2023
2e073ea
revert unclip scheduler
May 24, 2023
dab1a1f
more
May 24, 2023
410704e
fix inpaint test - update scheduler
May 24, 2023
eb06439
make style
May 24, 2023
b945f8f
change checkpoint name for prior
May 24, 2023
4145c05
update ckpt name for text2img
May 24, 2023
f83dddb
update ckpt for inpaint
May 24, 2023
93f4848
style
May 24, 2023
8d972bf
explain interpolate
May 24, 2023
307cef2
style
May 24, 2023
1634ebd
change default num_inference_steps for prior to 25
May 24, 2023
1f5c724
lose test for inpaint
May 24, 2023
4aa4e35
remove a comment
May 24, 2023
1d18955
udpate
May 24, 2023
8d370ab
style
May 24, 2023
6d360b1
Update docs/source/en/api/pipelines/kandinsky.mdx
yiyixuxu May 25, 2023
6dbbc95
add author names
May 25, 2023
f09306d
Merge branch 'kandinsky' of https://github.com/huggingface/diffusers …
May 25, 2023
357e15a
remove yiyi files
May 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/source/en/_toctree.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@
title: DiT
- local: api/pipelines/if
title: IF
- local: api/pipelines/kandinsky
title: Kandinsky
- local: api/pipelines/latent_diffusion
title: Latent Diffusion
- local: api/pipelines/paint_by_example
Expand Down
306 changes: 306 additions & 0 deletions docs/source/en/api/pipelines/kandinsky.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,306 @@
<!--Copyright 2023 The HuggingFace Team. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
-->

# Kandinsky

## Overview

Kandinsky 2.1 inherits best practices from [DALL-E 2](https://arxiv.org/abs/2204.06125) and [Latent Diffusion](https://huggingface.co/docs/diffusers/api/pipelines/latent_diffusion), while introducing some new ideas.

It uses [CLIP](https://huggingface.co/docs/transformers/model_doc/clip) for encoding images and text, and a diffusion image prior (mapping) between latent spaces of CLIP modalities. This approach enhances the visual performance of the model and unveils new horizons in blending images and text-guided image manipulation.

The Kandinsky model is created by [Arseniy Shakhmatov](https://github.com/cene555), [Anton Razzhigaev](https://github.com/razzant), [Aleksandr Nikolich](https://github.com/AlexWortega), [Igor Pavlov](https://github.com/boomb0om), [Andrey Kuznetsov](https://github.com/kuznetsoffandrey) and [Denis Dimitrov](https://github.com/denndimitrov) and the original codebase can be found [here](https://github.com/ai-forever/Kandinsky-2)

## Available Pipelines:

| Pipeline | Tasks | Colab
|---|---|:---:|
| [pipeline_kandinsky.py](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky/pipeline_kandinsky.py) | *Text-to-Image Generation* | - |
| [pipeline_kandinsky_inpaint.py](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky/pipeline_kandinsky_inpaint.py) | *Image-Guided Image Generation* | - |
| [pipeline_kandinsky_img2img.py](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky/pipeline_kandinsky_img2img.py) | *Image-Guided Image Generation* | - |

## Usage example

In the following, we will walk you through some cool examples of using the Kandinsky pipelines to create some visually aesthetic artwork.

### Text-to-Image Generation

For text-to-image generation, we need to use both [`KandinskyPriorPipeline`] and [`KandinskyPipeline`]. The first step is to encode text prompts with CLIP and then diffuse the CLIP text embeddings to CLIP image embeddings, as first proposed in [DALL-E 2](https://cdn.openai.com/papers/dall-e-2.pdf). Let's throw a fun prompt at Kandinsky to see what it comes up with :)

```python
prompt = "A alien cheeseburger creature eating itself, claymation, cinematic, moody lighting"
negative_prompt = "low quality, bad quality"
```

We will pass both the `prompt` and `negative_prompt` to our prior diffusion pipeline. In contrast to other diffusion pipelines, such as Stable Diffusion, the `prompt` and `negative_prompt` shall be passed separately so that we can retrieve a CLIP image embedding for each prompt input. You can use `guidance_scale`, and `num_inference_steps` arguments to guide this process, just like how you would normally do with all other pipelines in diffusers.

```python
from diffusers import KandinskyPriorPipeline
import torch

# create prior
pipe_prior = KandinskyPriorPipeline.from_pretrained(
"kandinsky-community/kandinsky-2-1-prior", torch_dtype=torch.float16
)
pipe_prior.to("cuda")

generator = torch.Generator(device="cuda").manual_seed(12)
image_emb = pipe_prior(
prompt, guidance_scale=1.0, num_inference_steps=25, generator=generator, negative_prompt=negative_prompt
).images

zero_image_emb = pipe_prior(
negative_prompt, guidance_scale=1.0, num_inference_steps=25, generator=generator, negative_prompt=negative_prompt
).images
Comment on lines +53 to +60
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider discussing why the guidance_scale is so low.

```

Once we create the image embedding, we can use [`KandinskyPipeline`] to generate images.

```python
from PIL import Image
from diffusers import KandinskyPipeline


def image_grid(imgs, rows, cols):
assert len(imgs) == rows * cols

w, h = imgs[0].size
grid = Image.new("RGB", size=(cols * w, rows * h))
grid_w, grid_h = grid.size

for i, img in enumerate(imgs):
grid.paste(img, box=(i % cols * w, i // cols * h))
return grid


# create diffuser pipeline
pipe = KandinskyPipeline.from_pretrained("kandinsky-community/kandinsky-2-1", torch_dtype=torch.float16)
pipe.to("cuda")

images = pipe(
prompt,
image_embeds=image_emb,
negative_image_embeds=zero_image_emb,
num_images_per_prompt=2,
height=768,
width=768,
num_inference_steps=100,
guidance_scale=4.0,
generator=generator,
).images
```

One cheeseburger monster coming up! Enjoy!

![img](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/kandinsky-docs/cheeseburger.png)

The Kandinsky model works extremely well with creative prompts. Here is some of the amazing art that can be created using the exact same process but with different prompts.

```python
prompt = "bird eye view shot of a full body woman with cyan light orange magenta makeup, digital art, long braided hair her face separated by makeup in the style of yin Yang surrealism, symmetrical face, real image, contrasting tone, pastel gradient background"
```
![img](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/kandinsky-docs/hair.png)

```python
prompt = "A car exploding into colorful dust"
```
![img](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/kandinsky-docs/dusts.png)

```python
prompt = "editorial photography of an organic, almost liquid smoke style armchair"
```
![img](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/kandinsky-docs/smokechair.png)

```python
prompt = "birds eye view of a quilted paper style alien planet landscape, vibrant colours, Cinematic lighting"
```
![img](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/kandinsky-docs/alienplanet.png)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have more examples, feel free to log them on Weights and Biases and leave a link here. Optional, though.


### Text Guided Image-to-Image Generation

The same Kandinsky model weights can be used for text-guided image-to-image translation. In this case, just make sure to load the weights using the [`KandinskyImg2ImgPipeline`] pipeline.

**Note**: You can also directly move the weights of the text-to-image pipelines to the image-to-image pipelines
without loading them twice by making use of the [`~DiffusionPipeline.components`] function as explained [here](#converting-between-different-pipelines).

Let's download an image.

```python
from PIL import Image
import requests
from io import BytesIO

# download image
url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg"
response = requests.get(url)
original_image = Image.open(BytesIO(response.content)).convert("RGB")
original_image = original_image.resize((768, 512))
```

![img](https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg)

```python
import torch
from diffusers import KandinskyImg2ImgPipeline, KandinskyPriorPipeline

# create prior
pipe_prior = KandinskyPriorPipeline.from_pretrained(
"kandinsky-community/kandinsky-2-1-prior", torch_dtype=torch.float16
)
pipe_prior.to("cuda")

# create img2img pipeline
pipe = KandinskyImg2ImgPipeline.from_pretrained("kandinsky-community/kandinsky-2-1", torch_dtype=torch.float16)
pipe.to("cuda")

prompt = "A fantasy landscape, Cinematic lighting"
negative_prompt = "low quality, bad quality"

generator = torch.Generator(device="cuda").manual_seed(30)
image_emb = pipe_prior(
prompt, guidance_scale=4.0, num_inference_steps=25, generator=generator, negative_prompt=negative_prompt
).images

zero_image_emb = pipe_prior(
negative_prompt, guidance_scale=4.0, num_inference_steps=25, generator=generator, negative_prompt=negative_prompt
).images

out = pipe(
prompt,
image=original_image,
image_embeds=image_emb,
negative_image_embeds=zero_image_emb,
height=768,
width=768,
num_inference_steps=500,
strength=0.3,
)

out.images[0].save("fantasy_land.png")
```

![img](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/kandinsky-docs/img2img_fantasyland.png)


### Text Guided Inpainting Generation

You can use [`KandinskyInpaintPipeline`] to edit images. In this example, we will add a hat to the portrait of a cat.

```python
from diffusers import KandinskyInpaintPipeline, KandinskyPriorPipeline
from diffusers.utils import load_image
import torch
import numpy as np

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

prompt = "a hat"
image_emb, zero_image_emb = pipe_prior(prompt, return_dict=False)

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

init_image = load_image(
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main" "/kandinsky/cat.png"
)

mask = np.ones((768, 768), dtype=np.float32)
# Let's mask out an area above the cat's head
mask[:250, 250:-250] = 0

out = pipe(
prompt,
image=init_image,
mask_image=mask,
image_embeds=image_emb,
negative_image_embeds=zero_image_emb,
height=768,
width=768,
num_inference_steps=150,
)

image = out.images[0]
image.save("cat_with_hat.png")
```
![img](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/kandinsky-docs/inpaint_cat_hat.png)

### Interpolate

The [`KandinskyPriorPipeline`] also comes with a cool utility function that will allow you to interpolate the latent space of different images and texts super easily. Here is an example of how you can create an Impressionist-style portrait for your pet based on "The Starry Night".

Note that you can interpolate between texts and images - in the below example, we passed a text prompt "a cat" and two images to the `interplate` function, along with a `weights` variable containing the corresponding weights for each condition we interplate.

```python
from diffusers import KandinskyPriorPipeline, KandinskyPipeline
from diffusers.utils import load_image
import PIL

import torch
from torchvision import transforms

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

img1 = load_image(
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main" "/kandinsky/cat.png"
)

img2 = load_image(
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main" "/kandinsky/starry_night.jpeg"
)

# add all the conditions we want to interpolate, can be either text or image
images_texts = ["a cat", img1, img2]
# specify the weights for each condition in images_texts
weights = [0.3, 0.3, 0.4]
image_emb, zero_image_emb = pipe_prior.interpolate(images_texts, weights)

pipe = KandinskyPipeline.from_pretrained("kandinsky-community/kandinsky-2-1", torch_dtype=torch.float16)
pipe.to("cuda")

image = pipe(
"", image_embeds=image_emb, negative_image_embeds=zero_image_emb, height=768, width=768, num_inference_steps=150
).images[0]

image.save("starry_cat.png")
```
![img](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/kandinsky-docs/starry_cat.png)


## KandinskyPriorPipeline

[[autodoc]] KandinskyPriorPipeline
- all
- __call__
- interpolate

## KandinskyPipeline

[[autodoc]] KandinskyPipeline
- all
- __call__

## KandinskyInpaintPipeline

[[autodoc]] KandinskyInpaintPipeline
- all
- __call__

## KandinskyImg2ImgPipeline

[[autodoc]] KandinskyImg2ImgPipeline
- all
- __call__

Loading