Clean Latent Slice (TJ 2.5)
The tiny node that stops PyTorch mangling your video latent
- latent
- latent
Clean Latent Slice (TJ 2.5) is a 20-line utility that does one thing: it cuts a video latent down to a start index and a length. No UI, no model, no settings worth a second glance. You reach for it because something upstream made your latent longer than the clip you actually asked for, and you need those spare frames gone before the VAE decodes them into a stretch of grey mush at the end of your shot.
Why a slice node exists at all
In a video graph the latent isn't a picture, it's a compressed stack of frames - the same latent-space trick the rest of ComfyUI runs on, just with a time axis bolted on. Latent-space models generate in that compressed stack and the VAE is what turns it back into pixels. When you lean on guide frames, reference images, retake mode or a rotated/hidden prefix, the nodes that insert those guides do it by extending the latent so the guide has somewhere to live. The math works, the sampler is happy, and then you decode and discover your five-second clip has an extra half-second of nonsense on the end.
Two ways to fix that. The obvious one is latent[:, :, start:start+length], which is also the one that periodically explodes on tensor subclasses - PyTorch's NestedTensor doesn't implement slicing well, and you get a traceback in the middle of a long render. This node's author went the other way: torch.narrow, which is what the C++ side of the tensor library actually implements, and which sidesteps the wrapper bugs. Mildly paranoid, entirely reasonable.
The three fields
- latent - the video latent to slice, whatever produced it.
- start - the frame index to slice from. The author's own tooltip tells you where it expects this to come from:
latent_start_index, i.e. an index another node already computed for you. - length - how many frames to keep. Same story: plug
clean_latent_frameshere. Those two names are the giveaway that this node is one half of a pair, and it's the receiving half.
One output, latent, and it's the same latent with noise_mask sliced to match. That last part matters more than it looks: if the mask still covers the old frame count, your denoise region no longer lines up with your samples and the sampler either complains or does something quietly wrong.
How it's actually wired
Wire it between whatever padded the latent and whatever reads it - usually out of the sampler or out of the guide stage, and in front of your VAEDecode. If you're running the LTX 2.5 Director chain, the pattern the code is built around is: the guide node pads the latent to make room for hidden reference/keyframe frames, the sampler runs, and then this node trims back to the clean length so what you decode is exactly the clip you intended. If a node in your graph hands you a latent_start_index and a clean_latent_frames, this is what those two numbers feed.
Install
It ships in the same package as everything else here, so there's nothing separate to install:
cd ComfyUI/custom_nodes
git clone https://github.com/designloves2/ComfyUI-TJ_NODE_STUDIO_ONE.git
Restart, then run the pack's dependency script once (bash install_requirements.sh on Mac/Linux, double-click install_requirements.bat on Windows) - the package's node packs don't come down with a Manager install. For the slice node itself the script is irrelevant; it needs nothing but torch.
Where people trip
The failure mode isn't an error, it's a shorter latent than you wanted. start and length are clamped to the tensor's real size instead of raising, so a wrong index gives you a one-frame latent or a silently truncated clip rather than a red box in the console. If your video is a few frames short, check these two numbers before you go hunting through the sampler.
Also note it only slices dimensions it recognises: 5D batches down the frame axis (dim 2), 4D and 3D down dim 0. Hand it something else and you get the latent back untouched, which looks identical to "the node did nothing" - because it did.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| latent | LATENT | — | |
| start | INT | 00–100000 | The starting frame index to slice from (plug 'latent_start_index' here). |
| length | INT | 11–100000 | The number of frames to keep (plug 'clean_latent_frames' here). |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| latent | LATENT | — |