MoE: add moe_late_tp_combine so routed experts take the tensor axis as expert parallelism - #4910
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces the moe_late_tp_combine configuration flag to use the tensor axis as expert parallelism in the default sparse MoE path, moving tensor-axis communication outside of expert-expanded activations. It updates the configurations, MoE layer sharding logic, and adds a new unit test suite. The reviewer recommended ensuring that "tensor" is not already present in the sequence before appending it in token_split_pspec to avoid duplicate mesh axes in the PartitionSpec under custom mesh configurations.
| def token_split_pspec(logical_axes): | ||
| spec = list(self._logical_to_mesh_axes(logical_axes)) | ||
| seq = spec[1] | ||
| seq = () if seq is None else ((seq,) if isinstance(seq, str) else tuple(seq)) | ||
| spec[1] = seq + ("tensor",) | ||
| return P(*spec) |
There was a problem hiding this comment.
To prevent potential JAX sharding errors under custom mesh configurations, it is safer to ensure that "tensor" is not already present in seq before appending it. If "tensor" is already in seq, appending it again would result in a duplicate mesh axis in the PartitionSpec, which is invalid.
| def token_split_pspec(logical_axes): | |
| spec = list(self._logical_to_mesh_axes(logical_axes)) | |
| seq = spec[1] | |
| seq = () if seq is None else ((seq,) if isinstance(seq, str) else tuple(seq)) | |
| spec[1] = seq + ("tensor",) | |
| return P(*spec) | |
| def token_split_pspec(logical_axes): | |
| spec = list(self._logical_to_mesh_axes(logical_axes)) | |
| seq = spec[1] | |
| seq = () if seq is None else ((seq,) if isinstance(seq, str) else tuple(seq)) | |
| if "tensor" not in seq: | |
| seq = seq + ("tensor",) | |
| spec[1] = seq | |
| return P(*spec) |
…s expert parallelism Removes tensor-axis collectives from expert-expanded activations. Measured 6.811 to 4.632 s/step (1.47x) on v6e-128 DeepSeek-V4 LoRA at seq 16384. Co-authored-by: Sudarsanan <[email protected]> Co-authored-by: Armin <[email protected]> Co-authored-by: utlz <[email protected]>
208de7f to
d9f831a
Compare
Description
Adds
moe_late_tp_combineso routed experts use the tensor axis as additional expert parallelism instead of sharding the MoE hidden dimension. This removes tensor-axis collectives from expert-expanded activations.Performance
Setup:
ici_expert_parallelism=16,ici_tensor_parallelism=8,ici_fsdp_parallelism=1,max_target_length=16384,per_device_batch_size=0.125(global batch 16),LIBTPU_INIT_ARGS=--xla_tpu_scoped_vmem_limit_kib=98304, dynamic-splash attention path enabled.Tests
JAX_PLATFORMS=cpu XLA_FLAGS=--xla_force_host_platform_device_count=8 pytest tests/unit/moe_late_tp_combine_test.pypassed 3 tests.Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.