Skip to content

Studio diffusion training: LTX-2.5 LoRA training (captions through the Gemma 4 worker, dev DiT, baked into the distilled Video page model) - #18386

Merged
danielhanchen merged 13 commits into
mainfrom
studio-ltx25-lora-training
Nov 19, 2026
Merged

danielhanchen merged 13 commits into
mainfrom
studio-ltx25-lora-training

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

Studio runs LTX-2.5 on the Video page, but its diffusion trainer refused it. The family was never marked trainable, get_trainer and _DIT_TRAIN_FAMILIES only knew ltx-2, and a local LTX-2.5 folder was explicitly refused.

This PR adds LTX-2.5 LoRA training using the same still-image style flow as LTX-2. A trained LoRA loads back on the Video page.

Design

  • Caption encoding. The Gemma 4 12B encoder needs transformers >= 5.10.1, while Studio pins 5.5.4, so the Video page already runs it in a separate worker with its own transformers. The trainer process has already imported 5.5.4, so the encoder cannot load in-process.
    • Captions are encoded once, before the DiT loads, through that same worker, at the Video page's default encoder precision.
    • The worker is then stopped, which frees its GPU and host memory.
    • Studio's conditioning cache is reused; on a warm cache the worker never starts.
  • Downloads. Conditioning fetches only the small components and one copy of the connectors. It skips both DiTs, the dense encoder (the worker reads it) and the prompt enhancer.
  • Which DiT. The LoRA trains on the dev DiT (transformer_full/), since the model card says "The dev transformer is fully trainable". The Video page bakes it into the distilled DiT it renders with, as Studio already does for Krea and FLUX.2 Klein. The dev scheduler gives exactly LTX-2's sigma table.
    • When the fetch comes from the unsloth/LTX-2.5-FP8 mirror, which has no dev DiT, the dev DiT is read from Lightricks/LTX-2.5-Diffusers if the token can access it. Otherwise training falls back to the distilled DiT with a warning.
    • UNSLOTH_LTX25_TRAIN_DIT=distilled trains the distilled DiT on purpose.
  • Base precision. The default is the same nf4 4-bit path ltx-2 uses. The hosted INT8-ConvRot / FP8 files are distilled-only and are not training bases; GGUF was already refused.
  • Routing.
    • A local LTX folder is routed by its model_index.json.
    • Training a local 2.5 folder as ltx-2, or a 2.0 folder as ltx-2.5, is still refused.
    • The single-file Lightricks/LTX-2.5 release is refused with a pointer to the Diffusers pack.

Results

LTX-2.5, A100-80 on Colab: nf4 base, 512 px, rank 32, lr 2e-4, 300 steps, seed 0, 16 style stills.

steps 1-50 51-100 101-150 151-200 201-250 251-300
mean loss 1.389 1.248 1.101 0.999 0.996 1.066
  • GPU memory: the trainer process peaks at 10.9 GiB and the training loop at 11.7 GB. The encoder worker used 12.4 GiB on the card and was stopped before the DiT loaded; the whole-card peak was 22.9 GB.
  • Host RAM: 20.5 GB process-tree peak.
  • Speed: 1.07 samples/s.

Video page renders through Studio's VideoBackend, distilled two-stage defaults, 768x512, 25 frames, seed 7:

prompt LoRA strength LPIPS vs no LoRA
cat on a sofa 0 (second load) 0, bit-identical
cat on a sofa 0.5 / 1.0 0.608 / 0.741
mountain sunset 0 (second load) 0, bit-identical
mountain sunset 0.5 / 1.0 0.449 / 0.772

The effect grows with strength, and the backend status shows the LoRA baked at the requested weight.

LTX-2 regression, same VM, interleaved base / head / base / head / base, 40 steps:

  • mean loss: base 1.3501 / 1.3541 / 1.3470; head 1.3514 / 1.3490;
  • the two head runs fall inside the base-vs-base per-step spread;
  • VRAM peaks are the same.

Tests

  • studio/backend/tests/test_diffusion_dit_trainer_ltx25.py has 25 tests. They fail at import on main and pass here.
    • They include a tiny CPU end-to-end run: train on the dev DiT with the real encoder worker process, then publish and bake the LoRA into the distilled DiT through the real VideoBackend. The output difference grows with strength.
  • Two existing tests changed on purpose: the old "training refuses LTX-2.5" contract became a routing test.
  • The related diffusion and video suites (58 files) pass: 3070 passed, 0 failed.

Not covered

Train LTX-2.5 (Lightricks/LTX-2.5-Diffusers) style LoRAs from still images on the DiT
trainer. Captions go through the Video page's Gemma 4 encoder worker (the encoder needs
the transformers 5.10 sidecar), once, before the DiT loads; the worker exits with its
memory. The LoRA trains against the pack's dev DiT (transformer_full/, the model card's
trainable model) on LTX-2's sigma schedule and bakes into the distilled DiT on the Video
page. UNSLOTH_LTX25_TRAIN_DIT=distilled trains the distilled DiT instead.
…n the fetch is the mirror

The ungated unsloth/LTX-2.5-FP8 mirror ships only the distilled DiT; the dev DiT then comes
from Lightricks/LTX-2.5-Diffusers when the token can read it, else the run trains the
distilled DiT. Also stage model_index.json when the Hub listing arrives as a generator.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T07:58:38.259488Z 72e2058 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4a2e468778

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

Comment on lines +2054 to +2057
_LTX25_DIT_SOURCES[key] = (
(repo, _LTX25_DEV_SUBFOLDER) if repo else (base, _LTX25_DISTILLED_SUBFOLDER)
)
return _LTX25_DIT_SOURCES[key]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Record the resolved DiT source in checkpoint identity

When resuming an LTX-2.5 run after changing UNSLOTH_LTX25_TRAIN_DIT, or after upstream access changes which fallback is selected, this resolver can choose different frozen weights and a different scheduler without invalidating the checkpoint. identity_for_config() and the later with_resolved_revision(identity, fetch_cfg.base_model) record only the configured fetch repository, not the resolved DiT repository/subfolder. Because dev and distilled adapters have matching shapes, restoration can silently apply the previous adapter and optimizer moments to a different base, corrupting the resumed experiment. Persist and compare the resolved DiT repository, revision, and subfolder before restoring training state.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 59e7975: the identity records the resolved DiT repo, subfolder and revision, and a mismatched resume is refused.

The trainer picks the dev or distilled DiT, from the upstream pack or the mirror, at load
time. Both have the adapter's shapes, so a resume after UNSLOTH_LTX25_TRAIN_DIT or token
access changed silently continued the old adapter and moments on another base. The
identity now records the resolved repo:subfolder and its revision and refuses a mismatch;
a bundle without the field resumes only onto the default dev DiT of its base.

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 59e797509a

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

The conditioning cache keyed captions on family, base and revision only, so after the
Gemma 4 encoder switched between int8 and bf16 (UNSLOTH_LTX25_TE_INT8, or the hosted int8
file becoming unavailable) a warm cache served captions from the other encoder. Text keys
now carry the resolved precision and source (hosted int8 file with its revision, int8
quantized at load, or bf16); families without a per-run encoder choice keep their keys.
…users is absent

The diffusion CI shard runs without diffusers; the subfolder and scheduler tests imported
it unguarded. They now skip with the repo's 'diffusers is not importable here' message, as
the tiny-pack fixture does.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@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: 4d37e9b216

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

The LTX saver dropped transformer_lora_adapter_metadata, so diffusers reloaded
an adapter trained with lora_alpha != rank at alpha == rank.
…Gemma 4 fits

The trainer started the worker resident on every GPU, which loads the whole
encoder on the card beside the 6.34 GB connectors and skips the worker's
layer-streamed and CPU fallbacks. It is now resident only when the free memory
covers the encoder weights, the encode margin and the worker context.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

The cache namespace read the base revision before load_conditioners fetched
it, so a first run on a fresh Hub cache wrote under "unresolved" and the next
run, which resolves the commit, missed every entry. The namespace is read
again after the encode; on a change the captions are copied over and the
latents are written under the resolved namespace.

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 72e2058b09

