




import argparse

import torch

from transformers import ElectraConfig, ElectraForMaskedLM, ElectraForPreTraining, load_tf_weights_in_electra
from transformers.utils import logging


logging.set_verbosity_info()



def      UpperCAmelCase_   (     __UpperCamelCase,    __UpperCamelCase,    __UpperCamelCase,    __UpperCamelCase     ):
    # Initialise PyTorch model
    SCREAMING_SNAKE_CASE__       =ElectraConfig.from_json_file(__UpperCamelCase     )
    print(f"""Building PyTorch model from configuration: {config}"""     )

    if discriminator_or_generator == "discriminator":
        SCREAMING_SNAKE_CASE__       =ElectraForPreTraining(__UpperCamelCase     )
    elif discriminator_or_generator == "generator":
        SCREAMING_SNAKE_CASE__       =ElectraForMaskedLM(__UpperCamelCase     )
    else:
        raise ValueError("""The discriminator_or_generator argument should be either 'discriminator' or 'generator'"""     )

    # Load weights from tf checkpoint
    load_tf_weights_in_electra(
        __UpperCamelCase,    __UpperCamelCase,    __UpperCamelCase,    discriminator_or_generator=__UpperCamelCase     )

    # Save pytorch-model
    print(f"""Save PyTorch model to {pytorch_dump_path}"""     )
    torch.save(model.state_dict(),    __UpperCamelCase     )


if __name__ == "__main__":
    lowerCamelCase_  						=       argparse.ArgumentParser()
    # Required parameters
    parser.add_argument(
        "--tf_checkpoint_path", default=None, type=str, required=True, help="Path to the TensorFlow checkpoint path."
    )
    parser.add_argument(
        "--config_file",
        default=None,
        type=str,
        required=True,
        help="The config json file corresponding to the pre-trained model. \nThis specifies the model architecture.",
    )
    parser.add_argument(
        "--pytorch_dump_path", default=None, type=str, required=True, help="Path to the output PyTorch model."
    )
    parser.add_argument(
        "--discriminator_or_generator",
        default=None,
        type=str,
        required=True,
        help=(
            "Whether to export the generator or the discriminator. Should be a string, either 'discriminator' or "
            "'generator'."
        ),
    )
    lowerCamelCase_  						=       parser.parse_args()
    convert_tf_checkpoint_to_pytorch(
        args.tf_checkpoint_path, args.config_file, args.pytorch_dump_path, args.discriminator_or_generator
    )












def      UpperCAmelCase_   (     __UpperCamelCase,    __UpperCamelCase     ):
    SCREAMING_SNAKE_CASE__       =len(__UpperCamelCase     )
    # Create a stack and push index of fist element to it
    SCREAMING_SNAKE_CASE__       =[]
    st.append(0     )

    # Span value of first element is always 1
    SCREAMING_SNAKE_CASE__       =1

    # Calculate span values for rest of the elements
    for i in range(1,    __UpperCamelCase     ):
        # Pop elements from stack while stack is not
        # empty and top of stack is smaller than price[i]
        while len(__UpperCamelCase     ) > 0 and price[st[0]] <= price[i]:
            st.pop()

        # If stack becomes empty, then price[i] is greater
        # than all elements on left of it, i.e. price[0],
        # price[1], ..price[i-1]. Else the price[i]  is
        # greater than elements after top of stack
        SCREAMING_SNAKE_CASE__       =i + 1 if len(__UpperCamelCase     ) <= 0 else (i - st[0])

        # Push this element to stack
        st.append(__UpperCamelCase     )



def      UpperCAmelCase_   (     __UpperCamelCase,    __UpperCamelCase     ):
    for i in range(0,    __UpperCamelCase     ):
        print(arr[i],    end=""" """     )


# Driver program to test above function
lowerCamelCase_  						=       [10, 4, 5, 90, 120, 80]
lowerCamelCase_  						=       [0 for i in range(len(price) + 1)]

# Fill the span values in array S[]
calculation_span(price, S)




print_array(S, len(price))






