Compute decoded features. Args: tgt (torch.Tensor): Input tensor (#batch, maxlen_out, size). tgt_mask (torch.Tensor): Mask for input tensor (#batch, maxlen_out). memory (torch.Tensor): Encoded memory, float32 (#batch, maxlen_in, size). memory_
(
self, tgt, memory, fsmn_cache=None, opt_cache=None, chunk_size=None, look_back=0
)
| 158 | return x, tgt_mask, memory, memory_mask, cache |
| 159 | |
| 160 | def forward_chunk( |
| 161 | self, tgt, memory, fsmn_cache=None, opt_cache=None, chunk_size=None, look_back=0 |
| 162 | ): |
| 163 | """Compute decoded features. |
| 164 | |
| 165 | Args: |
| 166 | tgt (torch.Tensor): Input tensor (#batch, maxlen_out, size). |
| 167 | tgt_mask (torch.Tensor): Mask for input tensor (#batch, maxlen_out). |
| 168 | memory (torch.Tensor): Encoded memory, float32 (#batch, maxlen_in, size). |
| 169 | memory_mask (torch.Tensor): Encoded memory mask (#batch, maxlen_in). |
| 170 | cache (List[torch.Tensor]): List of cached tensors. |
| 171 | Each tensor shape should be (#batch, maxlen_out - 1, size). |
| 172 | |
| 173 | Returns: |
| 174 | torch.Tensor: Output tensor(#batch, maxlen_out, size). |
| 175 | torch.Tensor: Mask for output tensor (#batch, maxlen_out). |
| 176 | torch.Tensor: Encoded memory (#batch, maxlen_in, size). |
| 177 | torch.Tensor: Encoded memory mask (#batch, maxlen_in). |
| 178 | |
| 179 | """ |
| 180 | residual = tgt |
| 181 | if self.normalize_before: |
| 182 | tgt = self.norm1(tgt) |
| 183 | tgt = self.feed_forward(tgt) |
| 184 | |
| 185 | x = tgt |
| 186 | if self.self_attn: |
| 187 | if self.normalize_before: |
| 188 | tgt = self.norm2(tgt) |
| 189 | x, fsmn_cache = self.self_attn(tgt, None, fsmn_cache) |
| 190 | x = residual + self.dropout(x) |
| 191 | |
| 192 | if self.src_attn is not None: |
| 193 | residual = x |
| 194 | if self.normalize_before: |
| 195 | x = self.norm3(x) |
| 196 | |
| 197 | x, opt_cache = self.src_attn.forward_chunk(x, memory, opt_cache, chunk_size, look_back) |
| 198 | x = residual + x |
| 199 | |
| 200 | return x, memory, fsmn_cache, opt_cache |
| 201 | |
| 202 | |
| 203 | @tables.register("decoder_classes", "FsmnDecoderSCAMAOpt") |
no outgoing calls
no test coverage detected