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.43.0).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Anima

Anima 是一个文本生成图像模型,它复用了 CosmosTransformer3DModel,并搭配 Qwen3 文本编码器、T5-token 文本条件器以及 AutoencoderKLQwenImage VAE。

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

类 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 )

用于 Anima 的 ModularPipeline。

AnimaAutoBlocks

class diffusers.AnimaAutoBlocks

< >

( )

使用 Anima 的 Auto Modular 流水线,用于文本到图像和图像到图像的生成。

支持的工作流:

  • text2image:需要 prompt
  • img2img:需要 image、prompt

组件: text_encoder (Qwen3Model) tokenizer (Qwen2Tokenizer) t5_tokenizer (T5Tokenizer) guider (ClassifierFreeGuidance) vae (AutoencoderKLQwenImage) image_processor (VaeImageProcessor) text_conditioner (AnimaTextConditioner) transformer (CosmosTransformer3DModel) scheduler (FlowMatchEulerDiscreteScheduler)

输入: prompt (str): 用于引导图像生成的提示词或提示词列表。 negative_prompt (str,可选): 用于排除的提示词或提示词列表,即不希望引导图像生成的内容。 max_sequence_length (int,可选,默认为 512): 提示词编码的最大序列长度。 image (Image | list,可选): 用于去噪的参考图像。可以是单张图像或图像列表。 height (int,可选): 生成图像的高度(以像素为单位)。 width (int,可选): 生成图像的宽度(以像素为单位)。 generator (Generator,可选): 用于确定性生成的 Torch 生成器。 num_images_per_prompt (int,可选,默认为 1): 每个提示词生成的图像数量。 image_latents (Tensor,可选): 用于引导图像生成的图像潜在表示。可以从 vae_encoder 步骤生成。 num_inference_steps (int): 去噪步骤数。 sigmas (list,可选): 用于去噪过程的自定义 sigmas。 strength (float,可选,默认为 0.9): img2img/重绘的强度。 latents (Tensor): 用于图像生成的预生成噪声潜在表示。 *denoiser_input_fields (None,可选): Anima 去噪器的条件模型输入。 output_type (str,可选*,默认为 pil): 输出格式:‘pil’、‘np’、‘pt’。

输出: images (list): 生成的图像。

AnimaTextConditioner

class 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 )

Anima 使用的文本条件器,用于将 Qwen3 隐藏状态和 T5 token id 映射到 Cosmos 文本嵌入。

Anima 复用了 Cosmos Predict2 DiT。唯一的模型特定条件模块是这个 LLM 适配器,它在扩散循环之前,从学习到的 T5 token 嵌入对 Qwen3 文本编码器的隐藏状态进行交叉注意力。target_dim 是条件器的输出维度,必须与 transformer 的 text_embed_dim 相匹配。

forward

< >

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

参数

  • source_hidden_states(形状为 (batch_size, source_sequence_length, source_dim) 的 torch.Tensor)— 用于条件化的 Qwen3 文本编码器隐藏状态。
  • target_input_ids(形状为 (batch_size, target_sequence_length) 的 torch.Tensor)— 用作学习查询 token 的 T5 token id。
  • target_attention_mask (torch.Tensor, 可选) — 目标 T5 token ids 的注意力掩码。
  • source_attention_mask (torch.Tensor, 可选) — 源 Qwen3 隐藏状态的注意力掩码。

返回值

torch.Tensor

Cosmos 变换器的文本条件嵌入。

Update on GitHub