(self, input_ids, position_ids, attention_mask, labels=None,
tokentype_ids=None, layer_past=None, get_key_value=False,
forward_method_parallel_output=None, curriculum_seqlen=None)
| 53 | |
| 54 | |
| 55 | def forward(self, input_ids, position_ids, attention_mask, labels=None, |
| 56 | tokentype_ids=None, layer_past=None, get_key_value=False, |
| 57 | forward_method_parallel_output=None, curriculum_seqlen=None): |
| 58 | args = get_args() |
| 59 | if curriculum_seqlen is not None: |
| 60 | args.curriculum_seqlen = curriculum_seqlen |
| 61 | if curriculum_seqlen < input_ids.size()[1]: |
| 62 | # seqlen-based curriculum learning |
| 63 | # input_ids, position_ids, labels have size [batch size, seqlen] |
| 64 | input_ids = input_ids[:, :curriculum_seqlen].contiguous() |
| 65 | position_ids = position_ids[:, :curriculum_seqlen].contiguous() |
| 66 | labels = labels[:, :curriculum_seqlen].contiguous() |
| 67 | |
| 68 | # attention_mask has size [1, 1, seqlen, seqlen] |
| 69 | attention_mask = attention_mask[:, :, :curriculum_seqlen, :curriculum_seqlen].contiguous() |
| 70 | raise NotImplementedError |
| 71 | else: |
| 72 | if args.curriculum_learning: |
| 73 | # If got a None input, need to reset curriculum_seqlen on user side |
| 74 | args.curriculum_seqlen = args.seq_length |
| 75 | |
| 76 | # Language model. |
| 77 | lm_output = self.language_model(input_ids, |
| 78 | position_ids, |
| 79 | attention_mask, |
| 80 | tokentype_ids=tokentype_ids, |
| 81 | layer_past=layer_past, |
| 82 | get_key_value=get_key_value) |
| 83 | |
| 84 | if get_key_value: |
| 85 | lm_output, presents = lm_output |
| 86 | |
| 87 | # Output. |
| 88 | parallel_output = self.parallel_output |
| 89 | if forward_method_parallel_output is not None: |
| 90 | parallel_output = forward_method_parallel_output |
| 91 | |
| 92 | output = parallel_lm_logits( |
| 93 | lm_output, |
| 94 | self.language_model.embedding.word_embeddings.weight, |
| 95 | parallel_output) |
| 96 | |
| 97 | if get_key_value: |
| 98 | output = [output, presents] |
| 99 | |
| 100 | if labels is None: |
| 101 | return output |
| 102 | else: |
| 103 | if self.fp16_lm_cross_entropy: |
| 104 | assert output.dtype == torch.half |
| 105 | loss = mpu.vocab_parallel_cross_entropy(output, labels) |
| 106 | else: |
| 107 | loss = mpu.vocab_parallel_cross_entropy(output.float(), labels) |
| 108 | return loss |
| 109 | |
| 110 | |
| 111 | def state_dict_for_save_checkpoint(self, destination=None, prefix='', |
nothing calls this directly
no test coverage detected