Repository navigation
Add TPU Ulysses context parallelism - #4687
Conversation
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
|
🤖 Hi @huytransformer, I've received your request, and I'm working on it now! You can track my progress in the logs for more details. |
There was a problem hiding this comment.
This Pull Request introduces highly performant TPU Ulysses context parallelism on the TPU Tokamax Splash attention training path. The implementation is exceptionally clean, well-integrated, and backed by comprehensive unit, collective, and integration tests that verify correctness against dense references and compiled HLO collectives.
🔍 General Feedback
- Excellent Test Coverage: The newly added tests (including CPU multi-device mock checks and HLO collective pattern assertions) set a very high bar for correctness and robustness.
- Robust Config Validation: The comprehensive validation in
configs/types.pyensures that unsupported combinations (like MQA, packing, ragged attention, dropout, etc.) are proactively rejected with precise errors. - Clean Shared Utilities: Factoring out mesh and sharding operations into
context_parallel_utils.pyis a great design choice that improves maintainability. - Thorough Documentation: The update to
sharding.mdis incredibly detailed and accurately captures Ulysses constraints and architectural mechanics.
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
RissyRan
left a comment
There was a problem hiding this comment.
Thanks! LGTM at high level. Some minor comments.
e72bd0d to
3cd54a9
Compare
3cd54a9 to
caf6dbf
Compare
caf6dbf to
42aecc2
Compare
Imported from GitHub PR #4836 # Description This PR introduces `context_parallel_strategy=usp` ([USP](https://arxiv.org/abs/2405.07719), Ulysses over ring). Follow up to #4687. Currently does not support load balancing + sequence packing. # Tests `python3 -m pytest tests/unit/configs_value_test.py tests/unit/usp_attention_test.py tests/unit/usp_collective_test.py` Passed. `python3 -m pytest tests/unit/attention_test.py -k usp` 3 passed. ## Performance llama3-8b, v5p (64 chips), CP64, bf16, synthetic data, global batch 1, no load-balancing Reporting median step time (s) | | 64K | 128K | 256K | |---|---|---|---| | all-gather (CP64) | 1.31 | 4.03 | 14.33 | | ring (CP64) | 1.68 | 4.63 | 15.35 | | usp (16x4) | 1.31 | 4.02 | 13.92 | | usp (8x8) | 1.44 | 4.05 | 13.65 | | usp (32x2) | 1.65 | 4.52 | 14.72 | Example repro command: ``` python3 -m maxtext.trainers.pre_train.train src/maxtext/configs/base.yml model_name=llama3-8b dataset_type=synthetic enable_checkpointing=False steps=20 per_device_batch_size=0.015625 packing=False attention=flash use_tokamax_splash=True use_jax_splash=False allow_split_physical_axes=True max_target_length=65536 context_parallel_strategy=usp ici_context_parallelism=16 ici_context_ulysses_parallelism=4 context_parallel_load_balance=False run_name=usp16x4_65536 base_output_directory=<output dir> ``` # Checklist Before submitting this PR, please make sure (put X in square brackets): - [X] I have performed a self-review of my code. For an optional AI review, add the `gemini-review` label. - [X] I have necessary comments in my code, particularly in hard-to-understand areas. - [X] I have run end-to-end tests tests and provided workload links above if applicable. - [X] I have made or will make corresponding changes to the doc if needed, including adding new documentation pages to the relevant Table of Contents (toctree directive) as explained in [our documentation](https://maxtext.readthedocs.io/en/latest/development.html#adding-new-documentation-files). Copybara import of the project: -- e5c987dc7fdf70a6e266856eef47370f2ebc43c1 by continuousml <continuousml@gmail.com>: Add TPU USP context parallelism Merging this change closes #4836 COPYBARA_INTEGRATE_REVIEW=#4836 from AI-Hypercomputer:htn-usp-cp e5c987dc7fdf70a6e266856eef47370f2ebc43c1 PiperOrigin-RevId: 964446152
Description
This PR adds
context_parallel_strategy="ulysses", DeepSpeed-Ulysses style context parallelism for the TPU splash attention (https://arxiv.org/abs/2309.14509).Motivations: (1) the existing approaches degrade when the context parallelism degree is large relative to the sequence length. (2) It is also the head-parallel half of a Ulysses x ring hybrid (USP), which can be built on top of this PR.
Performance
What we did: v5p-128 (64 chips), bf16, synthetic data, 2M tokens per step in every cell,
remat_policy=custom context=device,dq_reduction_steps=3. Each uses its best known block sizes (2048 for Ulysses, 1024 for Ring and All-gather).llama2-7b (MHA, 32 KV heads), 32K context, cp=16, 2K tokens per device.
Ulysses matches all-gather and runs 1.8x faster than ring, while holding 1/16 of all-gather's attention KV per device (2 of 32 heads).
llama3.1-8b (GQA, 8 KV heads), cp=4.
Correctness: 20 training steps against
all_gatheron llama3.1-8b at 64K, cp=4, identical data, max loss difference is 0.001.Example repro
Tests
tests/unit/ulysses_attention_test.py: Passed.tests/unit/ulysses_collective_test.py: Passed.tests/unit/configs_value_test.py: Passed.tests/integration/train_tests.py: train smoke test with ulysses cp=4. Passed.Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.