Skip to content

Studio: LTX-2 video LoRA training from still images - #8196

Merged
danielhanchen merged 16 commits into
mainfrom
ltx2-video-lora
Aug 9, 2026
Merged

danielhanchen merged 16 commits into
mainfrom
ltx2-video-lora

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

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 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 = 1 latent frame), and style and character LoRAs converge on 20 to 50 stills. So this reuses discover_image_caption_pairs verbatim 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, and LTX2VideoTransformer3DModel.forward takes audio_hidden_states and audio_encoder_hidden_states as required arguments. Lightricks' own trainer handles a video-only run by passing audio=None, which their transformer short-circuits so those branches never execute. diffusers has no such escape hatch, so the equivalent here is:

  • a minimal placeholder audio stream at the step's own sigma ((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,
  • audio excluded from the loss, and audio modules excluded from the LoRA targets.

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 match audio_attn1, audio_attn2, audio_to_video_attn and video_to_audio_attn under 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 small connectors module reduces them to the [batch, 1024, 3840] the transformer consumes. Only the connector output is cached, and _free_text_encoders now also drops connectors, audio_vae and vocoder.

Unscaled timestep. LTX-2's config carries timestep_scale_multiplier = 1000 and its pipeline feeds the scheduler timestep through as-is, unlike the image families' timestep / 1000.

flow_shift defaults to auto. LTX-2's scheduler sets use_dynamic_shifting, so its static shift is skipped at init and scheduler.sigmas is the unshifted uniform table; its inference mu is a constant (it evaluates calculate_shift at max_image_seq_len, giving max_shift = 2.05 at every resolution), which is exactly the case the existing auto branch already reproduces for Qwen-Image.

Routing: an explicit refusal instead of a silent misroute

Video bases live in a separate registry (video_families) that resolve_trainable_family never consulted, so until now every video checkpoint fell through the unknown-name fallback and was handed to the SDXL trainer, failing later inside from_pretrained. Video families are now resolved explicitly, on both the detection and the explicit-model_family paths, and one without a spec is refused by name:

'wan2.2-ti2v-5b' is a video model Studio can't train yet. Video LoRA
training currently supports: ltx-2. ...

Also adds the family defaults from the upstream LoRA configs (rank/alpha 32, lr 1e-4, 512px), a VRAM row, Lightricks/LTX-2 on 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_icon set) 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 LTX2Pipeline with no Studio code on the path, via pipe.load_lora_weights(dir). The emitted pytorch_lora_weights.safetensors loads 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:

phase peak
training loop only 11.2 GB
whole run 34.8 GB

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_unpack so 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_modalities left 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 /32 resolution gate removed or over-applied.

studio/backend/tests/ and studio/backend/hub/tests/ diffed against a pristine origin/main baseline 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

  • Clip datasets / motion LoRAs. Milestone two.
  • The Train UI listing. family_train_infos() is built from the image family registry, so LTX-2 is reachable through the API and the model_family override 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.
  • MiniMax-H3. It is a ModularPipeline rather than a DiffusionPipeline, it denoises packed video and audio jointly, its text encoder is 63 GB, and its modulation is a rank-8 lookup table so adaln_proj is not a sensible adapter site.
  • Upstream's token-count-dependent sigma shift. Lightricks shift the logit-normal mean by a value linear in sequence length; this uses Studio's existing auto shift, which reproduces LTX-2's own inference sigma distribution. Noted rather than ported.
  • fps for stills. Lightricks pin images to 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.

danielhanchen and others added 3 commits August 8, 2026 17:47
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.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen and others added 3 commits August 9, 2026 07:06
… 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.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen and others added 4 commits August 9, 2026 12:03
# 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.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

…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.
@danielhanchen

Copy link
Copy Markdown
Member Author

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 80c3f17c7, /api/train/diffusion/info returns the same 7 families as the merge base:

flux.1  flux.2-klein  flux.2-dev  qwen-image  z-image  krea-2  sdxl

Verified against two installed Studios, one per side, not just by reading the source. The cause is one call: family_train_infos() iterates trainable_family_names(), the image registry, at diffusion_train_common.py:659. The new _all_trainable_family_names() (image + TRAINABLE_VIDEO_FAMILIES) is used in exactly one place, the error message at line 199. The frontend cannot make up the difference either: FAMILY_PRESETS in diffusion-train-panel.tsx is documented as a fallback for an older backend whose /info reports none, and it has no video entry.

