Skip to content

feat: experimental two-phase (head-chunked) Ulysses all-to-all#428

Open
csgoogle wants to merge 1 commit into
mainfrom
sagarchapara/ulysses-two-phase
Open

feat: experimental two-phase (head-chunked) Ulysses all-to-all#428
csgoogle wants to merge 1 commit into
mainfrom
sagarchapara/ulysses-two-phase

Conversation

@csgoogle

@csgoogle csgoogle commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

Description

Overview

This PR introduces the ulysses_attention_chunks attention config, which splits the Ulysses all-to-all communication into head-group passes. This chunked path allows XLA to overlap all-to-all collectives with head-parallel local attention compute, while preserving the existing single-shot path by default.

Key Changes

  • Chunked Communication: Applied the same chunking mechanism to both plain Ulysses ( ulysses_custom ) and Hybrid Ulysses+Ring ( ulysses_ring_custom ) attention kernels.
  • Remainder Handling: Allows the final chunk to carry the remainder when the requested chunk count does not divide the Ulysses head groups evenly.
  • Testing: Added mocked attention tests for numerical and layout equivalence across various chunk counts.

Performance Results & Impact

We ran a comprehensive matrix of benchmarks on Wan 2.2 at both 480p and 720p resolutions, testing across cp=4 and cp=8 . By splitting into chunks ( chunks=2 and
chunks=5 ), we observed consistent generation time improvements due to XLA communication overlapping compute:

Resolution Attention Parallelism No chunking With chunking Speedup
480p ulysses_ring cp4 / u2 45.9 44.0 −4%
480p ulysses (custom) cp4 50.0 48.8 −2%
720p ulysses_ring cp4 / u2 126.0 124.3 −1%
720p Ulysses (custom) cp4 137.63 135.50 -2%
720p Ulysses (cfg=off) cp8 73.26s 71.73s −2%

We observe greater performance gains when the all-to-all communication time is comparable to or dominates the attention compute time, as demonstrated by the 480p resolution benchmarks where communication overhead is more pronounced.

Internal doc: go/ulysses-chuncked

@github-actions

Copy link
Copy Markdown

@google-cla

google-cla Bot commented Jun 24, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@csgoogle csgoogle force-pushed the sagarchapara/ulysses-two-phase branch from 7240f50 to 0d936f8 Compare June 24, 2026 13:59
@csgoogle csgoogle requested a review from Perseus14 June 24, 2026 14:05
# math is identical to the single-shot path (heads are independent); requires
# async-collective LIBTPU flags to actually overlap, and the per-chunk head
# count must still be shardable across the context axis.
num_chunks = int(os.environ.get("ULYSSES_ATTENTION_CHUNKS", "1"))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this to config file to be used for any ulysses type kernel

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

f"got heads={num_heads} and context_shards={num_shards}."
)

# EXPERIMENTAL: split the all-to-all into `num_chunks` head-groups so XLA's

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work on ulysses + ring as well?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, updated the code.

@Perseus14 Perseus14 requested a review from eltsai June 24, 2026 20:14
@csgoogle csgoogle force-pushed the sagarchapara/ulysses-two-phase branch 2 times, most recently from 14eb661 to e09195e Compare June 30, 2026 20:02
@csgoogle csgoogle marked this pull request as ready for review July 1, 2026 05:52
@csgoogle csgoogle requested a review from entrpn as a code owner July 1, 2026 05:52
@csgoogle csgoogle force-pushed the sagarchapara/ulysses-two-phase branch 2 times, most recently from ec4e407 to 064a87f Compare July 13, 2026 09:27
Comment thread src/maxdiffusion/configs/base_wan_27b.yml
@csgoogle csgoogle force-pushed the sagarchapara/ulysses-two-phase branch from 064a87f to 8287cb6 Compare July 13, 2026 18:57
Add a ulysses_attention_chunks attention config to split the Ulysses all-to-all into head-group passes. The chunked path lets XLA overlap all-to-all collectives with head-parallel local attention compute while preserving the existing single-shot path by default.

Apply the same chunking to plain Ulysses and Ulysses+Ring, and allow the final chunk to carry the remainder when the requested chunk count does not divide the Ulysses head groups evenly.

Add mocked attention tests for numerical and layout equivalence across chunk counts.
@csgoogle csgoogle force-pushed the sagarchapara/ulysses-two-phase branch from 8287cb6 to cb463cf Compare July 13, 2026 19:10
@csgoogle csgoogle requested a review from mbohlool July 13, 2026 19:29
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.

3 participants