(
self,
tgt,
memory,
tgt_mask: Optional[Tensor] = None,
memory_mask: Optional[Tensor] = None,
tgt_key_padding_mask: Optional[Tensor] = None,
memory_key_padding_mask: Optional[Tensor] = None,
pos: Optional[Tensor] = None,
query_pos: Optional[Tensor] = None,
)
| 111 | self.return_intermediate = return_intermediate |
| 112 | |
| 113 | def forward( |
| 114 | self, |
| 115 | tgt, |
| 116 | memory, |
| 117 | tgt_mask: Optional[Tensor] = None, |
| 118 | memory_mask: Optional[Tensor] = None, |
| 119 | tgt_key_padding_mask: Optional[Tensor] = None, |
| 120 | memory_key_padding_mask: Optional[Tensor] = None, |
| 121 | pos: Optional[Tensor] = None, |
| 122 | query_pos: Optional[Tensor] = None, |
| 123 | ): |
| 124 | output = tgt |
| 125 | |
| 126 | intermediate = [] |
| 127 | |
| 128 | for layer in self.layers: |
| 129 | output = layer( |
| 130 | output, |
| 131 | memory, |
| 132 | tgt_mask=tgt_mask, |
| 133 | memory_mask=memory_mask, |
| 134 | tgt_key_padding_mask=tgt_key_padding_mask, |
| 135 | memory_key_padding_mask=memory_key_padding_mask, |
| 136 | pos=pos, |
| 137 | query_pos=query_pos, |
| 138 | ) |
| 139 | if self.return_intermediate: |
| 140 | intermediate.append(self.norm(output)) |
| 141 | |
| 142 | if self.norm is not None: |
| 143 | output = self.norm(output) |
| 144 | if self.return_intermediate: |
| 145 | intermediate.pop() |
| 146 | intermediate.append(output) |
| 147 | |
| 148 | if self.return_intermediate: |
| 149 | return torch.stack(intermediate) |
| 150 | |
| 151 | return output.unsqueeze(0) |
| 152 | |
| 153 | |
| 154 | class TransformerEncoderLayer(nn.Module): |
nothing calls this directly
no outgoing calls
no test coverage detected