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