| 272 | |
| 273 | class EmbeddingPipe(Embedding): |
| 274 | def forward(self, inputs, **kwargs): |
| 275 | if not hasattr(self, "_args"): |
| 276 | self._args = get_args() |
| 277 | |
| 278 | input_ids = inputs[0] |
| 279 | position_ids = inputs[1] |
| 280 | if hasattr(self._args, "attn_mask"): |
| 281 | attention_mask = None |
| 282 | else: |
| 283 | attention_mask = inputs[2] |
| 284 | |
| 285 | if len(inputs) == 4: |
| 286 | tokentype_ids = inputs[3] |
| 287 | else: |
| 288 | tokentype_ids = None |
| 289 | |
| 290 | embeddings = super().forward( |
| 291 | input_ids, position_ids, tokentype_ids=tokentype_ids |
| 292 | ) |
| 293 | |
| 294 | # If cmd args has attn_mask, we don't forward it as an activation. |
| 295 | if hasattr(self._args, "attn_mask"): |
| 296 | return embeddings |
| 297 | else: |
| 298 | assert False |
| 299 | return embeddings, attention_mask |
| 300 | |
| 301 | @property |
| 302 | def word_embeddings_weight(self): |