(
self, hidden_states, attention_mask, rotary_pos_emb, kv_cache=None, use_cache=True,
)
| 792 | self.mlp = MLP(config, device=device) |
| 793 | |
| 794 | def forward( |
| 795 | self, hidden_states, attention_mask, rotary_pos_emb, kv_cache=None, use_cache=True, |
| 796 | ): |
| 797 | # hidden_states: [s, b, h] |
| 798 | |
| 799 | # Layer norm at the beginning of the transformer layer. |
| 800 | layernorm_output = self.input_layernorm(hidden_states) |
| 801 | # Self attention. |
| 802 | attention_output, kv_cache = self.self_attention( |
| 803 | layernorm_output, |
| 804 | attention_mask, |
| 805 | rotary_pos_emb, |
| 806 | kv_cache=kv_cache, |
| 807 | use_cache=use_cache |
| 808 | ) |
| 809 | |
| 810 | # Residual connection. |
| 811 | if self.apply_residual_connection_post_layernorm: |
| 812 | residual = layernorm_output |
| 813 | else: |
| 814 | residual = hidden_states |
| 815 | |
| 816 | layernorm_input = torch.nn.functional.dropout(attention_output, p=self.hidden_dropout, training=self.training) |
| 817 | layernorm_input = residual + layernorm_input |
| 818 | |
| 819 | # Layer norm post the self attention. |
| 820 | layernorm_output = self.post_attention_layernorm(layernorm_input) |
| 821 | |
| 822 | # MLP. |
| 823 | mlp_output = self.mlp(layernorm_output) |
| 824 | |
| 825 | # Second residual connection. |
| 826 | if self.apply_residual_connection_post_layernorm: |
| 827 | residual = layernorm_output |
| 828 | else: |
| 829 | residual = layernorm_input |
| 830 | |
| 831 | output = torch.nn.functional.dropout(mlp_output, p=self.hidden_dropout, training=self.training) |
| 832 | output = residual + output |
| 833 | |
| 834 | return output, kv_cache |
| 835 | |
| 836 | |
| 837 | class GLMTransformer(torch.nn.Module): |
nothing calls this directly
no outgoing calls
no test coverage detected