Repository navigation
Studio: LTX-2 video LoRA training from still images - #8196
Conversation
Adds LTX-2 as the first video family of the flow-matching DiT LoRA trainer. It is a seventh _FamilySpec plus routing, not a new trainer: the loop, the latent cache, the phased load and the adapter export are all shared with the image families. Milestone one trains from a STILL-IMAGE dataset. A 1-frame clip is a valid LTX-2 input (its VAE compresses time by 8), and style and character LoRAs converge on 20 to 50 stills, so discover_image_caption_pairs is reused verbatim and nothing decodes a video. Clip datasets are a follow-up. What a video family needed beyond the image path: - Audio. Every LTX-2 block carries a second audio stream plus two cross-modality attentions, and forward takes audio_hidden_states as a required argument. Lightricks handle a video-only run by passing audio=None, which their transformer short-circuits; diffusers has no such escape hatch, so the equivalent here is a minimal placeholder audio stream at the step's own sigma, isolate_modalities=True so it cannot reach the video prediction, no audio in the loss, and no audio modules in the LoRA targets. - LoRA targets are fully qualified (attn1.* / attn2.*). The shared bare suffixes would also match audio_attn1, audio_attn2, audio_to_video_attn and video_to_audio_attn, which is the mistake Lightricks warn about in their docs. - Conditioning is two stages: Gemma3-12B, then a connectors module. Only the connector output is cached (the encoder hidden states are ~50x larger), and _free_text_encoders now also drops connectors, audio_vae and vocoder. - LTX-2 conditions on the unscaled timestep, unlike the image families' /1000. - flow_shift defaults to auto: its scheduler sets use_dynamic_shifting, so scheduler.sigmas is the unshifted table and training on it would draw a sigma distribution inference never uses. Routing: video bases live in a separate registry, so until now every video checkpoint fell through resolve_trainable_family's unknown-name fallback and was handed to the SDXL trainer. Video families are now resolved explicitly, and one without a spec (Wan, HunyuanVideo-1.5) is refused by name. Also adds the family defaults from the upstream LoRA configs (rank/alpha 32, lr 1e-4, 512px), a VRAM row, and a resolution-must-be-a-multiple-of-32 gate.
Loop peak 11.2 GB, whole-run peak 34.8 GB on a B200 (nf4, rank 32, 512px stills, batch 1, gradient checkpointing). The run peak is set by the Gemma3-12B conditioning stage, not by the training loop.
… refuse a doomed video base before the GPU teardown Three defects in the LTX-2 video LoRA training path. A completed video run copied its adapter into loras/diffusion and reported the copy as catalog_path. That directory is scanned only by the Images LoRA picker, and core/inference/video.py has no LoRA surface at all, so the mirror was a multi-gigabyte file nothing could load behind a "Deploy to Create" button that could not work. _publish_to_lora_catalog now returns None for a video family, so catalog_path stays unset and the run reports lora_path (and ema_path), which is the adapter a caller loads directly. The Train panel drops the Deploy button and the "added to the LoRA picker" claim when there is no catalog path. A LoRA catalog and a load path for the Video tab is separate, larger work. LTX2Pipeline landed in diffusers 0.39 and the packaging deliberately keeps an older diffusers installable on the Python 3.9 hosts this project still supports, so a supported install can have no LTX2Pipeline at all. Both inference paths already assert the pipeline class exists before a load; the training preflight did not, so ltx-2 resolved as trainable, /diffusion/start unloaded the resident GPU workloads, and only the spawned child failed. resolve_trainable_family now runs the same assert, which puts it ahead of every teardown in the start route. That assert also had to stop raising anything but its own ValueError. diffusers exposes its pipelines through a lazy module, so hasattr is what imports the submodule, and an install whose own dependencies are unsatisfiable raises RuntimeError from there. hasattr only absorbs AttributeError, so a partially usable diffusers escaped the guard exactly the way a missing one used to, as a bare 500 with the message lost. The attribute probe moves inside the try. Finally, unsloth/LTX-2-FP8 resolved as a training base. It holds pre-cast component archives with no model_index.json, no VAE and no pipeline, but it carries the ltx-2 token so the detector claimed it, the unsloth/* trust gate passed it, and the gated-access probe ignores the resulting model_index.json 404 because a 404 is not an access problem. The run therefore evicted the resident models and only then failed inside from_pretrained. The preflight now refuses any repo the registries list only as a component source, read from te_prequant_repos across both the image and the video registry rather than by repo id. The rule is self-limiting: the image FP8 repos are also listed in prequant_repos as full-model mirrors, so they are bases and resolve exactly as before. Tests: the LTX-2 routing test no longer claims the component repo is a base; new tests cover the unpublished video adapter, the refusal on a diffusers without LTX2Pipeline, the component-repo refusal, and the registry-driven rule sparing the image mirrors. The two start-route tests assert the 400 arrives with the GPU teardown never called and the training slot never reserved.
…module cannot import The attribute probe is what imports the pipeline's submodule, so a partially usable diffusers raises RuntimeError there rather than reporting the class missing, and hasattr absorbs only AttributeError. Cover it at the guard itself and at the training preflight that now calls it, where the escape would turn an actionable 400 into a bare 500.
# Conflicts: # studio/backend/core/training/diffusion_dit_trainer.py # studio/backend/core/training/diffusion_train_common.py # studio/backend/tests/test_cached_gguf_routes.py # studio/frontend/src/features/images/train/diffusion-train-panel.tsx
- int8 quantized the audio stream. A still feeds a ONE-token audio stream and torch._int_mm needs M > 16, so audio_proj_in / audio_attn* / audio_ff crashed on the first forward, after the whole base had loaded. Add the LTX-2 audio exclusions, and pass the family through the trainer's int8 path at all -- it was calling the shared helper without one, so no family's small-M exclusions ever applied in training. - Lightricks/LTX-2.3 resolves to the ltx-2 family, so routing already sends it here and calls it trainable, but the training trust gate refused it as untrusted. Inference already trusts it; add the dense base so the two agree. The fp8 variant is not a training base and stays out. - The connector padding side was read before encode_prompt, which is what sets it: diffusers pins Gemma to left padding inside that call and reads the value afterwards. A tokenizer reporting right therefore baked a stale side into the valid-token mask, so any caption shorter than the 1024 pad length trained against conditioning masked on the wrong end.
ltx-2 was standing in for a family with no int8 exclusions of its own, which it no longer is: its one-token audio stream hits the same M floor the rest of that table exists for.
…jections from int8 Two corrections to the previous round. Lightricks/LTX-2.3 is not loadable by the trainer. The repo ships single-file checkpoints and no diffusers layout (no model_index.json, no transformer/ or scheduler/ subfolder); inference assembles 2.3 with from_single_file plus components borrowed from the 2.0 base, which the trainer's from_pretrained cannot do. Allowlisting it let preflight pass and the run evict the user's resident models before failing in the child. Refuse it explicitly in resolution instead, naming the real reason and the base to train from. The int8 audio exclusion was also too narrow. LTX-2's LTX2AdaLayerNormSingle projections (av_cross_attn_video_scale_shift, av_cross_attn_video_a2v_gate and the prompt_adaln pair) carry no audio in their names and match no generic token, yet each is a Linear over a batch-sized input, so they hit the same _int_mm floor at M=1 whatever the audio stream does. The cross-modality pair runs unconditionally, isolate_modalities or not.
|
Tried to capture before/after Studio screenshots for this and could not, because there is nothing to photograph yet: LTX-2 never reaches the Train tab. At head Verified against two installed Studios, one per side, not just by reading the source. The cause is one call: So the trainer works and is reachable by POSTing Two things worth deciding before this merges:
Happy to take either as a follow-up rather than growing this PR, but as it stands the feature ships switched off from the user's point of view. |
# Conflicts: # studio/backend/tests/test_diffusion_training.py
…ioning when the connectors change
|
Resolved the reachability gap I flagged above, in e4045f7.
It now iterates the union ( Two related things fell out of re-checking the rest of the families:
Tests: test_family_train_infos_offers_the_video_family, test_family_train_infos_drops_a_family_this_diffusers_cannot_run, test_the_strict_pipeline_gate_resolves_a_video_family_too. |
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Before/after screenshots of what this lands on screen, taken from two isolated Studio installs: one at the merge base Images -> Train -> Model family
7 options -> 8. Picking itBase model resolves to Numbers, read off the same servers that were photographed
One correction to something I said earlier while reading this branch: I had it that the feature was unreachable from the Train tab. That came from the description's "Deliberately left out / The Train UI listing" paragraph, which describes an earlier commit. The net diff between the merge base and the merged head does wire the video registry into |


Adds LTX-2 as the first video family of the flow-matching DiT LoRA trainer.
It is a seventh
_FamilySpecplus routing, not a new trainer: the flow-matching loop, the latent posterior cache, the phased load and the adapter export are all shared with the image families.Milestone: still images
A 1-frame clip is a valid LTX-2 input (its VAE compresses time by 8, so
(1 - 1) // 8 + 1 = 1latent frame), and style and character LoRAs converge on 20 to 50 stills. So this reusesdiscover_image_caption_pairsverbatim and nothing decodes a video. Clip datasets, and therefore motion LoRAs, are a follow-up.What a video family needed beyond the image path
Audio. Every LTX-2 block carries a second audio stream (
audio_attn1/audio_attn2/audio_ff) plus two cross-modality attentions, andLTX2VideoTransformer3DModel.forwardtakesaudio_hidden_statesandaudio_encoder_hidden_statesas required arguments. Lightricks' own trainer handles a video-only run by passingaudio=None, which their transformer short-circuits so those branches never execute. diffusers has no such escape hatch, so the equivalent here is:(1 - sigma) * 0 + sigma * noise, so it sits at the right scale for every timestep rather than being unit noise at a timestep the model expects nearly-clean latents at),isolate_modalities=True, which turns off the a2v/v2a cross attention for every block so the placeholder cannot reach the video prediction,For a still the audio stream is one token, so the wasted compute is negligible. This is a deliberate divergence from upstream and is commented as such.
LoRA targets are fully qualified (
attn1.*/attn2.*). The shared bare suffixes would also matchaudio_attn1,audio_attn2,audio_to_video_attnandvideo_to_audio_attnunder PEFT's suffix rule, which is the mistake Lightricks warn about in their configuration docs. This matches the target set they ship for their own video-only LoRA configs.Two-stage conditioning. Gemma3-12B emits
[batch, 1024, 3840 * layers]hidden states (~370 MB per caption in bf16); a smallconnectorsmodule reduces them to the[batch, 1024, 3840]the transformer consumes. Only the connector output is cached, and_free_text_encodersnow also dropsconnectors,audio_vaeandvocoder.Unscaled timestep. LTX-2's config carries
timestep_scale_multiplier = 1000and its pipeline feeds the scheduler timestep through as-is, unlike the image families'timestep / 1000.flow_shiftdefaults toauto. LTX-2's scheduler setsuse_dynamic_shifting, so its static shift is skipped at init andscheduler.sigmasis the unshifted uniform table; its inferencemuis a constant (it evaluatescalculate_shiftatmax_image_seq_len, givingmax_shift = 2.05at every resolution), which is exactly the case the existingautobranch already reproduces for Qwen-Image.Routing: an explicit refusal instead of a silent misroute
Video bases live in a separate registry (
video_families) thatresolve_trainable_familynever consulted, so until now every video checkpoint fell through the unknown-name fallback and was handed to the SDXL trainer, failing later insidefrom_pretrained. Video families are now resolved explicitly, on both the detection and the explicit-model_familypaths, and one without a spec is refused by name:Also adds the family defaults from the upstream LoRA configs (rank/alpha 32, lr 1e-4, 512px), a VRAM row,
Lightricks/LTX-2on the training trust allowlist, and a resolution-must-be-a-multiple-of-32 gate (the VAE's spatial compression), checked before the resident GPU models are evicted.Verification
Trained a style LoRA on 23 stills (the public
linoyts/3d_iconset) at 512px, rank 32, lr 1e-4, 400 steps, nf4 QLoRA. Avg loss 0.523 to 0.489.Rendered the same prompts and seeds with and without the adapter, at LoRA scale 1.0 and 1.5, in a stock diffusers
LTX2Pipelinewith no Studio code on the path, viapipe.load_lora_weights(dir). The emittedpytorch_lora_weights.safetensorsloads unmodified, which is the compatibility claim.The difference is style, not noise. At scale 1.0 the photographic starfield / black-studio backgrounds are replaced by the dataset's dark studio backdrop with a soft floor reflection and the subject becomes a glossy simplified 3D render, while staying prompt-faithful and coherent. At 1.5 the effect saturates into the dataset's rounded-square app-icon form language and starts to lose the subject, which is ordinary LoRA scale behaviour. An untriggered prompt ("a cat sitting on a wooden table") also shifts from photographic to a clean CG render, i.e. normal style bleed for a style LoRA trained without a rare trigger token.
Peak VRAM, B200, nf4 / rank 32 / 512px / batch 1 / gradient checkpointing:
The run peak is set by the Gemma3-12B conditioning stage, not by the loop; the encoder is freed before the transformer loads. Lightricks publish 80 GB recommended and 32 GB with their int8 low-VRAM config for their own trainer, so the QLoRA path lands at about their low-VRAM figure and the loop itself is far below it.
Tests
New
tests/test_diffusion_dit_trainer_ltx2.py(85 tests), CPU-only and free of a diffusers import: the two places that need the pipeline's patchifier are isolated behind_ltx2_pack/_ltx2_unpackso the forward contract is checkable against a fake transformer.Every new assertion was mutation-tested: break the thing it guards, confirm a test fails, restore. 31 mutations, 31 caught, including the bare-suffix audio leak,
isolate_modalitiesleft off, the timestep divided by 1000, unit-noise audio, a swapped video/audio caption stream, a dropped temporal axis on the VAE encode, an unscaled posterior std, connectors left resident, the video registry lookup removed on either routing path, and the/32resolution gate removed or over-applied.studio/backend/tests/andstudio/backend/hub/tests/diffed against a pristineorigin/mainbaseline in a separate worktree: identical failure set (the local shared venv has a huggingface-hub version skew that produces a pre-existing failure set on both sides), 18946 vs 18861 passed, 304 hub tests pass on both.Deliberately left out
family_train_infos()is built from the image family registry, so LTX-2 is reachable through the API and themodel_familyoverride but does not yet appear in the Train picker. Wiring the video registry into that payload is a UI change and belongs in its own PR.ModularPipelinerather than aDiffusionPipeline, it denoises packed video and audio jointly, its text encoder is 63 GB, and its modulation is a rank-8 lookup table soadaln_projis not a sensible adapter site.autoshift, which reproduces LTX-2's own inference sigma distribution. Noted rather than ported.fps = 1.0; this trains them at the family's native 24 fps, so a still lands at the temporal RoPE coordinate of the first latent frame of a generated clip. Commented at_LTX2_TRAIN_FPS.