Skip to content

Commit bc44f9f

Browse files
stefankoncarevicAndreasKaratzasmergify[bot]
authored
[ROCm][CI][MoE] Fix double-transpose of fused w3 expert weights (#47874)
Signed-off-by: stefankoncarevic <stefan.koncarevic@amd.com> Signed-off-by: Andreas Karatzas <akaratza@amd.com> Co-authored-by: Andreas Karatzas <akaratza@amd.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 7802c20 commit bc44f9f

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

vllm/model_executor/layers/fused_moe/routed_experts.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -886,17 +886,21 @@ def load_weights(
886886
param_name = weight_name.removeprefix(f"{self.layer_name}.")
887887
param = getattr(self, param_name)
888888
if is_fused:
889+
# w1 and w3 share one fused tensor; use a local copy so the
890+
# transpose below doesn't mutate loaded_weight across
891+
# iterations (else w3 is transposed twice and wrongly chunked)
892+
fused_weight = loaded_weight
889893
if shard_id in {"w1", "w3"}:
890-
if loaded_weight.shape[-1] != unpadded_hidden:
894+
if fused_weight.shape[-1] != unpadded_hidden:
891895
# [..., hidden, intermediate] -> [..., intermediate, hidden]
892-
loaded_weight = loaded_weight.transpose(-1, -2)
896+
fused_weight = fused_weight.transpose(-1, -2)
893897
# Repurpose expert_id for deconcatenating w1 and w3
894-
experts_shard = loaded_weight.chunk(2, dim=1)[expert_id]
898+
experts_shard = fused_weight.chunk(2, dim=1)[expert_id]
895899
else:
896-
if loaded_weight.shape[-2] != unpadded_hidden:
900+
if fused_weight.shape[-2] != unpadded_hidden:
897901
# [..., intermediate, hidden] -> [..., hidden, intermediate]
898-
loaded_weight = loaded_weight.transpose(-1, -2)
899-
experts_shard = loaded_weight
902+
fused_weight = fused_weight.transpose(-1, -2)
903+
experts_shard = fused_weight
900904
start = 0
901905
else:
902906
# loaded_weight is a single expert weight, so we add a dummy expert

0 commit comments

Comments
 (0)