MCPcopy Create free account
hub / github.com/zai-org/CodeGeeX / forward

Method forward

codegeex/oneflow/codegeex_model.py:704–765  ·  view source on GitHub ↗
(
        self,
        hidden_states,
        query_hidden_state,
        attention_mask,
        layer_past=None,
        get_key_value=False,
        prompt_length=None,
        context_length=None,
    )

Source from the content-addressed store, hash-verified

702 return self.layers[self._get_layer_index(layer_number)]
703
704 def forward(
705 self,
706 hidden_states,
707 query_hidden_state,
708 attention_mask,
709 layer_past=None,
710 get_key_value=False,
711 prompt_length=None,
712 context_length=None,
713 ):
714 # data format change to avoid explicit tranposes : [b s h] --> [s b h]
715 hidden_states = hidden_states.transpose(0, 1).contiguous()
716 query_hidden_state = query_hidden_state.transpose(0, 1).contiguous()
717
718 origin_attention_mask = attention_mask
719 if get_key_value:
720 presents = []
721 for index in range(self.num_layers):
722 layer = self._get_layer(index)
723 past = None
724 if layer_past is not None:
725 past = layer_past[index]
726 hidden_states, attention_mask = layer(hidden_states,
727 attention_mask,
728 layer_past=past,
729 get_key_value=get_key_value,
730 prompt_length=prompt_length,
731 context_length=context_length,
732 layer_id=index)
733 if get_key_value:
734 hidden_states, present = hidden_states
735 presents.append(present)
736
737 # Use FP32 for Layernorm
738 # hidden_states_ = self.final_layernorm(hidden_states.float()).half()
739 hidden_states_ = self.final_layernorm(hidden_states)
740
741 #################################
742 # top query layer
743 #################################
744 past = None
745 if layer_past is not None:
746 past = layer_past[self.num_layers]
747 hidden_states = self.topQueryLayer(hidden_states_,
748 query_hidden_state,
749 origin_attention_mask,
750 layer_past=past,
751 get_key_value=get_key_value,
752 prompt_length=prompt_length,
753 context_length=context_length)
754
755 if get_key_value:
756 hidden_states, present = hidden_states
757 presents.append(present)
758
759 # reverting data format change [s b h] --> [b s h]
760 output = hidden_states.transpose(0, 1).contiguous()
761

Callers

nothing calls this directly

Calls 1

_get_layerMethod · 0.95

Tested by

no test coverage detected