From 407625a73478c2bb5e20c62bfbdf53a55a1e6575 Mon Sep 17 00:00:00 2001
From: 游雁 <zhifu.gzf@alibaba-inc.com>
Date: 星期三, 12 六月 2024 15:18:42 +0800
Subject: [PATCH] decoding

---
 funasr/bin/train_ds.py           |    1 +
 funasr/train_utils/trainer_ds.py |   10 ++++++++++
 2 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/funasr/bin/train_ds.py b/funasr/bin/train_ds.py
index 67ed2ba..41ecbe4 100644
--- a/funasr/bin/train_ds.py
+++ b/funasr/bin/train_ds.py
@@ -124,6 +124,7 @@
         use_ddp=use_ddp,
         use_fsdp=use_fsdp,
         device=kwargs["device"],
+        excludes=kwargs.get("excludes", None),
         output_dir=kwargs.get("output_dir", "./exp"),
         **kwargs.get("train_conf"),
     )
diff --git a/funasr/train_utils/trainer_ds.py b/funasr/train_utils/trainer_ds.py
index ec76531..c973728 100644
--- a/funasr/train_utils/trainer_ds.py
+++ b/funasr/train_utils/trainer_ds.py
@@ -147,6 +147,10 @@
 
         self.use_deepspeed = use_deepspeed
         self.deepspeed_config = kwargs.get("deepspeed_config", "")
+        self.excludes = kwargs.get("excludes", None)
+        if self.excludes is not None:
+            if isinstance(self.excludes, str):
+                self.excludes = self.excludes.split(",")
 
     def save_checkpoint(
         self,
@@ -440,6 +444,12 @@
                     src_state = checkpoint["state_dict"]
                     dst_state = model.state_dict()
                     for k in dst_state.keys():
+                        if excludes is not None:
+                            for k_ex in excludes:
+                                k_tmp = k.replace("module.", "")
+                                if k_tmp.startswith(k_ex):
+                                    logging.info(f"key: {{k}} matching: {k_ex}, excluded")
+                                    continue
                         if not k.startswith("module.") and "module." + k in src_state.keys():
                             k_ddp = "module." + k
                         elif k.startswith("module.") and "module." + k not in src_state.keys():

--
Gitblit v1.9.1