Buckets:

mishig's picture
|
download
raw
7.04 kB
#
# Được cấp phép theo Giấy phép Apache, Phiên bản 2.0 (gọi là "Giấy phép");
# bạn có thể không sử dụng tệp này ngoại trừ tuân thủ theo Giấy phép.
# Bạn có thể nhận được một bản sao của Giấy phép tại
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Trừ khi được yêu cầu bởi luật pháp có hiệu lực hoặc được thỏa thuận bằng văn bản, phần mềm
# được phân phối theo Giấy phép được phân phối trên cơ sở
# KHÔNG CÓ BẢO HÀNH HOẶC ĐIỀU KIỆN DƯỚI BẤT KỲ HÌNH THỨC NÀO, dù được nêu rõ hay ngụ ý.
# Xem Giấy phép để biết ngôn ngữ cụ thể điều chỉnh các quyền và
# giới hạn theo Giấy phép. -->
# Anima
Anima là một mô hình text-to-image tái sử dụng [CosmosTransformer3DModel](/docs/diffusers/main/vi/api/models/cosmos_transformer3d#diffusers.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](/docs/diffusers/main/vi/api/models/autoencoderkl_qwenimage#diffusers.AutoencoderKLQwenImage).
```python
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]]
#### diffusers.AnimaModularPipeline[[diffusers.AnimaModularPipeline]]
```python
diffusers.AnimaModularPipeline(blocks: diffusers.modular_pipelines.modular_pipeline.ModularPipelineBlocks | None = None, pretrained_model_name_or_path: str | os.PathLike | None = None, components_manager: diffusers.modular_pipelines.components_manager.ComponentsManager | None = None, collection: str | None = None, workflow: str | None = None, modular_config_dict: dict[str, typing.Any] | None = None, config_dict: dict[str, typing.Any] | None = None, **kwargs)
```
[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/modular_pipelines/anima/modular_pipeline.py#L19)
Một ModularPipeline cho Anima.
## AnimaAutoBlocks[[diffusers.AnimaAutoBlocks]]
#### diffusers.AnimaAutoBlocks[[diffusers.AnimaAutoBlocks]]
```python
diffusers.AnimaAutoBlocks()
```
[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/modular_pipelines/anima/modular_blocks_anima.py#L312)
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`)
Inputs: 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*): Bộ tạo Torch cho việc tạo ảnh tất định. num_images_per_prompt (`int`, *tùy chọn*, mặc định là 1): Số lượng ảnh cần tạo 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 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): Cường độ 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 điều kiện cho bộ khử nhiễu Anima. output_type (`str`, *tùy chọn*, mặc định là pil): Định dạng đầu ra: 'pil', 'np', 'pt'.
Đầu ra: hình ảnh (`list`): Các hình ảnh được tạo ra.
## AnimaTextConditioner[[diffusers.AnimaTextConditioner]]
#### diffusers.AnimaTextConditioner[[diffusers.AnimaTextConditioner]]
```python
diffusers.AnimaTextConditioner(source_dim: int = 1024, target_dim: int = 1024, model_dim: int = 1024, num_layers: int = 6, num_attention_heads: int = 16, mlp_ratio: float = 4.0, target_vocab_size: int = 32128, use_self_attention: bool = True, use_layer_norm: bool = False, min_sequence_length: int = 512)
```
[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/condition_embedders/condition_embedder_anima.py#L229)
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[[diffusers.AnimaTextConditioner.forward]]
```python
forward(source_hidden_states: Tensor, target_input_ids: Tensor, target_attention_mask: typing.Optional[torch.Tensor] = None, source_attention_mask: typing.Optional[torch.Tensor] = None)
```
[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/condition_embedders/condition_embedder_anima.py#L285)
**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ó shape `(batch_size, target_sequence_length)`) : Các T5 token ids được sử dụng làm các query tokens đã 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.

Xet Storage Details

Size:
7.04 kB
·
Xet hash:
a4ac67fdc90548bf35c65efebc2820ad1c847e488fd7d9761ab768aa1d3d7641

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.