feat: experimental two-phase (head-chunked) Ulysses all-to-all#428
feat: experimental two-phase (head-chunked) Ulysses all-to-all#428csgoogle wants to merge 1 commit into
Conversation
|
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. |
7240f50 to
0d936f8
Compare
| # 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")) |
There was a problem hiding this comment.
Let's move this to config file to be used for any ulysses type kernel
| f"got heads={num_heads} and context_shards={num_shards}." | ||
| ) | ||
|
|
||
| # EXPERIMENTAL: split the all-to-all into `num_chunks` head-groups so XLA's |
There was a problem hiding this comment.
Does this work on ulysses + ring as well?
There was a problem hiding this comment.
yes, updated the code.
14eb661 to
e09195e
Compare
ec4e407 to
064a87f
Compare
8287cb6 to
cb463cf
Compare
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.
cb463cf to
ca0c88e
Compare
| return attention_output | ||
|
|
||
| x = wrap_ulysses_ring_attention(query, key, value) | ||
| head_chunk_ranges = _ulysses_head_chunk_ranges(num_heads, num_ulysses_shards, ulysses_attention_chunks) |
There was a problem hiding this comment.
this code is repeated 3 times, can we consolidate it into a single reusable code?
|
|
||
| [tool.ruff] | ||
| # Never enforce `E501` (line length violations). | ||
| line-length = 119 |
There was a problem hiding this comment.
Gemini fixed the configuration to use [tool.ruff.lint.per-file-ignores] and [tool.ruff.lint.isort] to resolve deprecation warnings.
entrpn
left a comment
There was a problem hiding this comment.
Where are we documenting these different techniques for users, in the readme?
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
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:
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