The PanguAlpha network consisting of two parts the backbone and the head Args: config(PanguAlphaConfig): the config of network Inputs: input_ids: the tokenized inputs input_mask: the mask indicating whether each position is a valid input past: the previou
| 459 | |
| 460 | |
| 461 | class PanguAlphaModel(nn.Cell): |
| 462 | """ |
| 463 | The PanguAlpha network consisting of two parts the backbone and the head |
| 464 | Args: |
| 465 | config(PanguAlphaConfig): the config of network |
| 466 | Inputs: |
| 467 | input_ids: the tokenized inputs |
| 468 | input_mask: the mask indicating whether each position is a valid input |
| 469 | past: the previous feature map |
| 470 | Returns: |
| 471 | logits: Tensor: the logits of the corresponding inputs with shape (batch_size, seq_length, vocab_size) |
| 472 | """ |
| 473 | |
| 474 | def __init__(self, config): |
| 475 | super(PanguAlphaModel, self).__init__() |
| 476 | # Network head to get logits over vocabulary |
| 477 | copied_parallel_config = copy.deepcopy(config.parallel_config) |
| 478 | if copied_parallel_config.pipeline_stage > 1: |
| 479 | copied_parallel_config.vocab_emb_dp = False |
| 480 | self.head = PanGuHead( |
| 481 | hidden_size=config.hidden_size, |
| 482 | parallel_config=copied_parallel_config, |
| 483 | ) |
| 484 | self.head.pipeline_stage = config.parallel_config.pipeline_stage - 1 |
| 485 | self.backbone = PanguAlpha_Model(config) |
| 486 | self.backbone.embedding.word_embedding.embedding_table.add_pipeline_stage(self.head.pipeline_stage) |
| 487 | |
| 488 | def construct(self, input_ids, input_position, attention_mask, |
| 489 | init_reset=True, batch_valid_length=None): |
| 490 | output_states, word_table = self.backbone(input_ids, input_position, attention_mask, |
| 491 | init_reset, batch_valid_length) |
| 492 | logits = self.head(output_states, word_table) |
| 493 | return logits |
| 494 | |
| 495 | |
| 496 | class PanGUAlphaWithLoss(Cell): |
no outgoing calls
no test coverage detected