def hybrid_forward(self, F, inputs, states=None, valid_length=None, position_weight=None):<EOL>
if states is not None:<EOL><INDENT>steps = states[-<NUM_LIT:1>]<EOL>positional_embed = F.Embedding(steps, position_weight, self._max_length, self._units)<EOL>inputs = F.broadcast_add(inputs, F.expand_dims(positional_embed, axis=<NUM_LIT:0>))<EOL><DEDENT>if self._dropout:<EOL><INDENT>if self._use_layer_norm_before_dropout:<EOL><INDENT>inputs = self.layer_norm(inputs)<EOL>inputs = self.dropout_layer(inputs)<EOL><DEDENT>else:<EOL><INDENT>inputs = self.dropout_layer(inputs)<EOL>inputs = self.layer_norm(inputs)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>inputs = self.layer_norm(inputs)<EOL><DEDENT>outputs = inputs<EOL>if valid_length is not None:<EOL><INDENT>mask = states[-<NUM_LIT:2>]<EOL><DEDENT>else:<EOL><INDENT>mask = None<EOL><DEDENT>all_encodings_outputs = []<EOL>additional_outputs = []<EOL>for cell in self.transformer_cells:<EOL><INDENT>outputs, attention_weights = cell(inputs, mask)<EOL>inputs = outputs<EOL>if self._output_all_encodings:<EOL><INDENT>if valid_length is not None:<EOL><INDENT>outputs = F.SequenceMask(outputs, sequence_length=valid_length,<EOL>use_sequence_length=True, axis=<NUM_LIT:1>)<EOL><DEDENT>all_encodings_outputs.append(outputs)<EOL><DEDENT>if self._output_attention:<EOL><INDENT>additional_outputs.append(attention_weights)<EOL><DEDENT><DEDENT>if valid_length is not None:<EOL><INDENT>outputs = F.SequenceMask(outputs, sequence_length=valid_length,<EOL>use_sequence_length=True, axis=<NUM_LIT:1>)<EOL><DEDENT>if self._output_all_encodings:<EOL><INDENT>return all_encodings_outputs, additional_outputs<EOL><DEDENT>else:<EOL><INDENT>return outputs, additional_outputs<EOL><DEDENT>
Parameters
----------
inputs : NDArray or Symbol, Shape(batch_size, length, C_in)
states : list of NDArray or Symbol
valid_length : NDArray or Symbol
position_weight : NDArray or Symbol

Returns
-------
outputs : NDArray or Symbol, or List[NDArray] or List[Symbol]
    If output_all_encodings flag is False, then the output of the last encoder.
    If output_all_encodings flag is True, then the list of all outputs of all encoders.
    In both cases, shape of the tensor(s) is/are (batch_size, length, C_out)
additional_outputs : list
    Either be an empty list or contains the attention weights in this step.
    The attention weights will have shape (batch_size, length, length) or
    (batch_size, num_heads, length, length)