From 870fa4a37a194fb7919b53930064129b6d616cb7 Mon Sep 17 00:00:00 2001
From: 游雁 <zhifu.gzf@alibaba-inc.com>
Date: 星期五, 07 六月 2024 04:05:30 +0800
Subject: [PATCH] auto frontend
---
funasr/models/llm_asr/model.py | 14 +++++++++++---
1 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/funasr/models/llm_asr/model.py b/funasr/models/llm_asr/model.py
index 0d9bf7f..66a69eb 100644
--- a/funasr/models/llm_asr/model.py
+++ b/funasr/models/llm_asr/model.py
@@ -468,7 +468,7 @@
if len(speech_lengths.size()) > 1:
speech_lengths = speech_lengths[:, 0]
- batch_size = speech.shape[0]
+ batch_size, frames, _ = speech.shape
# audio encoder
encoder_out, encoder_out_lens = self.audio_encoder(speech.permute(0, 2, 1), speech_lengths)
@@ -483,8 +483,9 @@
_, l, _ = encoder_out.shape
for batch_idx in range(batch_size):
fbank_beg_idx = fbank_beg[batch_idx, 0].item()
- inputs_embeds[batch_idx, fbank_beg_idx : fbank_beg_idx + l, :] = encoder_out[
- batch_idx, :l, :
+ min_len = min(l, inputs_embeds.shape[1] - fbank_beg_idx)
+ inputs_embeds[batch_idx, fbank_beg_idx : fbank_beg_idx + min_len, :] = encoder_out[
+ batch_idx, :min_len, :
]
labels_ids[labels_ids == -1] = -100
model_outputs = self.llm(
@@ -499,6 +500,13 @@
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"]
+ stats["batch_size_x_tokens"] = token_num * batch_size
+ stats["batch_size_real_tokens"] = attention_mask.sum().item()
+ stats["padding_tokens"] = stats["batch_size_x_tokens"] - stats["batch_size_real_tokens"]
# force_gatherable: to-device and to-tensor if scalar for DataParallel
if self.length_normalized_loss:
--
Gitblit v1.9.1