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
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 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 | |
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
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 | |
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
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 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 | |
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
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 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 | |
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)