Skip to content

Preserve non-tensor conditioning options across save and load - #554

Open
しの (vallicgrr) wants to merge 2 commits into
Lightricks:masterfrom
vallicgrr:preserve-conditioning-options
Open

Preserve non-tensor conditioning options across save and load#554
しの (vallicgrr) wants to merge 2 commits into
Lightricks:masterfrom
vallicgrr:preserve-conditioning-options

Conversation

@vallicgrr

Copy link
Copy Markdown

LTXVSaveConditioning persists the conditioning tensor and attention_mask. Everything else in cond_options is discarded, and the loader has no way to bring it back.

This matters for LTX-2.5. Its text encoder sets unprocessed_ltxav_embeds in the options dict, and av_model.py reads that flag to decide whether to run the video and audio embeddings connectors. A cached conditioning arrives without it, so the connectors are skipped and the values reaching cross-attention carry no meaning. Shapes stay correct and nothing raises. The decoded video is flat noise.

That matches #443, where several people describe brown noise from cached conditioning that generates correctly when encoded live. NRTnarathip (@NRTnarathip) identified the same root cause in June and published a fix as a separate pair of LTX-2.3 nodes. This applies the same approach inside the existing nodes.

What changed

Non-tensor values are serialised to JSON and written into the safetensors metadata block, keyed as {idx}:{name}. Tensor options other than attention_mask go to option_{idx}_{key}. Values that will not serialise are skipped so the save still completes.

The loader reads the metadata block back and merges both kinds into the options dict.

Compatibility

Files written by the current saver carry no non_tensor_options entry. The loader falls back to an empty dict and reads attention_mask_{idx} from its existing key, so old caches keep working.

Testing

Round-tripped a conditioning carrying attention_mask, pooled_output and unprocessed_ltxav_embeds. All three come back, with the flag preserved as a boolean.

A file written without the metadata block loads with the mask intact.

Checked against LTX-2.5 in a running graph, where a cached conditioning now produces the same coherent output as a live encode.

LTXVSaveConditioning wrote only the conditioning tensor and attention_mask,
so every other entry in cond_options was dropped. LTX-2.5 sets
unprocessed_ltxav_embeds there, and without it the model skips the embeddings
connector stage.

Non-tensor values now go into the safetensors metadata block as JSON, keyed by
conditioning index. Tensor options other than attention_mask are stored as
option_{idx}_{key}. Files written before this change still load, with the mask
read from its existing key.

Fixes Lightricks#443
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