From 05c8eba11c51ca928eee9c041de1a4192e590aec Mon Sep 17 00:00:00 2001
From: nianjiuhuiyi <64776403+nianjiuhuiyi@users.noreply.github.com>
Date: 星期五, 27 六月 2025 09:57:45 +0800
Subject: [PATCH] Fix: 修复c++后端服务因为空数组的异常退出,以及c++的http服务在收到Ctrl+C信号后无法正常退出 (#2571)

---
 funasr/train_utils/load_pretrained_model.py |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/funasr/train_utils/load_pretrained_model.py b/funasr/train_utils/load_pretrained_model.py
index 6bada5f..da2eed5 100644
--- a/funasr/train_utils/load_pretrained_model.py
+++ b/funasr/train_utils/load_pretrained_model.py
@@ -8,6 +8,7 @@
 import torch.nn
 import torch.optim
 import pdb
+import copy
 
 
 def load_pretrained_model(
@@ -35,11 +36,12 @@
     logging.info(f"ckpt: {path}")
 
     if oss_bucket is None:
-        src_state = torch.load(path, map_location=map_location)
+        ori_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)
+        ori_state = torch.load(buffer, map_location=map_location)
 
+    src_state = copy.deepcopy(ori_state)
     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
@@ -94,9 +96,8 @@
                 )
             else:
                 dst_state[k] = src_state[k_src]
-
         else:
-            logging.info(f"Warning, miss key in ckpt: {k}, mapped: {k_src}")
+            print(f"Warning, miss key in ckpt: {k}, {path}")
 
     flag = obj.load_state_dict(dst_state, strict=True)
     logging.info(f"Loading ckpt: {path}, status: {flag}")

--
Gitblit v1.9.1