Repository navigation
[distributed] Add a new parallel plan for unit sharding - #48848
Conversation
Covers replicated, non-dividing, coprime, exact, GQA and MQA head counts.
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
Replaces the hand-rolled attention mock with LlamaModel, so the styles read the config the same way they do in a real plan.
CI recapDashboard: View test results in Grafana |
3outeille
left a comment
There was a problem hiding this comment.
Did a first review, we need some forward + backward test in test_tensor_parallel_mixin.py to be safe
|
@ArthurZucker @3outeille Hi, will we adopt this approach? If so, I will close #47811 |
|
We will! You can close your PR! |
Build the (units, unit_replicate) view of the tp mesh once per group count in the mesh manager instead of creating a new DeviceMesh and process groups per projection.
This reverts commit 0106fb1.
… modules Drops the `needs_config` flag and the `module.config` / `module._mesh_manager` attributes that `apply_tensor_parallelism` used to attach, so applying a plan no longer mutates the model's modules. The unit styles take the config and mesh manager as arguments to `shard_param`, and MLA takes the config in `transform_output_post_forward`. Also guards the unit-rowwise inference all-reduce on the unit axis, and drops the stale "expected shape / prepare the slices" lines from the UnitColwiseParallel docstring.
fc93b7b to
2cedd8d
Compare
| ) | ||
|
|
||
| @is_tensor_parallel_test | ||
| def test_tp_unit_plan_forward_backward(self): |
There was a problem hiding this comment.
from my understanding the test never run _ScaleBackward right?
There was a problem hiding this comment.
It does with the TP Plan that uses the unit colwise etc!
There was a problem hiding this comment.
but wait now the test doesnt cover GQA ?
apply_tensor_parallelism passes config= and mesh_manager= to style.shard_param, but ColwiseParallel, RowwiseParallel, EmbeddingParallel, PackedColwiseParallel and PackedRowwiseParallel still had the old signature, so sharding any embedding or linear parameter raised a TypeError.
apply_tensor_parallelism called shard_param without the mesh argument, so sharding any parameter raised 'EmbeddingParallel.shard_param() missing 1 required positional argument: mesh'. This broke TP, EP and FSDP runs.
Beam keeps a per-head `gate_proj`/`gate_bias` and GraniteSWA a per-head `sinks`; Glm4v-MoE derives its mrope sections from `head_dim`. The unit-plan test forced Q heads to 1 without accounting for those, and `UnitColwiseParallel` assumed every sharded parameter belonged to a Linear weight. Shard bare per-head parameters on the unit mesh, undo the UnitRowwise input-gradient scaling for them, and keep the original `head_dim` in the test.
|
Las commit was shit |
Revert the UnitColwise per-head parameter support and its first-forward gradient hook. Unit sharding is only meant for head-aligned Linear weights for now; document that extra per-head parameters (Beam gate_bias, GraniteSWA sinks) are unsupported in a TODO. Fix the unit-plan test instead: keep the original head_dim so models that derive mrope sections from it still work, and skip models whose attention has extra head-aligned parameters.
Conflicts: the linear attention conv path became causal_conv1d_forward on main (#49xxx kernelizable conv): the paged CB branch keeps causal_conv1d_varlen and the rest calls main's causal_conv1d_forward (Qwen3-Next, Qwen3.5, Qwen3.5-MoE, Qwen4-Exp); transform_output_post_forward takes config (unit sharding, #48848); Gemma3RMSNorm(dim=) -> hidden_size.
What does this PR do?
This PR introduces unit sharding.
This affects mostly
q,k,v, but i figured it will give more freedom in general.When a layer is expressed as
And you want to unsure the last dim is sharded to non empty
units, use this TP style.DTensordoes not allow uneven sharding. So the trick is to transform anyShard(n)toShard(n// units), Replicate().This is not optimal in terms of memory, but its the only solution for now.
Superseeds #47811
Example:
# 6 heads, 8 RANKs