mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-06 00:57:33 +08:00
bugfix (#3322)
This commit is contained in:
@@ -86,6 +86,7 @@ class BaseRLModel(nn.Layer):
|
|||||||
super(BaseRLModel, self).__init__()
|
super(BaseRLModel, self).__init__()
|
||||||
self.infer_to_train_mapping = {}
|
self.infer_to_train_mapping = {}
|
||||||
self.fd_config = None
|
self.fd_config = None
|
||||||
|
self._mappings_built = False
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def name(cls) -> str:
|
def name(cls) -> str:
|
||||||
@@ -142,6 +143,12 @@ class Ernie4_5_MoeForCausalLMRL(Ernie4_5_MoeForCausalLM, BaseRLModel):
|
|||||||
|
|
||||||
def get_name_mappings_to_training(self, trainer_degree=None) -> Dict[str, str]:
|
def get_name_mappings_to_training(self, trainer_degree=None) -> Dict[str, str]:
|
||||||
"""Generate mapping between inference and training parameter for RL(donot delete!)."""
|
"""Generate mapping between inference and training parameter for RL(donot delete!)."""
|
||||||
|
if self._mappings_built:
|
||||||
|
return self.infer_to_train_mapping
|
||||||
|
|
||||||
|
self.infer_to_train_mapping = {}
|
||||||
|
self._mappings_built = True
|
||||||
|
|
||||||
# Prepare placeholders
|
# Prepare placeholders
|
||||||
place_holders = ["weight"]
|
place_holders = ["weight"]
|
||||||
|
|
||||||
@@ -215,6 +222,11 @@ class Ernie4_5_VLMoeForConditionalGenerationRL(Ernie4_5_VLMoeForConditionalGener
|
|||||||
|
|
||||||
def get_name_mappings_to_training(self, trainer_degree=None) -> Dict[str, str]:
|
def get_name_mappings_to_training(self, trainer_degree=None) -> Dict[str, str]:
|
||||||
"""Generate mapping between inference and training parameter for RL(donot delete!)."""
|
"""Generate mapping between inference and training parameter for RL(donot delete!)."""
|
||||||
|
if self._mappings_built:
|
||||||
|
return self.infer_to_train_mapping
|
||||||
|
|
||||||
|
self.infer_to_train_mapping = {}
|
||||||
|
self._mappings_built = True
|
||||||
# Prepare placeholders
|
# Prepare placeholders
|
||||||
place_holders = ["weight"]
|
place_holders = ["weight"]
|
||||||
|
|
||||||
@@ -316,6 +328,11 @@ class Qwen2ForCausalLMRL(Qwen2ForCausalLM, BaseRLModel):
|
|||||||
|
|
||||||
def get_name_mappings_to_training(self, trainer_degree=None) -> Dict[str, str]:
|
def get_name_mappings_to_training(self, trainer_degree=None) -> Dict[str, str]:
|
||||||
"""Generate mapping between inference and training parameter for RL(donot delete!)."""
|
"""Generate mapping between inference and training parameter for RL(donot delete!)."""
|
||||||
|
if self._mappings_built:
|
||||||
|
return self.infer_to_train_mapping
|
||||||
|
|
||||||
|
self.infer_to_train_mapping = {}
|
||||||
|
self._mappings_built = True
|
||||||
# Prepare placeholders
|
# Prepare placeholders
|
||||||
place_holders = ["weight"]
|
place_holders = ["weight"]
|
||||||
|
|
||||||
@@ -360,6 +377,11 @@ class Qwen3MoeForCausalLMRL(Qwen3MoeForCausalLM, BaseRLModel):
|
|||||||
|
|
||||||
def get_name_mappings_to_training(self, trainer_degree=None) -> Dict[str, str]:
|
def get_name_mappings_to_training(self, trainer_degree=None) -> Dict[str, str]:
|
||||||
"""Generate mapping between inference and training parameter for RL(donot delete!)."""
|
"""Generate mapping between inference and training parameter for RL(donot delete!)."""
|
||||||
|
if self._mappings_built:
|
||||||
|
return self.infer_to_train_mapping
|
||||||
|
|
||||||
|
self.infer_to_train_mapping = {}
|
||||||
|
self._mappings_built = True
|
||||||
# Prepare placeholders
|
# Prepare placeholders
|
||||||
place_holders = ["weight"]
|
place_holders = ["weight"]
|
||||||
|
|
||||||
@@ -429,4 +451,30 @@ class Qwen3ForCausalLMRL(Qwen3ForCausalLM, BaseRLModel):
|
|||||||
return "Qwen3ForCausalLMRL"
|
return "Qwen3ForCausalLMRL"
|
||||||
|
|
||||||
def get_name_mappings_to_training(self, trainer_degree=None) -> Dict[str, str]:
|
def get_name_mappings_to_training(self, trainer_degree=None) -> Dict[str, str]:
|
||||||
pass
|
|
||||||
|
if self._mappings_built:
|
||||||
|
return self.infer_to_train_mapping
|
||||||
|
|
||||||
|
self.infer_to_train_mapping = {}
|
||||||
|
self._mappings_built = True
|
||||||
|
# Prepare placeholders
|
||||||
|
place_holders = ["weight"]
|
||||||
|
|
||||||
|
# Initialize mapping dictionary
|
||||||
|
self._update_base_mappings("model")
|
||||||
|
base_name = "model.layers"
|
||||||
|
|
||||||
|
# Helper function to add layer mappings
|
||||||
|
def _add_layer_mappings(layer_idx):
|
||||||
|
# FFN mappings
|
||||||
|
for ph in place_holders:
|
||||||
|
self.infer_to_train_mapping[f"{base_name}.{layer_idx}.mlp.up_gate_proj.{ph}"] = (
|
||||||
|
f"{base_name}.{layer_idx}.mlp.gate_up_fused_proj.{ph}"
|
||||||
|
)
|
||||||
|
|
||||||
|
for layer_idx in range(self.fd_config.model_config.num_hidden_layers):
|
||||||
|
_add_layer_mappings(layer_idx)
|
||||||
|
|
||||||
|
self._complete_missing_mappings()
|
||||||
|
|
||||||
|
return self.infer_to_train_mapping
|
||||||
|
Reference in New Issue
Block a user