Skip to content

Commit 44f4424

Browse files
committed
Fix LTX2 cross-attention axis names and ring attention fallback
1 parent 1e15333 commit 44f4424

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

src/maxdiffusion/models/ltx2/attention_ltx2.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,15 +436,28 @@ def __init__(
436436
dtype=dtype,
437437
)
438438

439+
is_self_attention = context_dim is None
440+
if not is_self_attention:
441+
if attention_kernel in ("tokamax_ring", "tokamax_ring_custom", "ulysses_ring"):
442+
attention_kernel = "tokamax_flash" # do not use ring attention for cross attention
443+
if attention_kernel in ("ulysses_ring_custom", "ulysses_ring_custom_bidir"):
444+
attention_kernel = "ulysses_custom" # plain ulysses (no ring) for cross attention
445+
446+
axis_names_q = (common_types.BATCH, common_types.CROSS_ATTN_HEAD, common_types.CROSS_ATTN_Q_LENGTH, common_types.D_KV)
447+
axis_names_kv = (common_types.BATCH, common_types.CROSS_ATTN_HEAD, common_types.CROSS_ATTN_KV_LENGTH, common_types.D_KV)
448+
else:
449+
axis_names_q = (common_types.BATCH, common_types.SELF_ATTN_HEAD, common_types.SELF_ATTN_Q_LENGTH, common_types.D_KV)
450+
axis_names_kv = (common_types.BATCH, common_types.SELF_ATTN_HEAD, common_types.SELF_ATTN_KV_LENGTH, common_types.D_KV)
451+
439452
self.attention_op = NNXAttentionOp(
440453
mesh=mesh,
441454
attention_kernel=attention_kernel,
442455
scale=dim_head**-0.5,
443456
heads=heads,
444457
dim_head=dim_head,
445458
dtype=dtype,
446-
axis_names_q=(common_types.BATCH, common_types.SELF_ATTN_HEAD, common_types.SELF_ATTN_Q_LENGTH, common_types.D_KV),
447-
axis_names_kv=(common_types.BATCH, common_types.SELF_ATTN_HEAD, common_types.SELF_ATTN_KV_LENGTH, common_types.D_KV),
459+
axis_names_q=axis_names_q,
460+
axis_names_kv=axis_names_kv,
448461
flash_block_sizes=flash_block_sizes,
449462
flash_min_seq_length=flash_min_seq_length,
450463
ulysses_shards=ulysses_shards,

0 commit comments

Comments
 (0)