MCPcopy Create free account
hub / github.com/THUDM/GLM / forward

Method forward

mpu/transformer.py:563–581  ·  view source on GitHub ↗
(self, hidden_states, ltor_mask, position_embeddings=None, r_w_bias=None, r_r_bias=None, mem=None)

Source from the content-addressed store, hash-verified

561 output_layer_init_method=output_layer_init_method)
562
563 def forward(self, hidden_states, ltor_mask, position_embeddings=None, r_w_bias=None, r_r_bias=None, mem=None):
564 # hidden_states: [b, s, h]
565 # ltor_mask: [1, 1, s, s]
566
567 # Layer norm at the begining of the transformer layer.
568 layernorm_output = self.input_layernorm(hidden_states)
569 mem = self.input_layernorm(mem) if mem is not None else None
570 # Self attention.
571 attention_output = self.attention(layernorm_output, ltor_mask, position_embeddings, r_w_bias, r_r_bias, mem)
572 # Residual connection.
573 layernorm_input = hidden_states + attention_output
574 # Layer norm post the self attention.
575 layernorm_output = self.post_attention_layernorm(layernorm_input)
576 # MLP.
577 mlp_output = self.mlp(layernorm_output)
578 # Second residual connection.
579 output = layernorm_input + mlp_output
580
581 return output
582
583
584def unscaled_init_method(sigma):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected