Diffusers documentation

Echo

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

Echo

Echo là một mô hình tạo video dài. Nó hỗ trợ khung hình đầu tiên sạch tùy chọn, các khe bộ nhớ hình ảnh/âm thanh có thứ tự, và trình lấy mẫu Distribution Matching Distillation (DMD) ngẫu nhiên với vài bước. Pipeline tạo ra video và âm thanh đồng bộ.

Echo được triển khai dưới dạng ModularPipeline nên các khối mã hóa văn bản, điều kiện hóa bộ nhớ, khử nhiễu DMD ngẫu nhiên và giải mã của nó có thể được chạy như một quy trình hoàn chỉnh hoặc được kết hợp độc lập.

Suy luận

Tải trực tiếp checkpoint chính thức jdopensource/JoyAI-Echo. Nó sử dụng text encoder và tokenizer từ google/gemma-3-12b-it. Kho Gemma được bảo vệ, vì vậy hãy chấp nhận giấy phép của nó và xác thực với Hugging Face trước khi tải pipeline.

Mô hình đã phát hành sử dụng 241 khung hình trong ví dụ video dài. Tọa độ RoPE của video vẫn giữ ở tốc độ huấn luyện là 24 fps, độc lập với tốc độ của container đầu ra.

import torch
import torchaudio
from PIL import Image

from diffusers import ComponentsManager, ModularPipeline
from diffusers.utils import encode_video

manager = ComponentsManager()
pipe = ModularPipeline.from_pretrained("jdopensource/JoyAI-Echo", components_manager=manager)
pipe.load_components(dtype={"default": torch.bfloat16, "audio_vae": torch.float32})
manager.enable_auto_cpu_offload(device="cuda")
pipe.vae.enable_tiling()

first_frame = Image.open("first_frame.png").convert("RGB")
memory_images = [Image.open(path).convert("RGB") for path in ["memory_0.png", "memory_1.png"]]
memory_audio_with_rates = [torchaudio.load(path) for path in ["memory_0.wav", "memory_1.wav"]]
memory_audio = [waveform for waveform, _ in memory_audio_with_rates]
memory_audio_rates = [sample_rate for _, sample_rate in memory_audio_with_rates]

output = pipe(
    prompt="A cinematic dialogue scene in a quiet cafe.",
    image=first_frame,
    memory_images=memory_images,
    memory_audio_waveforms=memory_audio,
    memory_audio_sample_rates=memory_audio_rates,
    width=1280,
    height=736,
    num_frames=241,
    frame_rate=25.0,
    model_frame_rate=24.0,
    generator=torch.Generator(device="cuda").manual_seed(42),
    output_type="np",
    output=["videos", "audio"],
)

encode_video(
    output["videos"][0],
    fps=25,
    audio=output["audio"][0].float().cpu(),
    audio_sample_rate=pipe.vocoder.config.output_sampling_rate,
    output_path="echo.mp4",
)

Lịch sigma DMD mặc định là lịch tám bước đã được phát hành. Nó dự đoán x0 ở mỗi bước và thêm nhiễu lại bằng nhiễu Gaussian mới ở sigma tiếp theo, do đó một torch.Generator có seed sẽ kiểm soát cả nhiễu ban đầu lẫn tất cả các lần thêm nhiễu trung gian.

Việc mã hóa âm thanh-thuật toán từ bộ nhớ thô yêu cầu torchaudio. Để đảm bảo tính tương thích tham chiếu, hãy giữ audio_vae ở FP32 như đã minh họa ở trên. Các luồng công việc dạng module có thể lưu cache các tensor đã chuẩn hóa và giải nén của bộ mã hóa VAE. Video latents có hình dạng (batch, channels, frames, height, width) và audio latents có hình dạng (batch, channels, time, mel_bins). Khối denoise cốt lõi sẽ đóng gói các tensor đó, mở rộng điều kiện cho num_videos_per_prompt, và giải nén các đầu ra đã khử nhiễu trở lại cùng dạng VAE. Hãy truyền các latents và audio_latents ban đầu ở dạng đã giải nén đó. Các bộ giải mã nhận các tensor VAE đã chuẩn hóa và khử chuẩn hóa ngay trước khi giải mã. output=["latents", "audio_latents"] trả về các tensor VAE đã chuẩn hóa. Với output_type="latent" và output=["videos", "audio"], bạn sẽ nhận được các tensor VAE đã khử chuẩn hóa mà không cần giải mã.