ℹ️ 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 75bea11 into main Nov 19, 2026
@danielhanchen
danielhanchen deleted the studio-ltx25-lora-training branch November 19, 2026 12:50
danielhanchen added a commit that referenced this pull request Nov 19, 2026
)

## Summary

`(Python 3.13, diffusion)` fails on `main` for every PR (seen on #18477,
which only touches Hub frontend hooks):

```
FAILED tests/test_diffusion_windows_rocm_wide_head.py::test_dit_trainer_guards_the_preview_vae_a_warm_cache_loads[False]
core/training/diffusion_dit_trainer.py:3050: in _rekey_conditioning_cache
    if (fresh.family, getattr(fresh, "text_encoder", "")) == (
E   AttributeError: 'object' object has no attribute 'family'
```

Reproduced locally on `main` at `3ee3907c23`.

## Root cause

#18386 added `_rekey_conditioning_cache`, which reopens the persistent
conditioning cache once the conditioners are on disk and compares its
namespace (`family`, `text_encoder`) with the one the run opened. That
is correct for the real `PersistentConditioningCache`, which always sets
both attributes in `__init__`.

The test replaced `PersistentConditioningCache` with `lambda *_a:
object()`, a bare object with none of the cache's attributes. It only
worked while the cold path never read one. So the trainer change is fine
and the stub was too thin.

## Changes

- `test_diffusion_windows_rocm_wide_head.py` and
`test_diffusion_training_download_phases.py` no longer stub
`PersistentConditioningCache`. Both already point `cond_cache_dir` at
`tmp_path`, and the real constructor only creates that directory, so the
tests now run against the real cache and keep working when the trainer
reads another of its attributes. The encode and warm-load steps around
it stay stubbed as before, so nothing is encoded or downloaded.

No source change.

## Testing

- `pytest tests/test_diffusion_windows_rocm_wide_head.py
tests/test_diffusion_training_download_phases.py` (from
`studio/backend`): 19 passed; on `main` the `[False]` case fails as
above.
- The existing `tests/test_diffusion_cond_cache_rekey.py` covers
`_rekey_conditioning_cache` itself and is unchanged.
danielhanchen added a commit that referenced this pull request Nov 20, 2026
## Problem

A diffusion LoRA trained with a `lora_alpha` other than its rank reloads
at the wrong strength. diffusers' `save_lora_weights` only writes the
adapter config (rank, alpha) into the safetensors header when it is
passed `*_lora_adapter_metadata`; without it the loader assumes
`lora_alpha == rank`. Qwen-Image-2.1, FLUX.3, MOSS, Wan and (since
#18386) LTX-2.5 already pass it. FLUX.1, Qwen-Image, Z-Image, Krea 2,
FLUX.2-dev, FLUX.2-klein and the SDXL UNet trainer still saved without
it, and LTX-2 had its own inline copy of the logic.

`lora_alpha` defaults to the rank, so a default run is unaffected. A run
that sets `lora_alpha` (the training API accepts it) saves a file that
loads scaled by `rank / alpha` instead of `alpha / rank`.

## Change

- One helper, `_save_transformer_lora`, passes the trained adapter's
`LoraConfig` as `transformer_lora_adapter_metadata` when this diffusers'
`save_lora_weights` takes it (older diffusers keep the old call).
- Those families now set `save_takes_metadata = True` and save through
the helper; LTX-2's inline copy from #18386 is replaced by it.
- The SDXL trainer passes `unet_lora_adapter_metadata` the same way.

## Tests

`studio/backend/tests/test_diffusion_lora_alpha_metadata.py`: every DiT
family in `_SPECS` (skipped where the installed diffusers has no
pipeline for it) and SDXL save an r=4, alpha=8 adapter and the header
must read `lora_alpha` 8. On main 7 of these fail; here all pass.

The DiT trainer, conditioning cache and train suites: 410 passed (CPU).

---------

Co-authored-by: Nilay Yadav <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant