Attention matrix view:
make only frame-0 query rows dense
This visual explains the debugging intervention: keep sparse attention for most video tokens, but override the sparse mask for the query rows belonging to the first video frame. Those rows attend to every key/value token densely.
1. Token packing: rows are Q, columns are K/V
In video diffusion self-attention, tokens are usually flattened into one sequence. A common mental model is:
prompt/global
first frame
frame 1
frame 2
frame 3
frame 4
frame 5
frame 6
frame 7
sequence = [text tokens] + [frame0 tokens] + [frame1 tokens] + ... + [frame7 tokens] attention scores = Q @ Kᵀ one row = one query token attending over all K/V tokens
2. What “frame-0 query rows dense” means
This checks whether the first-frame artifact comes from corrupted attention outputs for frame-0 tokens. If the bright spots disappear, the sparse mask for frame-0 query rows is the likely failure point.
for q_token in frame0_tokens:
output[q_token] = dense_attention(Q[q_token], all_K, all_V)
for q_token in frame1_to_frame7_tokens:
output[q_token] = sparse_attention(Q[q_token], selected_K, selected_V)
3. Conceptual attention matrix
Rows are query groups. Columns are key/value groups. The green-labeled Q frame0 row is the only visual row group forced to be dense across all columns.
4. Block-level mask override
Real sparse kernels usually operate on blocks, not individual tokens. If a query block overlaps frame 0, mark the whole query block dense across all key blocks.
visual_start = text_len tokens_per_frame = latent_H * latent_W frame0_q_start = visual_start frame0_q_end = visual_start + tokens_per_frame first_q_block = frame0_q_start // q_block_size last_q_block = (frame0_q_end - 1) // q_block_size # Force all K/V blocks to be selected for frame-0 query blocks. mask[:, :, first_q_block:last_q_block + 1, :] = True
5. Why this is a good diagnostic
6. Interactive block-mask example
Adjust the example shape. The blue horizontal stripe shows the query blocks that overlap frame 0 and are forced dense across all key blocks.
Before global topk sparse
Frame 0 gets the same sparse ratio as every other frame. For short videos, one dropped key block can represent a large fraction of available temporal/context information.
mask[:, :, :, :] = sparse_topk_mask
After frame-0 rows protected
Only the first-frame query blocks are overwritten to dense. This protects the temporal boundary frame while preserving sparse attention elsewhere.
mask[:, :, frame0_q_blocks, :] = True