(
self,
hidden_states,
query_hidden_state,
attention_mask,
layer_past=None,
get_key_value=False,
prompt_length=None,
context_length=None,
)
| 609 | return self.layers[self._get_layer_index(layer_number)] |
| 610 | |
| 611 | def forward( |
| 612 | self, |
| 613 | hidden_states, |
| 614 | query_hidden_state, |
| 615 | attention_mask, |
| 616 | layer_past=None, |
| 617 | get_key_value=False, |
| 618 | prompt_length=None, |
| 619 | context_length=None, |
| 620 | ): |
| 621 | # data format change to avoid explicit tranposes : [b s h] --> [s b h] |
| 622 | hidden_states = hidden_states.transpose(0, 1).contiguous() |
| 623 | query_hidden_state = query_hidden_state.transpose(0, 1).contiguous() |
| 624 | |
| 625 | |
| 626 | if get_key_value: |
| 627 | presents = [] |
| 628 | for index in range(self.num_layers): |
| 629 | layer = self._get_layer(index) |
| 630 | past = None |
| 631 | if layer_past is not None: |
| 632 | past = layer_past[index] |
| 633 | hidden_states = layer(hidden_states, |
| 634 | attention_mask, |
| 635 | layer_past=past, |
| 636 | get_key_value=get_key_value, |
| 637 | prompt_length=prompt_length, |
| 638 | context_length=context_length) |
| 639 | if get_key_value: |
| 640 | hidden_states, present = hidden_states |
| 641 | presents.append(present) |
| 642 | |
| 643 | # Use FP32 for Layernorm |
| 644 | # hidden_states_ = self.final_layernorm(hidden_states.float()).half() |
| 645 | hidden_states_ = self.final_layernorm(hidden_states) |
| 646 | |
| 647 | ################################# |
| 648 | # top query layer |
| 649 | ################################# |
| 650 | past = None |
| 651 | if layer_past is not None: |
| 652 | past = layer_past[self.num_layers] |
| 653 | hidden_states = self.topQueryLayer(hidden_states_, |
| 654 | query_hidden_state, |
| 655 | attention_mask, |
| 656 | layer_past=past, |
| 657 | get_key_value=get_key_value, |
| 658 | prompt_length=prompt_length, |
| 659 | context_length=context_length) |
| 660 | |
| 661 | if get_key_value: |
| 662 | hidden_states, present = hidden_states |
| 663 | presents.append(present) |
| 664 | |
| 665 | # reverting data format change [s b h] --> [b s h] |
| 666 | output = hidden_states.transpose(0, 1).contiguous() |
| 667 | |
| 668 | if get_key_value: |
nothing calls this directly
no test coverage detected