r"""Pass the input through the encoder layers in turn. Args: src: the sequence to the encoder (required). mask: the mask for the src sequence (optional). src_key_padding_mask: the mask for the src keys per batch (optional). Shape: see
(
self,
src: Tensor,
mask: Optional[Tensor] = None,
src_key_padding_mask: Optional[Tensor] = None,
)
| 197 | self.norm = norm |
| 198 | |
| 199 | def forward( |
| 200 | self, |
| 201 | src: Tensor, |
| 202 | mask: Optional[Tensor] = None, |
| 203 | src_key_padding_mask: Optional[Tensor] = None, |
| 204 | ) -> T.Union[Tensor, Tensor]: |
| 205 | r"""Pass the input through the encoder layers in turn. |
| 206 | |
| 207 | Args: |
| 208 | src: the sequence to the encoder (required). |
| 209 | mask: the mask for the src sequence (optional). |
| 210 | src_key_padding_mask: the mask for the src keys per batch (optional). |
| 211 | |
| 212 | Shape: |
| 213 | see the docs in Transformer class. |
| 214 | """ |
| 215 | output = src |
| 216 | output_weights_list = [] |
| 217 | for mod in self.layers: |
| 218 | output, output_weights = mod(output, src_mask=mask, src_key_padding_mask=src_key_padding_mask) |
| 219 | output_weights_list.append(output_weights) # () |
| 220 | |
| 221 | if self.norm is not None: |
| 222 | output = self.norm(output) |
| 223 | |
| 224 | # Rick: potential improvement, not used during training, saved as list of tensor |
| 225 | output_weights = torch.stack(output_weights_list, dim=-1) |
| 226 | |
| 227 | return output, output_weights |
| 228 | |
| 229 | |
| 230 | def _get_clones(module, N): |
nothing calls this directly
no outgoing calls
no test coverage detected