nemo_automodel.components.flow_matching.adapters.ltx2
nemo_automodel.components.flow_matching.adapters.ltx2
LTX-2 dual-stream (video + audio) model adapter for the FlowMatching pipeline.
LTX-2’s transformer jointly denoises a video token stream and an audio token
stream with cross-modal attention. The pipeline owns noising and loss for the
primary (video) latents; this adapter additionally noises the audio latents
with the SAME per-sample sigma (independent noise draw), runs the dual-stream
forward, and reports the audio flow-matching loss through the
auxiliary_losses hook. Both streams therefore train from a single forward
and a single backward pass.
Expected batch keys (produced by tools/diffusion/processors/ltx2.py):
- video_latents: [B, 128, F, H, W] (consumed by the pipeline)
- audio_latents: [B, 8, L, 16]
- text_embeddings: [B, T, D_v] video-stream connector output
- audio_text_embeddings: [B, T, D_a] audio-stream connector output
- text_mask: [B, T] post-connector attention mask
Module Contents
Classes
Functions
Data
API
Bases: ModelAdapter
Model adapter for LTX-2 dual-stream (video + audio) transformers.
The adapter is stateless: all per-step tensors live in the inputs dict
created fresh by each prepare_inputs() call, so gradient accumulation
over micro-batches is safe.
Parameters:
Multiplier on the audio flow-matching MSE loss added to the video loss (LTX-2 reference training uses 1.0).
Video frame rate the model was trained at (LTX-2 uses 24).
Drop private stash keys and kwargs the model’s forward doesn’t accept.
Parameters:
The transformer (possibly wrapped; unwrapped via .module
for signature inspection only - the wrapped module is called).
Full inputs dict from prepare_inputs().
Returns: Dict[str, Any]
Kwargs safe to splat into model(...).
Compute the audio flow-matching loss from stashed tensors.
Parameters:
Dictionary from prepare_inputs() after forward() has run;
must contain _audio_pred [B, 8, L, 16] and _audio_target
(float32 [B, 8, L, 16]).
Returns: Dict[str, torch.Tensor] | None
{“audio_loss”: scalar} - unweighted MSE in float32 scaled by
Execute the dual-stream forward pass.
Calls the LTX-2 transformer with the kwargs from prepare_inputs()
(filtered to the model’s forward signature so minor diffusers-version
differences in optional kwargs don’t break the call). The raw
transformer outputs ARE the flow predictions (no conversion).
Parameters:
The LTX-2 transformer (possibly FSDP-wrapped).
Dictionary from prepare_inputs(). Mutated: the unpacked
audio prediction is stashed under _audio_pred for
auxiliary_losses().
Returns: torch.Tensor
Video flow prediction [B, 128, F, H, W].
Prepare dual-stream transformer inputs; noise the audio latents.
The video latents are already noised by the pipeline
(context.noisy_latents). Audio latents are noised here with the
same per-sample sigma and an independent Gaussian draw, in float32
(matching the pipeline’s video noising), then cast to the model dtype.
Parameters:
FlowMatchingContext with batch data. context.timesteps
is the rescaled timestep (sigma * num_train_timesteps) [B];
context.sigma is the raw sigma in [0, 1] [B].
Returns: Dict[str, Any]
Dictionary containing the transformer kwargs:
Raises:
KeyError: If the batch lacks LTX-2 audio/text cache keys.
Cache parameters by the underlying forward callable.
Pack audio latents [B, C, L, M] -> tokens [B, L, C*M].
Pack video latents [B, C, F, H, W] -> tokens [B, FHW, C] (patch size 1).
Unpack audio tokens [B, L, C*M] -> latents [B, C, L, M].
Parameters:
Audio token sequence [B, L, C*M].
Latent mel bin count M (16 for LTX-2).
Returns: torch.Tensor
Audio latents [B, C, L, M].
Unpack video tokens [B, FHW, C] -> latents [B, C, F, H, W] (patch size 1).
Parameters:
Video token sequence [B, FHW, C].
Latent frame count F.
Latent height H.
Latent width W.
Returns: torch.Tensor
Video latents [B, C, F, H, W].