Last Latent From Batch
The last N latents, 4D or 5D, without the index math
- samples
- LATENT
Nifty Last Latent From Batch is the "just give me the end" shortcut for latent batches - the same relationship to Nifty Latent From Batch that Last Image From Batch has to Image From Batch. One input decides how many latents from the tail you want; everything else is handled.
- samples - the latent batch to slice.
- length - how many latents to take from the end (1–4096, default 1).
Output: LATENT - the last length frames, as a fresh latent dict.
The part that matters: it knows video latents
Image batches are 4D and video latents are 5D, with the frame axis living in different places. If you sliced a 5D video latent with a naive 4D tail-slice, you'd get the wrong dimension entirely. This node checks the tensor rank and slices the correct axis - for a 5D latent it truncates along the time axis ([:, :, -length:]), for a 4D latent along the batch axis. You don't think about it; it just works. For WAN, LTX, or any video model, that's the difference between "the last N frames" and a confusing error.
Typical uses
- Final-frame latent. Save or inspect the very last latent of a video generation.
- Loop tails. Take the last few latents to feed a continuation or a seamless-loop pass.
- Cleanup. Trim an over-generated clip to its meaningful end before decode.
The author's whole batch utility set follows this pattern - a full slicer for precision, a one-input tail shortcut for the common case - and the tail nodes are worth having for the rank handling alone. If you only ever need the end of the batch, this is the node; if you need to start anywhere else, use the full slicer.
Install
Nifty Nodes, standard: ComfyUI Manager → search "Nifty Nodes", or
cd ComfyUI/custom_nodes
git clone https://github.com/Stibo/comfyui-nifty-nodes
Restart ComfyUI, keep ComfyUI current (v3 API). No extra dependencies.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| samples | LATENT | Input latent batch to take the last frames from. | |
| length | INT | 11–4096 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| LATENT | LATENT | — |