Skip to content

Commit 17556a2

Browse files
committed
fix gcu
1 parent c6e2a37 commit 17556a2

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

  • fastdeploy/model_executor/layers/moe

fastdeploy/model_executor/layers/moe/moe.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
from paddleformers.utils.log import logger
2323

2424
from fastdeploy import envs
25+
from fastdeploy.model_executor.layers.backends.gcu.moe.fused_moe_method_gcu_backend import (
26+
GCUWeightOnlyMoEMethod,
27+
)
2528
from fastdeploy.model_executor.layers.utils import get_tensor
2629
from fastdeploy.model_executor.utils import slice_fn
2730
from fastdeploy.platforms import current_platform
@@ -151,9 +154,10 @@ def __init__(
151154
self.gate_correction_bias = gate_correction_bias
152155
else:
153156
self.gate_correction_bias = None
154-
self.quant_method.create_weights(
155-
self, weight_loader=self.weight_loader, model_format=fd_config.model_config.model_format
156-
)
157+
if not isinstance(self.quant_method, GCUWeightOnlyMoEMethod):
158+
self.quant_method.create_weights(
159+
self, weight_loader=self.weight_loader, model_format=fd_config.model_config.model_format
160+
)
157161

158162
logger.info(
159163
f"{moe_tag}MoE config is {num_experts=}[{expert_id_offset}, {expert_id_offset + self.num_local_experts}), \
@@ -476,11 +480,17 @@ def load_state_dict(self, state_dict, is_rearrange: bool = False):
476480
load_state_dict function.
477481
"""
478482
if self.fd_config.model_config.is_quantized:
483+
if isinstance(self.quant_method, GCUWeightOnlyMoEMethod):
484+
self.quant_method.process_prequanted_weights(self, state_dict)
485+
return
479486
if getattr(self.fd_config.quant_config, "is_permuted", True):
480487
self.quant_method.process_prequanted_weights(self, state_dict, is_rearrange)
481488
else:
482489
self.quant_method.process_loaded_weights(self, state_dict)
483490
else:
491+
if isinstance(self.quant_method, GCUWeightOnlyMoEMethod):
492+
self.quant_method.create_weights(self, state_dict)
493+
return
484494
self.quant_method.process_loaded_weights(self, state_dict)
485495

486496
def forward(self, x: paddle.Tensor, gate: nn.Layer):

0 commit comments

Comments
 (0)