def forward(self, input_states, attention_mask, head_mask=None, output_all_states=False, output_attentions=False, keep_multihead_output=False):
    all_states = []
    all_attention_probs = []
    hidden_states = input_states
    for layer in self.layers:
        hidden_states = layer(hidden_states, attention_mask, head_mask=head_mask, output_attentions=output_attentions)
        if output_attentions:
            (hidden_states, attention_probs) = hidden_states
            all_attention_probs.append(attention_probs)
        if output_all_states:
            all_states.append(hidden_states)
    if (not output_all_states):
        all_states.append(hidden_states)
    if output_attentions:
        return (all_states, all_attention_probs)
    return all_states
def forward(self, input_states, attention_mask, head_mask=None, output_all_states=False, output_attentions=False, keep_multihead_output=False):
    all_states = []
    all_attention_probs = []
    hidden_states = input_states
    for layer in self.layers:
        hidden_states = layer(hidden_states, attention_mask, head_mask=head_mask, output_attentions=output_attentions)
        if output_attentions:
            (hidden_states, attention_probs) = hidden_states
            all_attention_probs.append(attention_probs)
        if output_all_states:
            all_states.append(hidden_states)
    if (not output_all_states):
        all_states.append(hidden_states)
    if output_attentions:
        return (all_states, all_attention_probs)
    return all_states