Latent-space chaining seams for chunked video continuation - #40
Merged
Conversation
TroyHernandez
added a commit
that referenced
this pull request
Jul 22, 2026
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.
Chained multi-chunk generation today round-trips every join through pixels: decode chunk N, H.264-encode it, re-read its tail frames, VAE re-encode them into conditioning latents for chunk N+1 — plus a full onload/offload cycle of every component per chunk. This PR adds the seams to keep a chain in latent space end to end and to hold components resident across back-to-back calls.
New surface
condition_latents=ontxt2vid_ltx2(): an already-encoded conditioning prefix[1, 128, k, H/32, W/32], bypassing the read/preprocess/VAE-encode block entirely. Mutually exclusive withimage/condition_video; geometry-validated.ltx23_tail_latents()(exported): slices the trailingklatent frames of a result intocondition_latentsform. Results now carrylatent_shapeto make that self-contained. The docs flag the semantics caveat: sliced continuation latents represent 8 pixel frames each, a fresh tail encode represents 1 + 8(k−1) with a first-frame-form leading latent — A/B on real content before trusting latent-only joins.resident=: component names to keep on the compute device after their phase. Onload is now idempotent (device check,tryCatch-guarded so anything odd falls back to the old path), offload and the dequant-buffer release skip resident components. A chunk loop pays one transformer onload per track instead of one per chunk.trim_frames=: drop leading pixel frames (the conditioning-head overlap) from the decoded video and the saved file, in memory — replacing a lossy subclip re-encode downstream. The returned latents keep the full sequence, since tail slicing needs it.Head trim stays in pixel space by design: the causal VAE decodes latent frame 1 to a single pixel frame and later frames to 8 each, so dropping leading latent frames before decode yields the wrong frame count (7 short) and pushes a continuation-form latent through the decoder's first-frame path.
Tests
Extends the tiny-pipeline CPU fixture:
condition_latentsreproduces thecondition_videopath bit-for-bit when fed the same encoded tail; tail slicing matches a manual unpack+narrow; a sliced tail feeds back end to end;trim_framesoutput equals the untrimmed video minus its head, with latents andlatent_shapeintact; guardrails for the three-way source exclusivity, bad geometry, bad trim, and unknown resident names. Full suite: 923 green (CPU).GPU validation still owed (deferred while the card is busy): resident-transformer chain timing, and the sliced-tail vs fresh-encoded-tail A/B on identity/lip-sync stability.