From 8f596af4be1c2e5c4e4b4a7008ba96f412d40fca Mon Sep 17 00:00:00 2001
From: 游雁 <zhifu.gzf@alibaba-inc.com>
Date: 星期一, 29 四月 2024 14:32:43 +0800
Subject: [PATCH] batch

---
 funasr/models/sense_voice/model.py |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/funasr/models/sense_voice/model.py b/funasr/models/sense_voice/model.py
index 4cbb490..ae20902 100644
--- a/funasr/models/sense_voice/model.py
+++ b/funasr/models/sense_voice/model.py
@@ -1,3 +1,4 @@
+import logging
 from dataclasses import dataclass
 from typing import Dict
 from typing import Iterable, Optional
@@ -308,7 +309,7 @@
         if len(speech_lengths.size()) > 1:
             speech_lengths = speech_lengths[:, 0]
 
-        batch_size = speech.shape[0]
+        batch_size, frames, _ = speech.shape
 
         if self.activation_checkpoint:
             from torch.utils.checkpoint import checkpoint
@@ -327,6 +328,9 @@
         stats["acc"] = acc_att
         stats["loss"] = torch.clone(loss.detach())
         stats["batch_size"] = batch_size
+        stats["batch_size_x_frames"] = frames * batch_size
+        stats["batch_size_real_frames"] = speech_lengths.sum().item()
+        stats["padding_frames"] = stats["batch_size_x_frames"] - stats["batch_size_real_frames"]
 
         # force_gatherable: to-device and to-tensor if scalar for DataParallel
         if self.length_normalized_loss:

--
Gitblit v1.9.1