已合并
[bugfix] 解决了PD分离场景下开启Fused MoE后的精度问题 #914
[bugfix] 解决了PD分离场景下开启Fused MoE后的精度问题 #914
已合并
Dawn952创建于 4月17日
3 个文件变更+18-9
Mmindie_llm/runtime/layers/fused_moe/moe_comm_strategy.py+1-0
@@ -202,6 +202,7 @@ class AllGatherStrategy(MoECommStrategyBase):
202 202 
203# Strategy selection order: first applicable strategy is used203# Strategy selection order: first applicable strategy is used
204MOE_COMM_STRATEGIES = [204MOE_COMM_STRATEGIES = [
205+ FusedMC2Strategy, # P0: Optimal (910C Fused MC2)
205 MC2Strategy, # P1: High perf (large cluster/decode)206 MC2Strategy, # P1: High perf (large cluster/decode)
206 All2AllStrategy, # P2: Fallback for prefill/specific cases207 All2AllStrategy, # P2: Fallback for prefill/specific cases
207 AllGatherStrategy, # P3: Universal fallback208 AllGatherStrategy, # P3: Universal fallback
Mmindie_llm/runtime/layers/quantization/ms_model_slim/w8a8.py+4-9
@@ -43,7 +43,6 @@ from mindie_llm.runtime.utils.distributed.utils import even_divide
43from mindie_llm.utils.log.logging import logger43from mindie_llm.utils.log.logging import logger
44 44 
45 45 
46-SUPPORT_NZ_NPU_LIST = ("Ascend910B3", "Ascend910B4-1", "Ascend910_9382", "Ascend910_9362")
47MXFP8_GROUP_SIZE = 3246MXFP8_GROUP_SIZE = 32
48 47 
49 48 
@@ -160,8 +159,7 @@ class W8A8PerTensorLinearMethod(LinearMethodBase):
160 )159 )
161 layer.weight.data = layer.weight.data.transpose(0, 1).contiguous()160 layer.weight.data = layer.weight.data.transpose(0, 1).contiguous()
162 161 
163- soc_name = get_npu_node_info().soc_name162+ if get_npu_node_info().is_nz_format_beneficial():
164- if soc_name in SUPPORT_NZ_NPU_LIST:
165 layer.weight.data = torch_npu.npu_format_cast(layer.weight.data, 29)163 layer.weight.data = torch_npu.npu_format_cast(layer.weight.data, 29)
166 logger.debug(164 logger.debug(
167 "Convert weight to FRACTAL_NZ done, current format is %s", torch_npu.get_npu_format(layer.weight.data)165 "Convert weight to FRACTAL_NZ done, current format is %s", torch_npu.get_npu_format(layer.weight.data)
@@ -249,8 +247,7 @@ class W8A8PerTokenLinearMethod(LinearMethodBase):
249 layer.weight.data = layer.weight.data.transpose(0, 1).contiguous()247 layer.weight.data = layer.weight.data.transpose(0, 1).contiguous()
250 layer.weight_scale.data = layer.weight_scale.data.flatten()248 layer.weight_scale.data = layer.weight_scale.data.flatten()
251 249 
252- soc_name = get_npu_node_info().soc_name250+ if get_npu_node_info().is_nz_format_beneficial():
253- if soc_name in SUPPORT_NZ_NPU_LIST:
254 layer.weight.data = torch_npu.npu_format_cast(layer.weight.data, 29)251 layer.weight.data = torch_npu.npu_format_cast(layer.weight.data, 29)
255 logger.debug(252 logger.debug(
256 "Convert weight to FRACTAL_NZ done, current format is %s", torch_npu.get_npu_format(layer.weight.data)253 "Convert weight to FRACTAL_NZ done, current format is %s", torch_npu.get_npu_format(layer.weight.data)
@@ -324,8 +321,7 @@ class W8A8MixLinearMethod(LinearMethodBase):
324 layer.weight.data = layer.weight.data.transpose(0, 1).contiguous()321 layer.weight.data = layer.weight.data.transpose(0, 1).contiguous()
325 layer.weight_scale.data = layer.weight_scale.data.flatten()322 layer.weight_scale.data = layer.weight_scale.data.flatten()
326 323 
327- soc_name = get_npu_node_info().soc_name324+ if get_npu_node_info().is_nz_format_beneficial():
328- if soc_name in SUPPORT_NZ_NPU_LIST:
329 layer.weight.data = torch_npu.npu_format_cast(layer.weight.data, 29)325 layer.weight.data = torch_npu.npu_format_cast(layer.weight.data, 29)
330 logger.debug(326 logger.debug(
331 "Convert weight to FRACTAL_NZ done, current format is %s", torch_npu.get_npu_format(layer.weight.data)327 "Convert weight to FRACTAL_NZ done, current format is %s", torch_npu.get_npu_format(layer.weight.data)
@@ -534,8 +530,7 @@ class W8A8PerTokenFusedMoEMethod(FusedMoEMethodBase):
534 "fused_down_weight_scale", ScalerParameter(scale_from_float_to_int64(layer.down_weight_scale.data))530 "fused_down_weight_scale", ScalerParameter(scale_from_float_to_int64(layer.down_weight_scale.data))
535 )531 )
536 532 
537- soc_name = get_npu_node_info().soc_name533+ if get_npu_node_info().is_nz_format_beneficial():
538- if soc_name in SUPPORT_NZ_NPU_LIST:
539 layer.gate_up_weight.data = torch_npu.npu_format_cast(layer.gate_up_weight.data, 29)534 layer.gate_up_weight.data = torch_npu.npu_format_cast(layer.gate_up_weight.data, 29)
540 logger.debug(535 logger.debug(
541 "Convert weight to FRACTAL_NZ done, current format is %s",536 "Convert weight to FRACTAL_NZ done, current format is %s",
Mmindie_llm/runtime/utils/npu/device_utils.py+13-0
@@ -142,6 +142,15 @@ class _NPUNodeInfo:
142 "Ascend310P5",142 "Ascend310P5",
143 "Ascend310P7",143 "Ascend310P7",
144 }144 }
145+ 
146+ self._nz_beneficial_soc_set = {
147+ "Ascend910B3",
148+ "Ascend910B4-1",
149+ "Ascend910_9362",
150+ "Ascend910_9382",
151+ "Ascend910_9392",
152+ }
153+ 
145 if self.soc_name in nz_only_names:154 if self.soc_name in nz_only_names:
146 self.only_supports_nz = True155 self.only_supports_nz = True
147 self.need_nz = True156 self.need_nz = True
@@ -192,6 +201,10 @@ class _NPUNodeInfo:
192 self._visible_device_ids = devices201 self._visible_device_ids = devices
193 return self._visible_device_ids202 return self._visible_device_ids
194 203 
204+ def is_nz_format_beneficial(self) -> bool:
205+ """Return True if current soc_name benefits from NZ format conversion."""
206+ return self.soc_name in self._nz_beneficial_soc_set
207+ 
195 def get_device_info_map(self) -> dict[int, _DeviceInfo]:208 def get_device_info_map(self) -> dict[int, _DeviceInfo]:
196 """Retrieve a mapping of logical NPU chip IDs to their device information.209 """Retrieve a mapping of logical NPU chip IDs to their device information.
197 210