So the trainer works and is reachable by POSTing /api/train/diffusion/start with an LTX-2 base, but a user cannot select it. The visible surfaces this PR does change, the completion line and the Deploy to Create gate, both sit after a finished run, so they are unreachable through the UI for the same reason.

Two things worth deciding before this merges:

  1. whether family_train_infos() should iterate _all_trainable_family_names() so the video families appear, which needs detect_family to resolve a video name or a video branch that reads video_families
  2. what the Train tab should offer as the base repo for ltx-2, since video families carry no train_base_repos

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
@danielhanchen

Copy link
Copy Markdown
Member Author

Resolved the reachability gap I flagged above, in e4045f7.

family_train_infos() (which builds /api/train/diffusion/info, and so the Train tab's family list) iterated trainable_family_names(), the image registry alone, and skipped any name detect_family could not resolve. LTX-2 lives in the separate video registry, so it was dropped there and never offered, even though the trainer, the config validation and /diffusion/start all accepted it.

It now iterates the union (_all_trainable_family_names()) and resolves each name through a new _trainable_family_spec() that tries both registries. A video family carries no train_base_repos and no deploy_base_repo, so its own base_repo (Lightricks/LTX-2) is the single training base and deploy_base stays null, which is what the panel already keys the Deploy to Create button off. Everything else the payload needs was already in place for ltx-2: label, defaults, the VRAM/params chips, and membership of the DiT precision set.

Two related things fell out of re-checking the rest of the families:

  • training_pipeline_import_error() resolved the family name through the image registry only, so it returned None for a video family and the strict half of the pipeline gate was skipped for LTX-2. That is the one that matters: the refusal would have landed in the spawned child, after the resident GPU models were freed. It now goes through the same both-registries lookup.
  • family_train_infos() now drops any family whose pipeline class the installed diffusers does not carry, matching what the image picker already does. Advertising one is offering a pick that can only 400 at start, and no choice in the UI fixes it.
  • The duplicate _assert_video_pipeline_available this branch added is gone; main's _assert_family_pipeline_available is family-agnostic by design, so the video path uses it.

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.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 9, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 9, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 9, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 9, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 9, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 9, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 9, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 9, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 9, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 18dc63502d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@danielhanchen
danielhanchen merged commit f02e49f into main Aug 9, 2026
42 of 47 checks passed
@danielhanchen
danielhanchen deleted the ltx2-video-lora branch August 9, 2026 15:50
@danielhanchen

Copy link
Copy Markdown
Member Author

Before/after screenshots of what this lands on screen, taken from two isolated Studio installs: one at the merge base f9656fd6c, one at the merged head 18dc63502. Same machine, same scene driven against both, diffusers 0.39.0 with LTX2Pipeline present on both sides (so the family_pipeline_available filter is not what produces the difference).

Images -> Train -> Model family

family_train_infos() used to walk trainable_family_names(), the image registry alone, so the video registry could not reach the Train picker however complete the trainer was. It now walks _all_trainable_family_names(), the image registry's trainable families union TRAINABLE_VIDEO_FAMILIES, and the row appears.

Model family menu, before and after

7 options -> 8. LTX-2 is appended last, which is what mergeFamilies does with a backend family the frontend has no preset for.

Picking it

Train panel after picking LTX-2, before and after

Base model resolves to Lightricks/LTX-2, the chips read 19B and QLoRA 36GB+ VRAM, and the note is Video: trains a style LoRA on still images.

Numbers, read off the same servers that were photographed

GET /api/train/diffusion/info:

merge base merged head
families 7 8
names flux.1, flux.2-klein, flux.2-dev, qwen-image, z-image, krea-2, sdxl the same 7, plus ltx-2
ltx-2 entry absent label LTX-2, base_repos [Lightricks/LTX-2], params 19B, qlora_vram_gb 36
ltx-2 defaults n/a rank 32, lr 1e-4, resolution 512, warmup 20
ltx-2 deploy_base n/a null

deploy_base being null is the same decision as the panel change in this diff: a video run publishes no entry into loras/diffusion, so the completion panel drops "Deploy to Create" and reports the saved path instead of claiming the LoRA picker got it.

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 family_train_infos(), and the pair above is the picker at both ends. The description is the stale part, not the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant