How lightricks/ltx-2 works
1. This is a Python monorepo for a foundation video generation system. It is split into three product-level packages: ltx-core for model/runtime primitives, ltx-pipelines for end-user inference workflows, and ltx-trainer for dataset processing and LoRA/fine-tuning.
2. ltx-core is the lowest architectural layer. It contains the reusable model implementation, inference utilities, and performance helpers that pipelines and training both depend on. This package is where checkpoint loading, model composition, conditioning, quantization, and specialized streaming/tiling logic live.
3. The core model layer is divided by modality and model type: a main DiT-style transformer under model/transformer, audio/video VAEs under model/audio_vae and model/video_vae, an upsampler under model/upsampler, and shared model abstractions in model/common and model_protocol.py. This suggests the generation stack is built as latent-space encoding/decoding around a transformer denoiser, with separate components for temporal, spatial, and audio representations.
4. Conditioning is a first-class subsystem in ltx-core. The conditioning package defines typed conditioning inputs such as keyframes, latent conditioning, masks, noise masks, reference audio, and reference video. That boundary is important: pipelines assemble these typed condition objects, while the core model consumes them in a uniform internal format.
5. Inference acceleration and memory management are also centralized in ltx-core. The loader package handles model assembly, attention/kernel selection, LoRA fusion, and single-GPU model building; quantization supports FP8 policies; block_streaming supports streaming model blocks from disk/source/pool abstractions; and tiling/modality_tiling support large-media processing. These are the main runtime boundaries for fitting a large model into GPU memory.
6. ltx-core also includes the text side of the system. The text_encoders/gemma subtree wraps a Gemma-based encoder with tokenizer, feature extraction, prompt files, and embedding connectors. In architecture terms, prompts are converted to text embeddings here before entering the generative model.
7. ltx-pipelines is the orchestration layer for inference modes. Each file in the package corresponds to a specific generation workflow: text-to-video, image-to-video, audio-to-video, distilled fast inference, keyframe interpolation, retake/editing, HDR output, and lip-dub variants. These pipelines combine the core model, text encoder, conditioning objects, denoisers/samplers, and postprocessing into a user-facing execution path.
8. The pipeline layer is where the major data flow is assembled: prompt or media input enters, gets encoded into text/audio/image/video latents or conditions, then a denoising loop runs, often in one or two stages, and finally decoded frames/audio are produced. The README’s emphasis on two-stage pipelines, spatial upscaling, distilled inference, and optional enhancement shows that generation is typically staged rather than a single monolithic forward pass.
9. ltx-trainer is a separate training and fine-tuning subsystem, not just a wrapper around inference. It owns config-driven training setup, dataset preprocessing/captioning scripts, model loading for training, training state/progress tracking, timestep/sigma sampling, and multiple training strategies. This package forms the boundary where raw media data is turned into training examples and then into updated checkpoints or LoRAs.
10. Training is organized around strategy modules rather than one generic loop. training_strategies contains text-to-video, video-to-video, and flexible strategies, which likely determine which inputs are masked/conditioned and what loss path is used. The configs under configs/ and the scripts/ directory indicate that training is expected to run from declarative presets plus preprocessing jobs such as scene splitting, captioning, and latent decoding.
11. The repository depends on external model assets from Hugging Face rather than shipping weights. The runtime expects the main LTX-2 checkpoint, spatial/temporal upscalers, Gemma text encoder assets, and various LoRAs for specialized behaviors such as camera motion, HDR, and lip dubbing. Those assets are not code dependencies; they are runtime inputs that plug into the loader/pipeline boundary.
12. A useful architecture diagram should show three layers: media and prompt inputs at the top; pipeline orchestration in the middle; and ltx-core model/runtime services beneath it. Training should be drawn as a parallel path that consumes prepared datasets and checkpoints to produce LoRA or model artifacts that later feed back into the inference layer.
Main entry points: loader Model loader · transformer Transformer · trainer.py Trainer · utils Pipeline utils
Components 20
ltx-2
Monorepo for generation runtime, inference pipelines, and training.
- Media + prompts · Text prompts and media assets that enter pipelines or training prep.
- Checkpoints + LoRAs · Produced training artifacts that feed back into inference loading.
ltx-core
Shared model and runtime primitives.
- Model loader · Builds models, selects kernels, fuses LoRAs, and manages attention/runtime ops.
packages/ltx-core/src/ltx_core/loader - Conditioning · Keyframes, latent conditions, masks, noise masks, reference audio/video, and related wrappers.
packages/ltx-core/src/ltx_core/conditioning - Gemma text · Tokenizer, feature extraction, prompt handling, and embedding connectors for text conditioning.
packages/ltx-core/src/ltx_core/text_encoders/gemma - Transformer · Main denoising transformer and shared transformer utilities.
packages/ltx-core/src/ltx_core/model/transformer - Video VAE · Video encoding/decoding, tiling, and memory-efficient decode paths.
packages/ltx-core/src/ltx_core/model/video_vae - Audio VAE · Audio encoding/decoding and vocoder-related components.
packages/ltx-core/src/ltx_core/model/audio_vae - Upsampler · Spatial super-resolution and resampling components.
packages/ltx-core/src/ltx_core/model/upsampler - Runtime helpers · Block streaming, tiling, quantization, schedulers, and guidance helpers used to fit models into memory and run efficiently.
packages/ltx-core/src/ltx_core
ltx-pipelines
Inference workflow orchestration.
- T2V pipeline · Text-to-video generation flow.
packages/ltx-pipelines/src/ltx_pipelines/ti2vid_one_stage.py - I2V pipeline · Image-conditioned video generation flow.
packages/ltx-pipelines/src/ltx_pipelines/ti2vid_two_stages.py - A2VID pipeline · Audio-conditioned video generation flow, including two-stage variants.
packages/ltx-pipelines/src/ltx_pipelines/a2vid_two_stage.py - Edit flows · Retake, keyframe interpolation, HDR, lip-dub, and related specialized generation paths.
packages/ltx-pipelines/src/ltx_pipelines - Pipeline utils · Sampling, denoising, media I/O, GPU model wrappers, and quantization selection for pipelines.
packages/ltx-pipelines/src/ltx_pipelines/utils
ltx-trainer
Dataset processing, training, and fine-tuning.
- Dataset prep · Captioning, scene splitting, preprocessing, latent decoding, and reference computation.
packages/ltx-trainer/scripts - Train loader · Loads base models, HF assets, and training-time model variants.
packages/ltx-trainer/src/ltx_trainer/model_loader.py - Trainer · Config-driven training execution and progress/state management.
packages/ltx-trainer/src/ltx_trainer/trainer.py - Strategies · Text-to-video, video-to-video, and flexible strategies that define training behavior.
packages/ltx-trainer/src/ltx_trainer/training_strategies - Sampling + state · Timestep/sigma sampling, state tracking, and validation/progress helpers.
packages/ltx-trainer/src/ltx_trainer
Connections 26
- Media + prompts → Gemma text: prompt text
- Media + prompts → Conditioning: media conditions
- Gemma text → Pipeline utils: embeddings
- Conditioning → Pipeline utils: typed conditions
- Pipeline utils → Model loader: assemble model
- Model loader → Transformer: build denoiser
- Model loader → Video VAE: load codec
- Model loader → Audio VAE: load codec
- Model loader → Upsampler: load scaler
- T2V pipeline → Transformer: denoise
- I2V pipeline → Transformer: denoise
- A2VID pipeline → Transformer: denoise
- Edit flows → Transformer: denoise
- T2V pipeline → Video VAE: decode frames
- I2V pipeline → Video VAE: decode frames
- A2VID pipeline → Audio VAE: decode audio
- Edit flows → Upsampler: enhance output
- Runtime helpers → Model loader: stream/quantize
- Runtime helpers → Transformer: tile/accelerate
- Dataset prep → Train loader: prepared data
- Train loader → Trainer: training model
- Trainer → Strategies: select strategy
- Trainer → Sampling + state: schedule + state
- Trainer → Checkpoints + LoRAs: emit checkpoints
- Checkpoints + LoRAs → Model loader: reload LoRA/checkpoint
- Checkpoints + LoRAs → Pipeline utils: runtime weights