From 47c14aff79bb902482b0a953a55d31bf130c7b04 Mon Sep 17 00:00:00 2001
From: 游雁 <zhifu.gzf@alibaba-inc.com>
Date: 星期一, 20 五月 2024 16:20:45 +0800
Subject: [PATCH] add
---
funasr/train_utils/average_nbest_models.py | 12 +++++++++---
1 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/funasr/train_utils/average_nbest_models.py b/funasr/train_utils/average_nbest_models.py
index b10c231..20da130 100644
--- a/funasr/train_utils/average_nbest_models.py
+++ b/funasr/train_utils/average_nbest_models.py
@@ -16,7 +16,7 @@
from functools import cmp_to_key
-def _get_checkpoint_paths(output_dir: str, last_n: int = 5):
+def _get_checkpoint_paths(output_dir: str, last_n: int = 5, use_deepspeed=False, **kwargs):
"""
Get the paths of the last 'last_n' checkpoints by parsing filenames
in the output directory.
@@ -29,7 +29,13 @@
sorted_items = (
sorted_items[:last_n] if avg_keep_nbest_models_type == "acc" else sorted_items[-last_n:]
)
- checkpoint_paths = [os.path.join(output_dir, key) for key, value in sorted_items[:last_n]]
+ checkpoint_paths = []
+ for key, value in sorted_items[:last_n]:
+ if not use_deepspeed:
+ ckpt = os.path.join(output_dir, key)
+ else:
+ ckpt = os.path.join(output_dir, key, "mp_rank_00_model_states.pt")
+
except:
print(f"{checkpoint} does not exist, avg the lastet checkpoint.")
# List all files in the output directory
@@ -49,7 +55,7 @@
Average the last 'last_n' checkpoints' model state_dicts.
If a tensor is of type torch.int, perform sum instead of average.
"""
- checkpoint_paths = _get_checkpoint_paths(output_dir, last_n)
+ checkpoint_paths = _get_checkpoint_paths(output_dir, last_n, **kwargs)
print(f"average_checkpoints: {checkpoint_paths}")
state_dicts = []
--
Gitblit v1.9.1