返回 JoyAI-Echo
modality.py
1 from dataclasses import dataclass
2
3 import torch
4
5
6 @dataclass(frozen=True)
7 class Modality:
8 """
9 Input data for a single modality (video or audio) in the transformer.
10 Bundles the latent tokens, timestep embeddings, positional information,
11 and text conditioning context for processing by the diffusion transformer.
12 Attributes:
13 latent: Patchified latent tokens, shape ``(B, T, D)`` where *B* is
14 the batch size, *T* is the total number of tokens (noisy +
15 conditioning), and *D* is the input dimension.
16 timesteps: Per-token timestep embeddings, shape ``(B, T)``.
17 positions: Positional coordinates, shape ``(B, 3, T)`` for video
18 (time, height, width) or ``(B, 1, T)`` for audio.
19 context: Text conditioning embeddings from the prompt encoder.
20 enabled: Whether this modality is active in the current forward pass.
21 context_mask: Optional mask for the text context tokens.
22 attention_mask: Optional 2-D self-attention mask, shape ``(B, T, T)``.
23 Values in ``[0, 1]`` where ``1`` = full attention and ``0`` = no
24 attention. ``None`` means unrestricted (full) attention between
25 all tokens. Built incrementally by conditioning items; see
26 :class:`~ltx_core.conditioning.types.attention_strength_wrapper.ConditioningItemAttentionStrengthWrapper`.
27 """
28
29 latent: (
30 torch.Tensor
31 ) # Shape: (B, T, D) where B is the batch size, T is the number of tokens, and D is input dimension
32 sigma: torch.Tensor # Shape: (B,). Current sigma value, used for cross-attention timestep calculation.
33 timesteps: torch.Tensor # Shape: (B, T) where T is the number of timesteps
34 positions: (
35 torch.Tensor
36 ) # Shape: (B, 3, T) for video, where 3 is the number of dimensions and T is the number of tokens
37 context: torch.Tensor
38 enabled: bool = True
39 context_mask: torch.Tensor | None = None
40 attention_mask: torch.Tensor | None = None
41
41 lines PYTHON