From 26d642bfdf59a50365a9c8158acb223cae1004dc Mon Sep 17 00:00:00 2001
From: zhifu gao <zhifu.gzf@alibaba-inc.com>
Date: 星期二, 23 四月 2024 20:13:44 +0800
Subject: [PATCH] Dev gzf exp (#1651)

---
 funasr/train_utils/load_pretrained_model.py |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/funasr/train_utils/load_pretrained_model.py b/funasr/train_utils/load_pretrained_model.py
index 84c6320..4f0914a 100644
--- a/funasr/train_utils/load_pretrained_model.py
+++ b/funasr/train_utils/load_pretrained_model.py
@@ -7,7 +7,7 @@
 import torch
 import torch.nn
 import torch.optim
-
+import pdb
 
 def filter_state_dict(
 	dst_state: Dict[str, Union[float, torch.Tensor]],
@@ -47,7 +47,6 @@
 	oss_bucket=None,
 	scope_map=[],
 	excludes=None,
-	ignore_mismatch=False,
 	**kwargs,
 ):
 	"""Load a model state and set it to the model.
@@ -63,14 +62,15 @@
 	dst_state = obj.state_dict()
 	
 	print(f"ckpt: {path}")
+
 	if oss_bucket is None:
 		src_state = torch.load(path, map_location=map_location)
 	else:
 		buffer = BytesIO(oss_bucket.get_object(path).read())
 		src_state = torch.load(buffer, map_location=map_location)
-	if "state_dict" in src_state:
-		src_state = src_state["state_dict"]
-	
+		
+	src_state = src_state["state_dict"] if "state_dict" in src_state else src_state
+	src_state = src_state["model_state_dict"] if "model_state_dict" in src_state else src_state
 	src_state = src_state["model"] if "model" in src_state else src_state
 	
 	if isinstance(scope_map, str):
@@ -99,7 +99,7 @@
 					
 		if k_src in src_state.keys():
 			if ignore_init_mismatch and dst_state[k].shape != src_state[k_src].shape:
-				print(f"ignore_mismatch:{ignore_mismatch}, dst: {k, dst_state[k].shape}, src: {k_src, src_state[k_src].shape}")
+				print(f"ignore_init_mismatch:{ignore_init_mismatch}, dst: {k, dst_state[k].shape}, src: {k_src, src_state[k_src].shape}")
 			else:
 				dst_state[k] = src_state[k_src]
 

--
Gitblit v1.9.1