Skip to content

Fusing Pallas Layout Transposes and Output Projections#449

Closed
prishajain1 wants to merge 1 commit into
mainfrom
fuse-transposes
Closed

Fusing Pallas Layout Transposes and Output Projections#449
prishajain1 wants to merge 1 commit into
mainfrom
fuse-transposes

Conversation

@prishajain1

Copy link
Copy Markdown
Collaborator

This PR optimizes the custom sequence-parallel attention path for WAN models by fusing layout transposes and avoiding post-attention copy overhead.

Changes:

  • Pallas Kernels (custom_splash_attention.py): Modified forward kernels to write output registers directly in transposed [H, S, D] layout using SRAM transposes.
  • Attention Wrappers (attention_flax.py): Bypassed post-attention jnp.swapaxes and _reshape_heads_to_head_dim transpose copy operations for custom kernels.
  • Output Projection (FlaxWanAttention): Implemented a custom multi-axis dot_general contraction contracting the H (heads) and D (head features) axes directly, avoiding transposing activations before matrix multiplication.

Performance and Results:

Eliminates layout transpose overhead after the Ulysses all_to_all collective:

Hardware Model Name Before fixes After fix Gain
TPU v6e-8 WAN 2.1 14B
TPU v7x-8 WAN 2.1 14B

@prishajain1
prishajain1 requested a review from entrpn as a code owner July 18, 2026 04:58
@github-actions

Copy link
Copy Markdown

@prishajain1
prishajain1 marked this pull request as draft July 18, 2026 04:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant