ltx2vae ¶
LTX-2 Video VAE implementation
Classes¶
fastvideo.models.vaes.ltx2vae.CausalConv3d ¶
CausalConv3d(in_channels: int, out_channels: int, kernel_size: int = 3, stride: int | Tuple[int, int, int] = 1, dilation: int = 1, groups: int = 1, bias: bool = True, spatial_padding_mode: PaddingModeType = ZEROS)
Bases: Module
Causal 3D convolution that pads temporally by repeating the first frame.
Source code in fastvideo/models/vaes/ltx2vae.py
fastvideo.models.vaes.ltx2vae.DepthToSpaceUpsample ¶
DepthToSpaceUpsample(dims: int, in_channels: int, stride: Tuple[int, int, int], residual: bool = False, out_channels_reduction_factor: int = 1, spatial_padding_mode: PaddingModeType = ZEROS)
Bases: Module
Upsampling via depth-to-space (pixel shuffle).
Source code in fastvideo/models/vaes/ltx2vae.py
fastvideo.models.vaes.ltx2vae.DimensionIntervals dataclass ¶
DimensionIntervals(starts: List[int], ends: List[int], left_ramps: List[int], right_ramps: List[int])
Intervals which a single dimension of the latent space is split into.
fastvideo.models.vaes.ltx2vae.LTX2CausalVideoAutoencoder ¶
Bases: Module
LTX-2 VAE that exposes FastVideo's VAE encode/decode interface. Supports tiled decoding to reduce memory usage for high-resolution videos.
Source code in fastvideo/models/vaes/ltx2vae.py
Methods:¶
fastvideo.models.vaes.ltx2vae.LTX2CausalVideoAutoencoder.decode ¶
Decode latents to video, using tiling if enabled.
Source code in fastvideo/models/vaes/ltx2vae.py
fastvideo.models.vaes.ltx2vae.LTX2CausalVideoAutoencoder.disable_channels_last_3d ¶
Restore contiguous layout for 3D VAE convolutions.
Source code in fastvideo/models/vaes/ltx2vae.py
fastvideo.models.vaes.ltx2vae.LTX2CausalVideoAutoencoder.disable_tiling ¶
fastvideo.models.vaes.ltx2vae.LTX2CausalVideoAutoencoder.enable_channels_last_3d ¶
Enable channels-last layout for 3D VAE convolutions.
Source code in fastvideo/models/vaes/ltx2vae.py
fastvideo.models.vaes.ltx2vae.LTX2CausalVideoAutoencoder.enable_tiling ¶
fastvideo.models.vaes.ltx2vae.LTX2CausalVideoAutoencoder.tiled_decode ¶
tiled_decode(latent: Tensor, tiling_config: TilingConfig | None = None, timestep: Tensor | None = None, generator: Generator | None = None) -> Iterator[Tensor]
Decode a latent tensor into video frames using tiled processing. Splits the latent tensor into tiles, decodes each tile individually, and yields video chunks as they become available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latent | Tensor | Input latent tensor (B, C, F', H', W'). | required |
tiling_config | TilingConfig | None | Tiling configuration for the latent tensor. | None |
timestep | Tensor | None | Optional timestep for decoder conditioning. | None |
generator | Generator | None | Optional random generator for deterministic decoding. | None |
Yields:
| Type | Description |
|---|---|
Tensor | Video chunks (B, C, T, H, W) by temporal slices. |
Source code in fastvideo/models/vaes/ltx2vae.py
1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 | |
fastvideo.models.vaes.ltx2vae.LTX2VideoDecoder ¶
fastvideo.models.vaes.ltx2vae.LTX2VideoEncoder ¶
fastvideo.models.vaes.ltx2vae.LatentIntervals dataclass ¶
LatentIntervals(original_shape: Size, dimension_intervals: Tuple[DimensionIntervals, ...])
Intervals which the latent tensor of given shape is split into.
fastvideo.models.vaes.ltx2vae.PerChannelStatistics ¶
PerChannelStatistics(latent_channels: int = 128)
Bases: Module
Per-channel statistics for normalizing and denormalizing the latent representation. Statistics are computed over the dataset and stored in the model checkpoint.
Source code in fastvideo/models/vaes/ltx2vae.py
fastvideo.models.vaes.ltx2vae.PixArtAlphaCombinedTimestepSizeEmbeddings ¶
Bases: Module
Timestep embeddings for decoder conditioning.
Source code in fastvideo/models/vaes/ltx2vae.py
fastvideo.models.vaes.ltx2vae.PixelNorm ¶
fastvideo.models.vaes.ltx2vae.ResnetBlock3D ¶
ResnetBlock3D(dims: int, in_channels: int, out_channels: int | None = None, dropout: float = 0.0, groups: int = 32, eps: float = 1e-06, norm_layer: NormLayerType = PIXEL_NORM, inject_noise: bool = False, timestep_conditioning: bool = False, spatial_padding_mode: PaddingModeType = ZEROS)
Bases: Module
A 3D ResNet block with optional timestep conditioning and noise injection.
Source code in fastvideo/models/vaes/ltx2vae.py
fastvideo.models.vaes.ltx2vae.SpaceToDepthDownsample ¶
SpaceToDepthDownsample(dims: int, in_channels: int, out_channels: int, stride: Tuple[int, int, int], spatial_padding_mode: PaddingModeType = ZEROS)
Bases: Module
Downsampling via space-to-depth with residual connection.
Source code in fastvideo/models/vaes/ltx2vae.py
fastvideo.models.vaes.ltx2vae.SpatialTilingConfig dataclass ¶
Configuration for dividing each frame into spatial tiles with optional overlap.
fastvideo.models.vaes.ltx2vae.TemporalTilingConfig dataclass ¶
Configuration for dividing a video into temporal tiles (chunks of frames) with optional overlap.
fastvideo.models.vaes.ltx2vae.Tile ¶
fastvideo.models.vaes.ltx2vae.TilingConfig dataclass ¶
TilingConfig(spatial_config: SpatialTilingConfig | None = None, temporal_config: TemporalTilingConfig | None = None)
Configuration for splitting video into tiles with optional overlap.
fastvideo.models.vaes.ltx2vae.TimestepEmbedding ¶
Bases: Module
MLP for timestep embeddings.
Source code in fastvideo/models/vaes/ltx2vae.py
fastvideo.models.vaes.ltx2vae.Timesteps ¶
Bases: Module
Sinusoidal timestep embeddings.
Source code in fastvideo/models/vaes/ltx2vae.py
fastvideo.models.vaes.ltx2vae.UNetMidBlock3D ¶
UNetMidBlock3D(dims: int, in_channels: int, dropout: float = 0.0, num_layers: int = 1, resnet_eps: float = 1e-06, resnet_groups: int = 32, norm_layer: NormLayerType = GROUP_NORM, inject_noise: bool = False, timestep_conditioning: bool = False, spatial_padding_mode: PaddingModeType = ZEROS, attention_head_dim: int | None = None)
Bases: Module
A 3D UNet mid-block with multiple residual blocks.
Source code in fastvideo/models/vaes/ltx2vae.py
fastvideo.models.vaes.ltx2vae.VideoDecoder ¶
VideoDecoder(convolution_dimensions: int = 3, in_channels: int = 128, out_channels: int = 3, decoder_blocks: list[tuple[str, int | dict]] = [], patch_size: int = 4, norm_layer: NormLayerType = PIXEL_NORM, causal: bool = False, timestep_conditioning: bool = False, decoder_spatial_padding_mode: PaddingModeType = REFLECT)
Bases: Module
LTX-2 Video Decoder. Decodes latent representation into video frames.
Source code in fastvideo/models/vaes/ltx2vae.py
1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 | |
fastvideo.models.vaes.ltx2vae.VideoDecoderConfigurator ¶
Configurator for creating a video VAE Decoder from a configuration dictionary.
fastvideo.models.vaes.ltx2vae.VideoEncoder ¶
VideoEncoder(convolution_dimensions: int = 3, in_channels: int = 3, out_channels: int = 128, encoder_blocks: list[tuple[str, int]] | list[tuple[str, dict[str, Any]]] = [], patch_size: int = 4, norm_layer: NormLayerType = PIXEL_NORM, latent_log_var: LogVarianceType = UNIFORM, encoder_spatial_padding_mode: PaddingModeType = ZEROS)
Bases: Module
LTX-2 Video Encoder. Encodes video frames into a latent representation.
Source code in fastvideo/models/vaes/ltx2vae.py
1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 | |
fastvideo.models.vaes.ltx2vae.VideoEncoderConfigurator ¶
Configurator for creating a video VAE Encoder from a configuration dictionary.
fastvideo.models.vaes.ltx2vae.VideoLatentShape ¶
Functions:¶
fastvideo.models.vaes.ltx2vae.compute_trapezoidal_mask_1d ¶
compute_trapezoidal_mask_1d(length: int, ramp_left: int, ramp_right: int, left_starts_from_0: bool = False) -> Tensor
Generate a 1D trapezoidal blending mask with linear ramps.
Source code in fastvideo/models/vaes/ltx2vae.py
fastvideo.models.vaes.ltx2vae.make_conv_nd ¶
make_conv_nd(dims: int, in_channels: int, out_channels: int, kernel_size: int, stride: int | Tuple[int, int, int] = 1, padding: int = 0, dilation: int = 1, groups: int = 1, bias: bool = True, causal: bool = False, spatial_padding_mode: PaddingModeType = ZEROS) -> Module
Create a convolution layer (2D or 3D, causal or not).
Source code in fastvideo/models/vaes/ltx2vae.py
fastvideo.models.vaes.ltx2vae.make_linear_nd ¶
Create a 1x1 convolution (pointwise linear).
Source code in fastvideo/models/vaes/ltx2vae.py
fastvideo.models.vaes.ltx2vae.patchify ¶
Rearrange spatial dimensions into channels (space-to-depth).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x | Tensor | Input tensor (4D or 5D) | required |
patch_size_hw | int | Spatial patch size for height and width. | required |
patch_size_t | int | Temporal patch size. Default=1 (no temporal patching). | 1 |
For 5D: (B, C, F, H, W) -> (B, Cpatch_size_hw^2patch_size_t, F/patch_size_t, H/patch_size_hw, W/patch_size_hw)
Source code in fastvideo/models/vaes/ltx2vae.py
fastvideo.models.vaes.ltx2vae.unpatchify ¶
Rearrange channels back into spatial dimensions (depth-to-space).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x | Tensor | Input tensor (4D or 5D) | required |
patch_size_hw | int | Spatial patch size for height and width. | required |
patch_size_t | int | Temporal patch size. Default=1 (no temporal expansion). | 1 |
For 5D: (B, Cpatch_size_hw^2patch_size_t, F, H, W) -> (B, C, Fpatch_size_t, Hpatch_size_hw, W*patch_size_hw)