From e62e208a5cf632576cea92207d1005c2b7781844 Mon Sep 17 00:00:00 2001
From: zhifu gao <zhifu.gzf@alibaba-inc.com>
Date: 星期四, 16 三月 2023 19:50:52 +0800
Subject: [PATCH] Merge pull request #251 from alibaba-damo-academy/dev_lhn
---
funasr/modules/embedding.py | 11 ++++++++++-
1 files changed, 10 insertions(+), 1 deletions(-)
diff --git a/funasr/modules/embedding.py b/funasr/modules/embedding.py
index b61a61a..e4f9bff 100644
--- a/funasr/modules/embedding.py
+++ b/funasr/modules/embedding.py
@@ -405,4 +405,13 @@
positions = torch.arange(1, timesteps+1)[None, :]
position_encoding = self.encode(positions, input_dim, x.dtype).to(x.device)
- return x + position_encoding
\ No newline at end of file
+ return x + position_encoding
+
+ def forward_chunk(self, x, cache=None):
+ start_idx = 0
+ batch_size, timesteps, input_dim = x.size()
+ if cache is not None:
+ start_idx = cache["start_idx"]
+ positions = torch.arange(1, timesteps+start_idx+1)[None, :]
+ position_encoding = self.encode(positions, input_dim, x.dtype).to(x.device)
+ return x + position_encoding[:, start_idx: start_idx + timesteps]
--
Gitblit v1.9.1