[Bugfix] [ROCm] [DSV4] Fix AITER MXFP4 MoE weight loading and shuffle… (#42595)
Co-authored-by: MHYangAMD <MHYangAMD@users.noreply.github.com>
This commit is contained in:
@@ -727,16 +727,19 @@ class FusedMoE(PluggableLayer):
|
||||
# Only narrow if the loaded_weight is not a scalar (0-dim tensor)
|
||||
# and we're not loading the full weight
|
||||
if not load_full and loaded_weight.ndim > 0:
|
||||
# Handle padding: loaded_weight might be smaller than shard_size on last
|
||||
# TP rank
|
||||
start_offset = shard_size * tp_rank
|
||||
# When the parameter has been padded (e.g. MXFP4 rounding up
|
||||
# intermediate_size_per_partition), shard_size is the padded
|
||||
# size. Compute the offset into the checkpoint weight using
|
||||
# the *unpadded* per-rank size so that every TP rank lands at
|
||||
# the correct slice.
|
||||
tp_size = self.moe_config.moe_parallel_config.tp_size
|
||||
loaded_per_rank = loaded_weight.shape[shard_dim] // tp_size
|
||||
start_offset = loaded_per_rank * tp_rank
|
||||
available = loaded_weight.shape[shard_dim] - start_offset
|
||||
if available <= 0:
|
||||
# If there is no available weight to load for this TP rank
|
||||
# (can happen on last TP rank with padding), we can skip
|
||||
# loading and return early
|
||||
return
|
||||
narrow_size = min(shard_size, available)
|
||||
narrow_size = min(loaded_per_rank, available)
|
||||
loaded_weight = loaded_weight.narrow(shard_dim, start_offset, narrow_size)
|
||||
# Narrow parameter and load.
|
||||
# w1, gate_proj: Load into first logical weight of w13.
|
||||
@@ -765,21 +768,18 @@ class FusedMoE(PluggableLayer):
|
||||
):
|
||||
# Index the loaded weight for tp sharding.
|
||||
# down_proj: "RowParallel" so tp sharding on input_dim
|
||||
# Narrow parameter and load.
|
||||
shard_size = expert_data.shape[shard_dim]
|
||||
# Only narrow if the loaded_weight is not a scalar (0-dim tensor)
|
||||
# and we're not loading the full weight
|
||||
if not load_full and loaded_weight.ndim > 0:
|
||||
# Handle padding: loaded_weight might be smaller than shard_size on last
|
||||
# TP rank
|
||||
start_offset = shard_size * tp_rank
|
||||
# Same padding fix as _load_w13: use unpadded per-rank size.
|
||||
tp_size = self.moe_config.moe_parallel_config.tp_size
|
||||
loaded_per_rank = loaded_weight.shape[shard_dim] // tp_size
|
||||
start_offset = loaded_per_rank * tp_rank
|
||||
available = loaded_weight.shape[shard_dim] - start_offset
|
||||
if available <= 0:
|
||||
# If there is no available weight to load for this TP rank
|
||||
# (can happen on last TP rank with padding), we can skip
|
||||
# loading and return early
|
||||
return
|
||||
narrow_size = min(shard_size, available)
|
||||
narrow_size = min(loaded_per_rank, available)
|
||||
loaded_weight = loaded_weight.narrow(shard_dim, start_offset, narrow_size)
|
||||
# w2, down_proj: Load into only logical weight of w2.
|
||||
hidden_dim = self._get_hidden_dim(shard_dim, expert_data.ndim)
|
||||
|
||||
Reference in New Issue
Block a user