Diffusers documentation

Anima

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

Anima

Anima là một mô hình text-to-image tái sử dụng CosmosTransformer3DModel với bộ mã hóa văn bản Qwen3, bộ điều kiện văn bản T5-token và VAE AutoencoderKLQwenImage.

import torch
from diffusers import ModularPipeline

pipe = ModularPipeline.from_pretrained("circlestone-labs/Anima-Base-v1.0-Diffusers")
pipe.load_components(dtype=torch.bfloat16)
pipe.to("cuda")  # or "mps", "xpu", "cpu"

image = pipe(prompt="masterpiece, best quality, 1girl, solo, city lights").images[0]

AnimaModularPipeline

lớp diffusers.AnimaModularPipeline

< >

( blocks: diffusers.modular_pipelines.modular_pipeline.ModularPipelineBlocks | None = Nonepretrained_model_name_or_path: str | os.PathLike | None = Nonecomponents_manager: diffusers.modular_pipelines.components_manager.ComponentsManager | None = Nonecollection: str | None = Noneworkflow: str | None = Nonemodular_config_dict: dict[str, typing.Any] | None = Noneconfig_dict: dict[str, typing.Any] | None = None**kwargs )

Một ModularPipeline cho Anima.

AnimaAutoBlocks

lớp diffusers.AnimaAutoBlocks

< >

( )

Auto Modular pipeline cho việc tạo ảnh từ văn bản và tạo ảnh từ ảnh sử dụng Anima.

Các quy trình làm việc được hỗ trợ:

  • text2image: yêu cầu prompt
  • img2img: yêu cầu image, prompt

Các thành phần: text_encoder (Qwen3Model) tokenizer (Qwen2Tokenizer) t5_tokenizer (T5Tokenizer) guider (ClassifierFreeGuidance) vae (AutoencoderKLQwenImage) image_processor (VaeImageProcessor) text_conditioner (AnimaTextConditioner) transformer (CosmosTransformer3DModel) scheduler (FlowMatchEulerDiscreteScheduler)

Đầu vào: prompt (str): Prompt hoặc các prompt để định hướng tạo ảnh. negative_prompt (str, tùy chọn): Prompt hoặc các prompt không dùng để định hướng tạo ảnh. max_sequence_length (int, tùy chọn, mặc định là 512): Độ dài chuỗi tối đa cho việc mã hóa prompt. image (Image | list, tùy chọn): Ảnh tham chiếu để khử nhiễu. Có thể là một ảnh hoặc danh sách các ảnh. height (int, tùy chọn): Chiều cao của ảnh được tạo ra, tính bằng pixel. width (int, tùy chọn): Chiều rộng của ảnh được tạo ra, tính bằng pixel. generator (Generator, tùy chọn): Torch generator để tạo ra kết quả xác định. num_images_per_prompt (int, tùy chọn, mặc định là 1): Số lượng ảnh cần tạo ra cho mỗi prompt. image_latents (Tensor, tùy chọn): image latents được dùng để định hướng tạo ảnh. Có thể được tạo ra từ bước vae_encoder. num_inference_steps (int): Số bước khử nhiễu. sigmas (list, tùy chọn): Các sigmas tùy chỉnh cho quá trình khử nhiễu. strength (float, tùy chọn, mặc định là 0.9): Độ mạnh cho img2img/inpainting. latents (Tensor): Noisy latents được tạo trước cho việc tạo ảnh. *denoiser_input_fields (None,tùy chọn): Các đầu vào mô hình có điều kiện cho Anima denoiser. output_type (str,tùy chọn*, mặc định là pil): Định dạng đầu ra: ‘pil’, ‘np’, ‘pt’.

Đầu ra: images (list): Các hình ảnh được tạo.

AnimaTextConditioner

lớp diffusers.AnimaTextConditioner

< >

( source_dim: int = 1024target_dim: int = 1024model_dim: int = 1024num_layers: int = 6num_attention_heads: int = 16mlp_ratio: float = 4.0target_vocab_size: int = 32128use_self_attention: bool = Trueuse_layer_norm: bool = Falsemin_sequence_length: int = 512 )

Bộ điều kiện văn bản được Anima sử dụng để ánh xạ các trạng thái ẩn của Qwen3 và các id token của T5 sang các vector nhúng văn bản của Cosmos.

Anima tái sử dụng Cosmos Predict2 DiT. Module điều kiện cụ thể cho mô hình duy nhất là bộ thích ứng LLM này, thực hiện cross-attention từ các embedding token T5 đã học sang các trạng thái ẩn của bộ mã hóa văn bản Qwen3 trước khi vào vòng lặp khuếch tán. target_dim là chiều đầu ra của bộ điều kiện và phải khớp với text_embed_dim của transformer.

forward

< >

( source_hidden_states: Tensortarget_input_ids: Tensortarget_attention_mask: typing.Optional[torch.Tensor] = Nonesource_attention_mask: typing.Optional[torch.Tensor] = None ) → torch.Tensor

Tham số

  • source_hidden_states (torch.Tensor có hình dạng (batch_size, source_sequence_length, source_dim)) — Trạng thái ẩn của bộ mã hóa văn bản Qwen3 để điều kiện hóa.
  • target_input_ids (torch.Tensor có hình dạng (batch_size, target_sequence_length)) — Các id token T5 được sử dụng làm các token truy vấn đã học.
  • target_attention_mask (torch.Tensor, tùy chọn) — Mặt nạ chú ý cho các id token T5 đích.
  • source_attention_mask (torch.Tensor, tùy chọn) — Mặt nạ chú ý cho các trạng thái ẩn nguồn của Qwen3.

Trả về

torch.Tensor

Text conditioning embeddings cho transformer Cosmos.

Update on GitHub