You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 575b59f
Browse filesBrowse the repository at this point in the historyBrowse files
* the branch is now pointing to main and not to unify-resolve-plan
* Refactor expert parallelism registration and improve documentation
- Consolidated the registration of parallel styles into the `ParallelInterface` class for better organization.
- Updated the `expert_parallel.py` and `tensor_parallel.py` files to streamline the registration process of expert parallel strategies.
- Enhanced documentation for clarity regarding the usage of tensor parallel strategies and their registration.
- Removed redundant code related to `MoeExpertsParallel` and `MoeIdentityParallel` classes, which are now properly registered in the new structure.
* comment
* some models missed the tests EP mixin
* fix copyright
Copy file name to clipboardExpand all lines: docs/source/en/perf_infer_gpu_multi.md
+22-29Lines changed: 22 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -101,35 +101,28 @@ print(model.tp_plan)
101
101
102
102
## Partitioning strategies
103
103
104
-
The `ParallelInterface`class maps each strategy name you can use in a `tp_plan` to a configured strategy instance. You don't interact with it directly to shard a model, but it's the authoritative list of available names.
104
+
`ALL_PARALLEL_STYLES`, a `ParallelInterface`defined in [distributed/parallel_utils.py](https://github.com/huggingface/transformers/blob/main/src/transformers/distributed/parallel_utils.py), maps each strategy name you can use in a plan to a configured strategy instance. You don't interact with it directly to shard a model, but it's the authoritative list of available names.[distributed/tensor_parallel.py](https://github.com/huggingface/transformers/blob/main/src/transformers/distributed/tensor_parallel.py) registers the tensor parallel strategies into it:
Every strategy is a subclass of `TensorParallelLayer` in [distributed/tensor_parallel.py](https://github.com/huggingface/transformers/blob/main/src/transformers/distributed/tensor_parallel.py). The two you'll reach for most, `ColwiseParallel` and `RowwiseParallel`, take `input_layouts` and `output_layouts` placements, which is how one class covers several plan names. `colwise` leaves its output sharded on the last dim for a following `rowwise` layer to consume, while `colwise_gather_output` all-gathers it back to a full tensor.
125
+
Every tensor parallel strategy is a subclass of `TensorParallelLayer` in that file. The expert parallel strategies, such as `ep_dispatch_experts`, live in [distributed/expert_parallel.py](https://github.com/huggingface/transformers/blob/main/src/transformers/distributed/expert_parallel.py), subclass `ExpertParallelLayer`, which has the same hooks, and register into the same `ALL_PARALLEL_STYLES`. The two you'll reach for most, `ColwiseParallel` and `RowwiseParallel`, take `input_layouts` and `output_layouts` placements, which is how one class covers several plan names. `colwise` leaves its output sharded on the last dim for a following `rowwise` layer to consume, while `colwise_gather_output` all-gathers it back to a full tensor.
133
126
134
127
The table below describes each strategy.
135
128
@@ -144,12 +137,12 @@ The table below describes each strategy.
144
137
|`ReplicatedWithGradAllReduce`| Replicates a parameter but all-reduces its gradient. Needed for norms that sit between a column-wise and a row-wise layer and normalize along a sharded axis, where each rank only sees its own heads. |
145
138
|`AllReduceParallel`| All-reduces a module's `Partial()` forward output to `Replicate()`. Use it as a sync point for a module whose compute ends in a partial sum. |
146
139
|`MlaKvAProjParallel`| Splits the `kv_a_proj_with_mqa` output of DeepSeek-V2 style MLA attention and all-reduces the gradient of the RoPE half, which bypasses `kv_b_proj` and would otherwise keep a partial gradient. Requires `qk_rope_head_dim` in the model config. |
140
+
|`MoeExpertsParallel`| Tensor parallel MoE experts. All-reduces the expert output forward and adds the backward all-reduces for hidden states and routing weights. |
141
+
|`MoeIdentityParallel`| Pre-divides the input of a zero or identity expert by the mesh size, cancelling the all-reduce that `moe_tp_experts` applies downstream. |
147
142
|`MoEParamShard`| Shards MoE expert weights on a given placement. Backs the `grouped_gemm` name, where `shards_expert_dim=True` also rewrites `module.num_experts` to the per-rank expert count. |
148
143
|`EpRouterParallel`| Masks router scores for non-local experts and remaps global expert IDs to local ones, so each rank runs only the experts it owns. Requires `num_experts` to be divisible by the mesh size. |
149
144
|`RouterParallelMegaMoe`| Router variant for DeepGEMM Mega MoE, which dispatches experts inside the kernel which wants the router output untouched. |
150
-
|`MoeExpertsParallel`| Tensor parallel MoE experts. All-reduces the expert output forward and adds the backward all-reduces for hidden states and routing weights. |
151
145
|`MoeTensorParalellMegaMoeExperts`| Inference-only experts layer for DeepGEMM Mega MoE. Skips the gradient syncs and passes the process group into the module so the kernel can set up its shared buffers on the first forward. |
152
-
|`MoeIdentityParallel`| Pre-divides the input of a zero or identity expert by the mesh size, cancelling the all-reduce that `moe_tp_experts` applies downstream. |
153
146
154
147
### Packed strategies
155
148
@@ -242,9 +235,9 @@ The example below walks through a trimmed version of `ColwiseParallel`.
242
235
import torch
243
236
244
237
from transformers import AutoModelForCausalLM, DistributedConfig
245
-
from transformers.distributed.tensor_parallelimportParallelInterface
238
+
from transformers.distributed.parallel_utilsimportALL_PARALLEL_STYLES
0 commit comments