Diffusers documentation

CogView4

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

and get access to the augmented documentation experience

to get started

CogView4

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

이 파이프라인은 zRzRzRzRzRzRzR님이 기여했습니다. 원래 코드베이스는 여기에서 찾을 수 있습니다. 원래 가중치는 hf.co/THUDM에서 찾을 수 있습니다.

CogView4Pipeline

클래스 diffusers.CogView4Pipeline

< >

( tokenizer: AutoTokenizertext_encoder: GlmModelvae: AutoencoderKLtransformer: CogView4Transformer2DModelscheduler: FlowMatchEulerDiscreteScheduler )

매개변수

  • vae (AutoencoderKL) — 이미지를 잠재 표현으로 인코딩하고 디코딩하는 Variational Auto-Encoder (VAE) 모델.
  • text_encoder (GLMModel) — 동결된 텍스트 인코더입니다. CogView4는 glm-4-9b-hf를 사용합니다.
  • tokenizer (PreTrainedTokenizer) — PreTrainedTokenizer 클래스의 토크나이저.
  • transformer (CogView4Transformer2DModel) — 인코딩된 이미지 latents의 노이즈를 제거하기 위한 텍스트 조건부 CogView4Transformer2DModel입니다.
  • scheduler (SchedulerMixin) — transformer와 함께 사용되어 인코딩된 이미지 latents의 노이즈를 제거하는 스케줄러.

CogView4를 사용한 텍스트-이미지 생성을 위한 Pipeline

이 모델은 DiffusionPipeline에서 상속됩니다. 라이브러리가 모든 파이프라인에 대해 구현하는 일반적 메서드(다운로드 또는 저장, 특정 디바이스에서 실행 등)에 대해서는 상위 클래스 문서를 확인하세요.

__call__

< >

( prompt: str | list[str] | None = Nonenegative_prompt: str | list[str] | None = Noneheight: int | None = Nonewidth: int | None = Nonenum_inference_steps: int = 50timesteps: list[int] | None = Nonesigmas: list[float] | None = Noneguidance_scale: float = 5.0num_images_per_prompt: int = 1generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Nonelatents: typing.Optional[torch.FloatTensor] = Noneprompt_embeds: typing.Optional[torch.FloatTensor] = Nonenegative_prompt_embeds: typing.Optional[torch.FloatTensor] = Noneoriginal_size: tuple[int, int] | None = Nonecrops_coords_top_left: tuple = (0, 0)output_type: str = 'pil'return_dict: bool = Trueattention_kwargs: dict[str, typing.Any] | None = Nonecallback_on_step_end: typing.Union[typing.Callable[[int, int], NoneType], diffusers.callbacks.PipelineCallback, diffusers.callbacks.MultiPipelineCallbacks, NoneType] = Nonecallback_on_step_end_tensor_inputs: list = ['latents']max_sequence_length: int = 1024 ) → ~pipelines.cogview4.pipeline_CogView4.CogView4PipelineOutput or tuple