EchoModularPipeline

lớp diffusers.EchoModularPipeline

< >

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

ModularPipeline cho checkpoint DMD video dài của Echo.

EchoBlocks

lớp diffusers.EchoBlocks

< >

( )

Sinh video từ tham chiếu Echo với điều kiện khung hình đầu tiên sạch, các khe bộ nhớ hình ảnh/âm thanh có thứ tự và khử nhiễu DMD ngẫu nhiên.

Các thành phần: text_encoder (PreTrainedModel) tokenizer (PreTrainedTokenizerBase) connectors (LTX2TextConnectors) vae (AutoencoderKLLTX2Video) audio_vae (AutoencoderKLLTX2Audio) transformer (LTX2VideoTransformer3DModel) video_processor (VideoProcessor) vocoder (LTX2Vocoder)

Đầu vào: prompt (str): Prompt hoặc các prompt để định hướng việc tạo hình ảnh. max_sequence_length (int, tùy chọn, mặc định là 1024): Độ dài chuỗi tối đa cho việc mã hóa prompt. image (Image | Tensor, tùy chọn): Khung đầu tiên tùy chọn được sử dụng làm điều kiện tham chiếu sạch. memory_images (list, tùy chọn): Các hình ảnh tham chiếu có thứ tự, mỗi hình ảnh tương ứng với một ô bộ nhớ Echo. memory_audio_waveforms (list, tùy chọn): Các dạng sóng bộ nhớ có thứ tự dưới dạng tensor (channels, samples). Các đầu vào dài hơn 9,62 giây sẽ được cắt xén xuống cửa sổ có phản hồi cao nhất. Sử dụng None cho một ô im lặng. memory_audio_sample_rates (int | list, tùy chọn): Tần số lấy mẫu dùng chung cho tất cả các dạng sóng bộ nhớ, hoặc một tần số cho mỗi ô. height (int, tùy chọn, mặc định là 512): Chiều cao tính bằng pixel của hình ảnh được tạo ra. width (int, tùy chọn, mặc định là 704): Chiều rộng tính bằng pixel của hình ảnh được tạo ra. model_frame_rate (float, tùy chọn, mặc định là 24.0): Tốc độ khung hình tại thời điểm huấn luyện được sử dụng cho các tọa độ RoPE video của Echo. memory_position_offset (float, tùy chọn, mặc định là 500.0): Tâm thời gian được gán cho ô bộ nhớ đầu tiên. memory_position_slot_stride (float, tùy chọn, mặc định là 50.0): Khoảng cách thời gian giữa các tâm ô bộ nhớ liên tiếp. num_videos_per_prompt (int, tùy chọn, mặc định là 1): Số lượng video cho mỗi prompt. num_frames (int, tùy chọn, mặc định là 241): Số lượng khung hình pixel được tạo ra; phải là 1 + k * vae_temporal_compression_ratio. frame_rate (float, tùy chọn, mặc định là 25.0): Tốc độ khung hình của video được tạo ra. latents (Tensor, tùy chọn): Nhiễu video ban đầu tùy chọn ở dạng VAE (B, C, F, H, W). audio_latents (Tensor, tùy chọn): Nhiễu âm thanh ban đầu tùy chọn ở dạng VAE (B, C, L, M). generator (Generator, tùy chọn): Trình tạo Torch cho việc tạo ra có tính xác định. sigmas (list | tuple): Lịch trình sigma DMD, bao gồm số không cuối cùng. attention_kwargs (dict, tùy chọn): Các kwargs bổ sung cho các bộ xử lý attention. output_type (str, tùy chọn, mặc định là pil): Định dạng đầu ra: ‘pil’, ‘np’, ‘pt’. decode_timestep (None, tùy chọn, mặc định là 0.0): Bước thời gian được sử dụng để giải mã các latents cuối cùng. decode_noise_scale (None, tùy chọn): Hệ số nội suy nhiễu được áp dụng tại bước thời gian giải mã.

Đầu ra: videos (list): Các video được tạo. audio (Tensor): Dạng sóng âm thanh được tạo.

Update on GitHub