Repository navigation
Add tensor parallelism for NucleusMoE-Image routed experts - #15424
yzhautouskay wants to merge 1 commit into
Conversation
|
Hi @yzhautouskay, thanks for the PR! It does not appear to link an issue it fixes.
See the contribution guide for more details. Please note that PRs without a linked issue are likely to be automatically closed 10 days after this notice. Once the PR links an existing issue, the author box is ticked, or the |
|
Thanks for the PR! We're discussing a bit if we want TP for a model that doesn't have much usage yet. |
dfbee01 to
f4e653a
Compare
sayakpaul
left a comment
There was a problem hiding this comment.
Thanks!
I opened yzhautouskay#2 with some suggestions to keep the modeling changes simpler and to move changes to a hook-based implementation.
|
|
||
| All ranks process the same routed tokens. Each rank takes a different slice of the intermediate channels, pairing the corresponding gate and up channels with the same input channels of the down projection. The expert computes its own elementwise gate activation on those local shards. After the down projection, PyTorch sums the partial outputs across ranks. | ||
|
|
||
| NucleusMoE-Image uses this plan entry because only some blocks contain routed experts. |
There was a problem hiding this comment.
Let's hyperlink the NucleusMoE-Image pipeline page here.
|
|
||
| def _packed_gated_expert_specs(module) -> dict[str, TPShardSpec]: | ||
| """Shard matching intermediate channels of the packed gate, up, and down projections for every expert.""" | ||
| width = module.down_proj.shape[1] |
There was a problem hiding this comment.
What if the module doesn't have down_proj? I think we should validate better and early.
| with torch.device("meta"): | ||
| model = self.model_class(**self.get_init_dict()) | ||
| prefix = "transformer_blocks.1.img_mlp.experts" | ||
| assert resolve_tp_shard_specs(model, model._tp_plan, tp_degree=4) == { |
There was a problem hiding this comment.
Is this supposed to run on 4 GPUs?
|
|
||
| @pytest.fixture(autouse=True) | ||
| def initialize_experts(self, monkeypatch): | ||
| # The checkpoint normally supplies these two torch.empty parameters. |
There was a problem hiding this comment.
I think this could be confusing. It's not the checkpoint that supplies torch.empty, it's the initialization block.
What does this PR do?
Adds the
"packed_gated_experts"tensor-parallel style and enables it for the routed experts in NucleusMoE-Image at TP2 and TP4. Attention, routing and shared experts stay replicated. Public checkpointExpert weight sharding
Both projections are bias-free. Each rank processes the same routed tokens across all 64 experts.
gate_up_proj[64, 2048, 2688][64, 2048, 1344][64, 2048, 672]a:b(gate) and1344+a:1344+b(up)down_proj[64, 1344, 2048][64, 672, 2048][64, 336, 2048]a:bFor rank
rat TP degreeP,w = 1344 // P,a = r * w, andb = a + w. PyTorch sums the partial outputs across ranks.Results
On GB200, TP4 used 41% less peak memory per GPU and took 1.22 s longer per image than TP1. Latency is the median of three end-to-end BF16 generations after warmup (1024 × 1024, batch size 1, 50 steps).
Before submitting
self-reviewskill on the diff?documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
@sayakpaul @JingyaHuang, could you review how packed MoE expert sharding fits into Diffusers’ tensor parallelism support?
@sippycoder, could you review how NucleusMoE-Image’s expert forward pass uses the sharded weights?