[feat] Support training_cfg_rate > 0 for LTX-2 - #1752
Open
alanhuangyoo wants to merge 1 commit into
Open
alanhuangyoo wants to merge 1 commit into
alanhuangyoo wants to merge 1 commit into
Conversation
Contributor
Merge Protections🔴 1 of 1 protections blocking · waiting on 👀 reviews and 🤖 CI
🔴 PR merge requirementsWaiting for
This rule is failing.
|
alanhuangyoo
marked this pull request as ready for review
August 26, 2026 06:37
CFG dropout was rejected outright because the shared parquet path drops text conditioning by zeroing the stored embedding, which is not the unconditional input LTX-2 samples with. Do the drop inside LTX2Model.prepare_batch so dropped samples carry the empty prompt encoded through Gemma and the Embeddings1D connector. LTX2GemmaTextEncoderModel owns the connector, so encode_negative_prompt already returns the post-connector tensor. Gemma is only loaded when training_cfg_rate > 0.
alanhuangyoo
force-pushed
the
feat/ltx2-cfg-training
branch
from
August 26, 2026 08:12
6651cc2 to
6236e29
Compare
Contributor
Author
|
@SolitaryThinker Thanks for merging #1791! Could you also take a look at this one and #1751 when you get a chance? |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Draft — the implementation and unit tests are in place, but I have one semantics question for you before this is ready, and I have not run a convergence check yet. Details at the bottom.
Problem
LTX2Model.__init__rejects CFG dropout outright:That is accurate. The drop happens in the data layer, in
get_torch_tensors_from_row_dict:Zeros are not what the LTX-2 sampler feeds its unconditional branch, so training that way teaches an unconditional the sampler never uses.
Approach
Do the drop in
LTX2Model.prepare_batchinstead, substituting the cached unconditional embedding.ensure_negative_conditioning()encodes the unconditional prompt via the sharedencode_negative_prompthelper.LTX2GemmaTextEncoderModelownsEmbeddings1DConnector, so what comes back is already the post-connector tensor — no separate connector pass is needed._apply_cfg_dropout()picks samples withtorch.rand(..., generator=generator)and swaps in that embedding and its mask. It is a no-op whentraining_cfg_rate == 0, and it clones rather than mutating the batch in place.set_requires_negative_conditioning(cfg_rate > 0.0)keeps the existing "don't pay 23GB of Gemma per rank for an unused embedding" property — nothing is loaded unless CFG dropout is on.ltx2_training_pipeline.pypassescfg_rate=0.0to the parquet loader so the drop happens once, in the model. This also gives the precomputed.ptpath CFG dropout, which it never had (ltx2_precomputed_dataset.pyhas nocfg_rate).Question before this leaves draft
What should the unconditional prompt be? I used
"", following the wording in theNotImplementedError, exposed asLTX2_UNCONDITIONAL_PROMPT.But the presets disagree with each other —
ltx2_baseandltx2_distilledsetnegative_promptto_LTX2_NEGATIVE_PROMPT, whileltx2_two_stageandltx2_3_baseset it to"". So "the unconditional LTX-2 samples with" is not one fixed string. Options as I see them:""(what this PR does).SamplingParam.from_pretrained(model_path).negative_prompt, the wayWanModel.ensure_negative_conditioningdoes — then training matches whichever preset the checkpoint ships.I did not want to guess, since option 2 changes what gets trained depending on the checkpoint.
Verified
New unit tests in
fastvideo/tests/train/models/test_ltx2_cfg_dropout.py(3 passed) cover the rate-0 no-op, that dropped samples carry the unconditional embedding and specifically not zeros, and that the caller's tensors are not mutated. They construct the model shell directly, so nothing large is loaded.pre-commit run --files ...is clean on all three files (yapf, ruff, codespell, mypy).pytest fastvideo/tests/train/ -k ltx2gives the same 4 failures with and without this patch —test_ltx2_finetune_single_train_step[ltx2|ltx2_3]andtest_ltx2_model_loads_and_forwards[ltx2|ltx2_3], allCould not find model at FastVideo/LTX-2.3-Distilled-Diffusers and failed to download from HF Hub. Pre-existing, environment-side.Not verified
No convergence run. I can put a short LoRA finetune with
training_cfg_rate=0.1againstcfg_rate=0on H20 once the prompt question above is settled, so the run measures the intended behaviour.Env: torch 2.12.0+cu130, H20, single node.