Diffusers documentation

Kandinsky 3

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v0.43.0).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Kandinsky 3

LoRA

Kandinsky 3은 Vladimir Arkhipkin, Anastasia Maltseva, Igor Pavlov, Andrei Filatov, Arseniy Shakhmatov, Andrey Kuznetsov, Denis Dimitrov, Zein Shaheen에 의해 개발되었습니다.

GitHub 페이지의 설명:

Kandinsky 3.0는 Kandinsky2-x 모델 계열을 기반으로 구축된 오픈소스 텍스트-이미지 확산 모델입니다. 이전 버전과 비교하여 텍스트 인코더와 Diffusion U-Net 모델의 크기를 각각 늘림으로써 모델의 텍스트 이해 능력과 시각적 품질을 향상시켰습니다.

아키텍처에는 3개의 주요 구성 요소가 포함되어 있습니다:

  1. T5 아키텍처 기반의 인코더-디코더 모델인 FLAN-UL2
  2. BigGAN-deep 블록을 갖춘 새로운 U-Net 아키텍처는 매개변수 수를 동일하게 유지하면서 깊이를 두 배로 늘립니다.
  3. Sber-MoVQGAN은 이미지 복원 분야에서 우수한 결과를 입증한 디코더입니다.

원본 코드베이스는 ai-forever/Kandinsky-3에서 찾을 수 있습니다.

Hub의 Kandinsky Community 조직에서 텍스트-이미지, 이미지-이미지, 인페인팅과 같은 작업에 대한 공식 모델 체크포인트를 확인해 보세요.

스케줄러의 가이드를 확인하여 스케줄러의 속도와 품질 사이의 트레이드오프를 탐색하는 방법을 배우고, 파이프라인 간 구성 요소 재사용 섹션을 확인하여 동일한 구성 요소를 여러 파이프라인에 효율적으로 로드하는 방법을 배워보세요.

Kandinsky3Pipeline

클래스 diffusers.Kandinsky3Pipeline

< >

( tokenizer: T5Tokenizertext_encoder: T5EncoderModelunet: Kandinsky3UNetscheduler: DDPMSchedulermovq: VQModel )

__call__

< >

( prompt: str | list[str] = Nonenum_inference_steps: int = 25guidance_scale: float = 3.0negative_prompt: str | list[str] | None = Nonenum_images_per_prompt: int | None = 1height: int | None = 1024width: int | None = 1024generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Noneprompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Noneattention_mask: typing.Optional[torch.Tensor] = Nonenegative_attention_mask: typing.Optional[torch.Tensor] = Noneoutput_type: str | None = 'pil'return_dict: bool = Truelatents = Nonecallback_on_step_end: typing.Optional[typing.Callable[[int, int], NoneType]] = Nonecallback_on_step_end_tensor_inputs: list[str] = ['latents']**kwargs ) → ImagePipelineOutput or tuple

매개변수

  • prompt (str 또는 list[str], 선택 사항) — 이미지 생성을 안내할 프롬프트입니다. 정의되지 않은 경우 prompt_embeds를 대신 전달해야 합니다.
  • num_inference_steps (int, 선택 사항, 기본값 25) — 디노이징 단계의 수입니다. 디노이징 단계가 많을수록 일반적으로 더 높은 품질의 이미지를 생성하지만, 추론 속도가 느려집니다.
  • guidance_scale (float, 선택 사항, 기본값 3.0) — Classifier-Free Diffusion Guidance에서 정의한 가이던스 스케일입니다. guidance_scale은 Imagen Paper의 방정식 2의 w로 정의됩니다. guidance_scale > 1로 설정하면 가이던스 스케일이 활성화됩니다. 가이던스 스케일이 높을수록 prompt 텍스트와 밀접하게 연결된 이미지를 생성하도록 유도하지만, 일반적으로 이미지 품질이 낮아지는 대가를 치릅니다.
  • negative_prompt (str 또는 list[str], 선택 사항) — 이미지 생성을 안내하지 않을 프롬프트입니다. 정의되지 않은 경우 negative_prompt_embeds를 대신 전달해야 합니다. 가이던스를 사용하지 않을 때 무시됩니다(즉, guidance_scale이 1보다 작으면 무시됩니다).
  • num_images_per_prompt (int, 선택 사항, 기본값 1) — 프롬프트당 생성할 이미지의 수입니다.
  • height (int, 선택 사항, 기본값 self.unet.config.sample_size) — 생성된 이미지의 픽셀 단위 높이입니다.
  • width (int, 선택 사항, 기본값 self.unet.config.sample_size) — 생성된 이미지의 픽셀 단위 너비입니다.
  • generator (torch.Generator 또는 list[torch.Generator], 선택 사항) — 생성을 결정적으로 만들기 위한 torch generator 하나 또는 목록
  • prompt_embeds (torch.Tensor, 선택) — 미리 생성된 텍스트 임베딩입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 prompt 입력 인자로부터 텍스트 임베딩이 생성됩니다.
  • negative_prompt_embeds (torch.Tensor, 선택 사항) — 미리 생성된 negative text embeddings입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 negative_prompt 입력 인자로부터 negative_prompt_embeds가 생성됩니다.
  • attention_mask (torch.Tensor, 선택 사항) — 미리 생성된 attention mask입니다. prompt_embeds를 직접 전달하는 경우 반드시 제공해야 합니다.
  • negative_attention_mask (torch.Tensor, 선택 사항) — 미리 생성된 negative attention mask입니다. negative_prompt_embeds를 직접 전달하는 경우 반드시 제공해야 합니다.
  • output_type (str, 선택 사항, 기본값 "pil") — 이미지 생성의 출력 형식입니다. PIL: PIL.Image.Image 또는 np.array 중 하나를 선택합니다.
  • return_dict (bool, 선택 사항, 기본값 True) — ~pipelines.stable_diffusion.IFPipelineOutput을 반환할지, 아니면 일반 튜플을 반환할지를 결정합니다.
  • latents (torch.Tensor, 선택 사항) — 이미지 생성의 입력으로 사용할 가우시안 분포에서 샘플링된 사전 생성된 노이즈 latents입니다. 동일한 생성을 다른 프롬프트로 조정하는 데 사용할 수 있습니다. 제공되지 않으면, 제공된 랜덤 generator를 사용하여 샘플링하여 latents 텐서가 생성됩니다.
  • callback_on_step_end (Callable, 선택 사항) — 추론 중 각 디노이징 단계의 끝에서 호출되는 함수입니다. 이 함수는 다음 인수를 받아 호출됩니다: callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict). callback_kwargs에는 callback_on_step_end_tensor_inputs로 지정된 모든 텐서 목록이 포함됩니다.
  • callback_on_step_end_tensor_inputs (list, 선택 사항) — callback_on_step_end 함수의 텐서 입력 목록입니다. 목록에 지정된 텐서는 callback_kwargs 인수로 전달됩니다. 파이프라인 클래스의 ._callback_tensor_inputs 속성에 나열된 변수만 포함할 수 있습니다.

반환값

ImagePipelineOutput 또는 tuple

생성을 위해 파이프라인을 호출할 때 호출되는 함수.

예:

>>> from diffusers import AutoPipelineForText2Image
>>> import torch

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

>>> prompt = "A photograph of the inside of a subway train. There are raccoons sitting on the seats. One of them is reading a newspaper. The window shows the city in the background."

>>> generator = torch.Generator(device="cpu").manual_seed(0)
>>> image = pipe(prompt, num_inference_steps=25, generator=generator).images[0]

encode_prompt

< >

( promptdo_classifier_free_guidance = Truenum_images_per_prompt = 1device = Nonenegative_prompt = Noneprompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = None_cut_context = Falseattention_mask: typing.Optional[torch.Tensor] = Nonenegative_attention_mask: typing.Optional[torch.Tensor] = None )

매개변수

  • prompt (str 또는 list[str], 선택 사항) — 인코딩할 프롬프트
  • device — (torch.device, 선택 사항): 결과 임베딩을 배치할 torch device
  • num_images_per_prompt (int, 선택 사항, 기본값 1) — 프롬프트당 생성할 이미지 수
  • do_classifier_free_guidance (bool, 선택 사항, 기본값 True) — classifier free guidance를 사용할지 여부
  • negative_prompt (str 또는 list[str], 선택 사항) — 이미지 생성을 안내하지 않을 프롬프트입니다. 정의되지 않은 경우 negative_prompt_embeds를 대신 전달해야 합니다. 정의되지 않은 경우 negative_prompt_embeds를 대신 전달해야 합니다. 가이던스를 사용하지 않는 경우 무시됩니다(즉, guidance_scale이 1보다 작은 경우 무시됩니다).
  • prompt_embeds (torch.Tensor, 선택) — 미리 생성된 텍스트 임베딩입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 prompt 입력 인자로부터 텍스트 임베딩이 생성됩니다.
  • negative_prompt_embeds (torch.Tensor, 선택 사항) — 미리 생성된 negative text embeddings입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 negative_prompt 입력 인자로부터 negative_prompt_embeds가 생성됩니다.
  • attention_mask (torch.Tensor, 선택 사항) — 미리 생성된 attention mask입니다. prompt_embeds를 직접 전달하는 경우 반드시 제공해야 합니다.
  • negative_attention_mask (torch.Tensor, 선택 사항) — 미리 생성된 negative attention mask입니다. negative_prompt_embeds를 직접 전달하는 경우 반드시 제공해야 합니다.

프롬프트를 텍스트 인코더의 히든 상태로 인코딩합니다.

Kandinsky3Img2ImgPipeline

클래스 diffusers.Kandinsky3Img2ImgPipeline

< >

( tokenizer: T5Tokenizertext_encoder: T5EncoderModelunet: Kandinsky3UNetscheduler: DDPMSchedulermovq: VQModel )

__call__

< >

( prompt: str | list[str] = Noneimage: typing.Union[torch.Tensor, list[torch.Tensor], PIL.Image.Image, list[PIL.Image.Image]] = Nonestrength: float = 0.3num_inference_steps: int = 25guidance_scale: float = 3.0negative_prompt: str | list[str] | None = Nonenum_images_per_prompt: int | None = 1generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Noneprompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Noneattention_mask: typing.Optional[torch.Tensor] = Nonenegative_attention_mask: typing.Optional[torch.Tensor] = Noneoutput_type: str | None = 'pil'return_dict: bool = Truecallback_on_step_end: typing.Optional[typing.Callable[[int, int], NoneType]] = Nonecallback_on_step_end_tensor_inputs: list[str] = ['latents']**kwargs ) → ImagePipelineOutput or tuple

매개변수

  • prompt (str 또는 list[str], 선택 사항) — 이미지 생성을 안내할 프롬프트입니다. 정의되지 않은 경우 prompt_embeds를 대신 전달해야 합니다.
  • image (torch.Tensor, PIL.Image.Image, np.ndarray, list[torch.Tensor], list[PIL.Image.Image] 또는 list[np.ndarray]) — 프로세스의 시작점으로 사용될 Image 또는 이미지 배치 텐서입니다.
  • strength (float, 선택 사항, 기본값 0.8) — 참조 image를 변환하는 정도를 나타냅니다. 0과 1 사이여야 합니다. image가 시작점으로 사용되며, strength 값이 높을수록 더 많은 노이즈가 추가됩니다. 디노이징 단계의 수는 초기에 추가된 노이즈의 양에 따라 결정됩니다. strength가 1이면 추가되는 노이즈가 최대가 되며, num_inference_steps에 지정된 전체 반복 횟수만큼 디노이징 프로세스가 실행됩니다. 1이라는 값은 사실상 image를 무시하는 것과 같습니다.
  • num_inference_steps (int, 선택 사항, 기본값 50) — 디노이징 단계의 수입니다. 디노이징 단계가 많을수록 일반적으로 더 높은 품질의 이미지를 생성하지만, 추론 속도가 느려집니다.
  • guidance_scale (float, 선택 사항, 기본값 3.0) — Classifier-Free Diffusion Guidance에서 정의한 가이던스 스케일입니다. guidance_scale은 Imagen Paper의 방정식 2의 w로 정의됩니다. guidance_scale > 1로 설정하면 가이던스 스케일이 활성화됩니다. 가이던스 스케일이 높을수록 prompt 텍스트와 밀접하게 연결된 이미지를 생성하도록 유도하지만, 일반적으로 이미지 품질이 낮아지는 대가를 치릅니다.
  • negative_prompt (str 또는 list[str], 선택 사항) — 이미지 생성을 안내하지 않을 프롬프트입니다. 정의되지 않은 경우 negative_prompt_embeds를 대신 전달해야 합니다. 가이던스를 사용하지 않을 때 무시됩니다(즉, guidance_scale이 1보다 작으면 무시됩니다).
  • num_images_per_prompt (int, 선택 사항, 기본값 1) — 프롬프트당 생성할 이미지의 수입니다.
  • generator (torch.Generator 또는 list[torch.Generator], 선택 사항) — 생성을 결정적으로 만들기 위한 torch generator 하나 또는 목록
  • prompt_embeds (torch.Tensor, 선택) — 미리 생성된 텍스트 임베딩입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 prompt 입력 인자로부터 텍스트 임베딩이 생성됩니다.
  • negative_prompt_embeds (torch.Tensor, 선택 사항) — 미리 생성된 negative text embeddings입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 negative_prompt 입력 인자로부터 negative_prompt_embeds가 생성됩니다.
  • attention_mask (torch.Tensor, 선택 사항) — 미리 생성된 attention mask입니다. prompt_embeds를 직접 전달하는 경우 반드시 제공해야 합니다.
  • negative_attention_mask (torch.Tensor, 선택 사항) — 미리 생성된 negative attention mask입니다. negative_prompt_embeds를 직접 전달하는 경우 반드시 제공해야 합니다.
  • output_type (str, 선택 사항, 기본값 "pil") — 이미지 생성의 출력 형식입니다. PIL: PIL.Image.Image 또는 np.array 중 하나를 선택합니다.
  • return_dict (bool, 선택 사항, 기본값 True) — ~pipelines.stable_diffusion.IFPipelineOutput을 반환할지, 아니면 일반 튜플을 반환할지를 결정합니다.
  • callback_on_step_end (Callable, 선택 사항) — 추론 중 각 디노이징 단계의 끝에서 호출되는 함수입니다. 이 함수는 다음 인수를 받아 호출됩니다: callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict). callback_kwargs에는 callback_on_step_end_tensor_inputs로 지정된 모든 텐서 목록이 포함됩니다.
  • callback_on_step_end_tensor_inputs (list, 선택 사항) — callback_on_step_end 함수의 텐서 입력 목록입니다. 목록에 지정된 텐서는 callback_kwargs 인수로 전달됩니다. 파이프라인 클래스의 ._callback_tensor_inputs 속성에 나열된 변수만 포함할 수 있습니다.

반환값

ImagePipelineOutput 또는 tuple

생성을 위해 파이프라인을 호출할 때 호출되는 함수.

예:

>>> from diffusers import AutoPipelineForImage2Image
>>> from diffusers.utils import load_image
>>> import torch

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

>>> prompt = "A painting of the inside of a subway train with tiny raccoons."
>>> image = load_image(
...     "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/kandinsky3/t2i.png"
... )

>>> generator = torch.Generator(device="cpu").manual_seed(0)
>>> image = pipe(prompt, image=image, strength=0.75, num_inference_steps=25, generator=generator).images[0]

encode_prompt

< >

( promptdo_classifier_free_guidance = Truenum_images_per_prompt = 1device = Nonenegative_prompt = Noneprompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = None_cut_context = Trueattention_mask: typing.Optional[torch.Tensor] = Nonenegative_attention_mask: typing.Optional[torch.Tensor] = None )

매개변수

  • prompt (str 또는 list[str], 선택 사항) — 인코딩할 프롬프트

프롬프트를 텍스트 인코더의 히든 상태로 인코딩합니다.

device: (torch.device, optional): 결과 임베딩을 배치할 torch device num_images_per_prompt (int, optional, defaults to 1): 프롬프트당 생성할 이미지 수 do_classifier_free_guidance (bool, optional, defaults to True): classifier free guidance를 사용할지 여부 negative_prompt (str or list[str], optional): 이미지 생성을 유도하지 않을 프롬프트입니다. 정의되지 않은 경우 대신 negative_prompt_embeds를 전달해야 합니다. 정의되지 않은 경우 대신 negative_prompt_embeds를 전달해야 합니다. guidance를 사용하지 않는 경우 무시됩니다(즉, guidance_scale이 1보다 작은 경우 무시됨). prompt_embeds (torch.Tensor, optional): 미리 생성된 텍스트 임베딩입니다. e.g. 프롬프트 가중치와 같은 텍스트 입력을 쉽게 조정하는 데 사용할 수 있습니다. 제공되지 않으면 prompt 입력 인자에서 텍스트 임베딩이 생성됩니다. negative_prompt_embeds (torch.Tensor, optional): 미리 생성된 negative text embeddings입니다. e.g. 프롬프트 가중치와 같은 텍스트 입력을 쉽게 조정하는 데 사용할 수 있습니다. 제공되지 않으면 negative_prompt 입력 인자에서 negative_prompt_embeds가 생성됩니다. attention_mask (torch.Tensor, optional): 미리 생성된 attention mask입니다. prompt_embeds를 직접 전달하는 경우 제공해야 합니다. negative_attention_mask (torch.Tensor, optional): 미리 생성된 negative attention mask입니다. negative_prompt_embeds를 직접 전달하는 경우 제공해야 합니다.

Update on GitHub