(
self,
hidden_states,
query_hidden_state,
attention_mask,
layer_past=None,
get_key_value=False,
prompt_length=None,
context_length=None,
)
| 512 | self.mlp = MLP(self.hidden_size) |
| 513 | |
| 514 | def forward( |
| 515 | self, |
| 516 | hidden_states, |
| 517 | query_hidden_state, |
| 518 | attention_mask, |
| 519 | layer_past=None, |
| 520 | get_key_value=False, |
| 521 | prompt_length=None, |
| 522 | context_length=None, |
| 523 | ): |
| 524 | # hidden_states: [b, s, h] |
| 525 | assert query_hidden_state != None |
| 526 | |
| 527 | # Use FP32 for Layernorm |
| 528 | # layernorm_output = self.input_layernorm(hidden_states.float()).half() |
| 529 | layernorm_output = self.input_layernorm(hidden_states) |
| 530 | |
| 531 | # Self attention. |
| 532 | attention_output = self.attention(layernorm_output, |
| 533 | query_hidden_state, |
| 534 | attention_mask, |
| 535 | layer_past=layer_past, |
| 536 | get_key_value=get_key_value, |
| 537 | prompt_length=prompt_length, |
| 538 | context_length=context_length) |
| 539 | |
| 540 | if get_key_value: |
| 541 | attention_output, presents = attention_output |
| 542 | |
| 543 | # Residual connection. |
| 544 | residual = hidden_states |
| 545 | layernorm_input = attention_output + residual |
| 546 | |
| 547 | # Use FP32 for Layernorm |
| 548 | # layernorm_output = self.post_attention_layernorm(layernorm_input.float()).half() |
| 549 | layernorm_output = self.post_attention_layernorm(layernorm_input) |
| 550 | |
| 551 | # MLP. |
| 552 | mlp_output = self.mlp(layernorm_output) |
| 553 | |
| 554 | # Second residual connection. |
| 555 | residual = layernorm_input |
| 556 | output = mlp_output + residual |
| 557 | |
| 558 | if get_key_value: |
| 559 | output = [output, presents] |
| 560 | |
| 561 | return output |
| 562 | |
| 563 | |
| 564 | class Transformer(torch.nn.Module): |
nothing calls this directly
no outgoing calls
no test coverage detected