Skip to content

Commit

Permalink
quick fix from pretrained. (PaddlePaddle#8487)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZHUI authored and DesmonDay committed Sep 5, 2024
1 parent 08898bf commit 1b352af
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions paddlenlp/transformers/model_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ def _load_state_dict_into_meta_model(

dtype = convert_np_dtype_to_dtype_(dtype)
error_msgs = []

model_state_dict = model.state_dict()
for param_name, param in state_dict.items():
# First part of the test is always true as loaded_state_dict_keys always contains state_dict keys.
if param_name not in loaded_state_dict_keys or param_name not in expected_keys:
Expand Down Expand Up @@ -833,7 +833,7 @@ def _load_state_dict_into_meta_model(
if old_param is not None:
param = param.astype(dtype=old_param.dtype)
with paddle.no_grad():
model.state_dict()[param_name].get_tensor()._share_data_with(param.value().get_tensor())
model_state_dict[param_name].get_tensor()._share_data_with(param.value().get_tensor())
param.value().get_tensor()._clear()
return error_msgs

Expand Down Expand Up @@ -1890,7 +1890,7 @@ def _find_mismatched_keys(
if (
shard_file.endswith(".safetensors")
and config.tensor_parallel_degree > 1
and "tp" not in shard_file
and "tp" not in os.path.spilt(shard_file)[-1]
):
pre_tensor_parallel_split = True
assert loaded_keys is not None, "loaded_keys is not None."
Expand Down

0 comments on commit 1b352af

Please sign in to comment.