Insert Latent To Index(InsertLatentToIndex)
This node accepts two inputs of type LATENT and supports both 4D (B, C, H, W) and 5D (B, C, T, H, W) tensor formats.
Insert Latent To Index
The Insert Latent To Index node receives two inputs of type LATENT and supports both 4D (B, C, H, W) and 5D (B, C, T, H, W) tensor formats.
The Insert Latent To Index node is used to insert a batch of latent representations into a specified position within another latent batch. Its core function is to replace the latent sample at a specific index in the target batch, enabling precise editing and composition within the latent space.
Node Functionality
This node receives two inputs of type LATENT and supports both 4D (B, C, H, W) and 5D (B, C, T, H, W) tensor formats. Internally, it uses PyTorch's torch.cat function to concatenate the source tensor before the specified index of the destination tensor, skipping the original data at that index in the destination tensor, and finally outputs a new combined latent tensor.
Node Parameter Description - Insert Latent To Index
Connection Inputs (Inputs)
| Parameter Name | Data Type | Required | Default Value | Range/Options | Description |
|---|---|---|---|---|---|
source | LATENT | Yes | - | - | source (input parameter): Provides the source latent representation batch to be inserted. |
destination | LATENT | Yes | - | - | destination (input parameter): Provides the target latent representation batch to be modified. |
Control Parameters (Parameters)
| Parameter Name | Data Type | Required | Default Value | Range/Options | Description |
|---|---|---|---|---|---|
index | INT | Yes | 0 | -1 - 4096 (step: 1) | index (input parameter): Specifies the insertion position for the source latent representation within the target batch. The valid range is from -1 to 4096. |
Output
| Parameter Name | Data Type | Description |
|---|---|---|
| LATENT | LATENT | LATENT (output parameter): Outputs the newly merged latent representation batch. |
Usage Scenarios
In an image generation workflow, this node can be used to replace the latent representation of a specific image within a batch generation. For example, after generating a set of portrait images, if you want to replace the facial features of the third image with a more satisfactory one, you can use the new facial latent representation as source, the original batch as destination, and set index to 2 to complete the replacement.
Notes
When using this node, note that the specified index value must be within the valid range of the target latent batch; otherwise, the node will report an error. For 4D tensors, the index corresponds to the batch dimension (B); for 5D tensors, the index corresponds to the time dimension (T).
Insert Latent To Index Node Source Code Link
The Insert Latent To Index node is from the ComfyUI-KJNodes node package.
Comments
Sign in with GitHub to join the discussion.