매개변수

  • prompt (str 또는 list[str], 선택 사항) — 이미지 생성을 안내할 프롬프트입니다. 정의되지 않은 경우 prompt_embeds를 전달해야 합니다.
  • negative_prompt (str 또는 list[str], 선택 사항) — 이미지 생성을 안내하지 않을 프롬프트입니다. 정의되지 않은 경우 negative_prompt_embeds를 대신 전달해야 합니다. 가이던스를 사용하지 않을 때 무시됩니다(즉, guidance_scale이 1보다 작으면 무시됩니다).
  • height (int, 선택 사항, 기본값은 self.transformer.config.sample_size * self.vae_scale_factor) — 생성된 이미지의 픽셀 단위 높이입니다. 제공되지 않으면 1024로 설정됩니다.
  • width (int, 선택 사항, 기본값은 self.transformer.config.sample_size * self.vae_scale_factor) — 생성된 이미지의 픽셀 단위 너비입니다. 제공되지 않으면 1024로 설정됩니다.
  • num_inference_steps (int, 선택 사항, 기본값 50) — 디노이징 단계의 수입니다. 디노이징 단계가 많을수록 일반적으로 더 높은 품질의 이미지를 생성하지만, 추론 속도가 느려집니다.
  • timesteps (list[int], 선택 사항) — timesteps 인수를 지원하는 스케줄러의 set_timesteps 메서드에서 디노이징 과정에 사용할 커스텀 timesteps입니다. 정의되지 않은 경우, num_inference_steps가 전달될 때의 기본 동작이 사용됩니다. 내림차순으로 정렬되어 있어야 합니다.
  • sigmas (list[float], 선택 사항) — set_timesteps 메서드에 sigmas 인수를 지원하는 스케줄러의 노이즈 제거 과정에 사용할 커스텀 시그마입니다. 정의되지 않은 경우, num_inference_steps가 전달될 때의 기본 동작이 사용됩니다.
  • guidance_scale (float, 선택 사항, 기본값 5.0) — Classifier-Free Diffusion Guidance에서 정의한 가이던스 스케일입니다. guidance_scale은 Imagen Paper의 방정식 2의 w로 정의됩니다. guidance_scale > 1로 설정하면 가이던스 스케일이 활성화됩니다. 가이던스 스케일이 높을수록 prompt 텍스트와 밀접하게 연결된 이미지를 생성하도록 유도하지만, 일반적으로 이미지 품질이 낮아지는 대가를 치릅니다.
  • num_images_per_prompt (int, 선택 사항, 기본값 1) — 프롬프트당 생성할 이미지의 수입니다.
  • generator (torch.Generator 또는 list[torch.Generator], 선택 사항) — 생성을 결정적으로 만들기 위한 torch generator 하나 또는 목록
  • latents (torch.FloatTensor, 선택 사항) — 이미지 생성의 입력으로 사용할 가우시안 분포에서 샘플링된 사전 생성된 노이즈 latents입니다. 동일한 생성을 다른 프롬프트로 조정하는 데 사용할 수 있습니다. 제공되지 않으면, 제공된 무작위 generator를 사용하여 샘플링하여 latents 텐서가 생성됩니다.
  • prompt_embeds (torch.FloatTensor, 선택) — 미리 생성된 텍스트 임베딩입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 prompt 입력 인자로부터 텍스트 임베딩이 생성됩니다.
  • negative_prompt_embeds (torch.FloatTensor, optional) — 미리 생성된 부정 텍스트 임베딩입니다. 프롬프트 가중치와 같은 텍스트 입력을 쉽게 조정하는 데 사용할 수 있습니다. e.g. 제공되지 않으면 negative_prompt 입력 인수에서 negative_prompt_embeds가 생성됩니다.
  • original_size (tuple[int], 선택 사항, 기본값 (1024, 1024)) — original_size가 target_size와 다르면 이미지가 다운샘플링 또는 업샘플링된 것처럼 보입니다. 지정되지 않으면 original_size의 기본값은 (height, width)입니다. https://huggingface.co/papers/2307.01952의 2.2절에서 설명된 SDXL의 마이크로 컨디션잉(micro-conditioning)의 일부입니다.
  • crops_coords_top_left (tuple[int], 선택 사항, 기본값 (0, 0)) — crops_coords_top_left는 crops_coords_top_left 위치에서 아래쪽으로 “잘라낸” 것처럼 보이는 이미지를 생성하는 데 사용할 수 있습니다. crops_coords_top_left를 (0, 0)으로 설정하면 일반적으로 잘 중앙 정렬된 이미지를 얻을 수 있습니다. https://huggingface.co/papers/2307.01952의 2.2절에서 설명된 SDXL의 micro-conditioning의 일부입니다.
  • output_type (str, 선택 사항, 기본값 "pil") — 이미지 생성의 출력 형식입니다. PIL: PIL.Image.Image 또는 np.array 중 하나를 선택합니다.
  • return_dict (bool, 선택 사항, 기본값 True) — 일반 튜플 대신 ~pipelines.stable_diffusion_xl.StableDiffusionXLPipelineOutput를 반환할지 여부.
  • attention_kwargs (dict, 선택 사항) — 지정된 경우 diffusers.models.attention_processor의 self.processor에서 정의된 AttentionProcessor로 전달되는 kwargs 사전입니다.
  • 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 속성에 나열된 변수만 포함할 수 있습니다.
  • max_sequence_length (int, 기본값 224) — 인코딩된 프롬프트의 최대 시퀀스 길이입니다. 다른 값으로 설정할 수 있지만, 결과가 나빠질 수 있습니다.

반환값

~pipelines.cogview4.pipeline_CogView4.CogView4PipelineOutput 또는 tuple

return_dict가 True인 경우 ~pipelines.cogview4.pipeline_CogView4.CogView4PipelineOutput, 그렇지 않으면 tuple입니다. tuple을 반환할 경우 첫 번째 요소는 생성된 이미지의 리스트입니다.

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

예:

>>> import torch
>>> from diffusers import CogView4Pipeline

>>> pipe = CogView4Pipeline.from_pretrained("THUDM/CogView4-6B", torch_dtype=torch.bfloat16)
>>> pipe.to("cuda")

>>> prompt = "A photo of an astronaut riding a horse on mars"
>>> image = pipe(prompt).images[0]
>>> image.save("output.png")

encode_prompt

< >

( prompt: str | list[str]negative_prompt: str | list[str] | None = Nonedo_classifier_free_guidance: bool = Truenum_images_per_prompt: int = 1prompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Nonedevice: typing.Optional[torch.device] = Nonedtype: typing.Optional[torch.dtype] = Nonemax_sequence_length: int = 1024 )

매개변수

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

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

CogView4PipelineOutput

클래스 diffusers.pipelines.cogview4.pipeline_output.CogView4PipelineOutput

< >

( images: list[PIL.Image.Image] | numpy.ndarray )

매개변수

  • images (list[PIL.Image.Image] 또는 np.ndarray) — batch_size 길이의 denoised PIL 이미지 목록 또는 (batch_size, height, width, num_channels) 형태의 numpy 배열. PIL 이미지 또는 numpy 배열은 diffusion 파이프라인의 denoised 이미지를 나타냅니다.

CogView3 파이프라인의 출력 클래스입니다.

Update on GitHub