Nodes/ComfyUI-LTX-Attention-Toolkit/LTX Attn — Query Map
ComfyUI Node

LTX Attn — Query Map

Flip the lens and see who's doing the looking

By g-raw·Created 3 months ago·Updated 2 months ago· 2
LTX Attn — Query Map
    • query_map
    store_handle
    attn_typesa
    block_idx0
    step_idx-1
    head_indicesall
    num_frames1
    latent_height32
    latent_width32
    key_token_idx-1
    aggregate_framesmean
    colormapinferno
    normalize_per_headtrue
    cell_size96

    Key Map answers "what is this head looking at?" Query Map answers the mirror question: "which tokens are actively doing the looking?" The pack itself frames it as "who is actively looking" - and unlike the Key Map, this one works for both self-attention and cross-attention, which is where it gets genuinely interesting.

    Cross-attention is video→text: each video token queries against the text tokens from your prompt. So the Query Map in ca mode shows you which video regions are attending to the prompt's tokens - the classic way to see prompt adherence as a spatial pattern. In sa mode it's the self-attention mirror of the Key Map, showing which regions of the frame are emitting the attention.

    How it works

    Where Key Map collapses the query dimension (W.mean(dim=1)), this collapses the key dimension (W.mean(dim=2)), giving you a [Sq] vector of "total attention emitted by each query token," reshaped to [frames, latent_h, latent_w]. One rendered tile per head, same layout as the Key Map.

    The knob that unlocks the good stuff is key_token_idx. Set it to -1 (default) and you average over all keys - the whole picture. Set it to a specific text token index in ca mode and you isolate which video regions are attending to that one token. That's how you ask "where in the frame is the model looking at the word 'sword'?" - a genuinely useful diagnostic when a prompt isn't landing where you expect.

    The inputs that matter

    • attn_type - sa or ca. This is the decision that changes what the map means.
    • block_idx, head_indices, step_idx - same as Key Map: which block, which heads, which denoising step (-1 = last captured).
    • key_token_idx - the text-token isolator described above.
    • aggregate_frames - mean / max / first for collapsing frames.
    • num_frames, latent_height, latent_width - same geometry requirement as Key Map; these must exactly match the capture or you get a shape error. LTX Latent Dims exists to feed these.
    • normalize_per_head, cell_size, colormap - rendering details; defaults are fine.

    Output is a single query_map IMAGE.

    Same prerequisites as its sibling: the block must have been captured with store_mode=full_fp16 (or hybrid + full_blocks) so a dense multi-head map exists. A reduced capture won't have one, and a block stored via full_targets (sparse per-head dict) raises - single-head consumers like Head Freeze don't care, but this node needs every head.

    Install

    cd ComfyUI/custom_nodes
    git clone https://github.com/g-raw/ComfyUI-LTX-Attention-Toolkit.git
    

    Restart ComfyUI. No extra dependencies, no model downloads - same story as the rest of the pack. And the same WIP caveat: store formats can break between versions.

    Common issues

    Mostly the same three as Key Map: geometry mismatch (feed the right num_frames/latent dims), no dense map because you captured in reduced mode, and forgetting that the store only exists after the capture run finishes - queue this node as a separate later run with the handle typed in. One more: in ca mode, don't set key_token_idx past the number of text tokens in your prompt - it clamps to the last key, so you'll silently be looking at a different token than you think.

    Categoryg_raw/LTX/Profiler

    Inputs (13)

    NameTypeDefaultDescription
    store_handleSTRING
    attn_typeCOMBOsa2 options: sa, ca
    block_idxINT00–47
    step_idxINT-1-1–255
    head_indicesSTRINGall
    num_framesINT11–256
    latent_heightINT321–256
    latent_widthINT321–256
    key_token_idxINT-1-1–65535
    aggregate_framesCOMBOmean3 options: mean, max, first
    colormapCOMBOinferno7 options: inferno, viridis, magma, plasma, hot, turbo, +1
    normalize_per_headBOOLEANtrue
    cell_sizeINT9616–512

    Outputs (1)

    NameTypeDescription
    query_mapIMAGE