[Bugfix][Quantization] Fix fp32 weight scale for mxfp4 quantization and per-expert checkpoint mapping (#51419)

Signed-off-by: Isotr0py <Isotr0py@outlook.com>
This commit is contained in:
Isotr0py
2026-08-09 23:08:52 -07:00
committed by GitHub
parent b22afe45ac
commit 3b4c86e489
2 changed files with 67 additions and 0 deletions
@@ -896,6 +896,14 @@ class RoutedExperts(PluggableLayer):
break
continue
matched = True
is_per_expert_fused_w13 = (
not is_fused
and shard_id in {"w1", "w3"}
and any(
f".{fused_name}." in qual_name
for fused_name in ("gate_up_proj", "w13")
)
)
weight_name = qual_name.replace(weight_name, param_name)
param_name = weight_name.removeprefix(f"{self.layer_name}.")
param = getattr(self, param_name, None)
@@ -919,6 +927,12 @@ class RoutedExperts(PluggableLayer):
else:
experts_shard = fused_weight
start = 0
elif is_per_expert_fused_w13:
shard_index = 0 if shard_id == "w1" else 1
experts_shard = loaded_weight.chunk(2, dim=0)[
shard_index
].unsqueeze(0)
start = expert_id
else:
# loaded_weight is a single expert weight, so we add a dummy expert
# dimension to unify the loading logic with the fused case
@@ -1069,6 +1083,19 @@ class RoutedExperts(PluggableLayer):
(f"{w13}weight", f"experts.{gate_up}", 1, "w3"),
(f"{w2}weight", f"experts.{ckpt_down_proj_name}", 0, "w2"),
]
fused_mapping.extend(
(
w13,
(
f"experts.{physical_to_logical_map[expert_id]}."
f"{gate_up}.{lora_base_layer_prefix}"
),
expert_id,
shard_id,
)
for expert_id in range(num_physical_experts)
for shard_id in ("w1", "w3")
)
per_expert_mapping = [
# (param_name, weight_name, expert_id, shard_id)