from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowerCAmelCase__     						=			logging.get_logger(__name__)

lowerCAmelCase__     						=			{
    'facebook/s2t-wav2vec2-large-en-de': (
        'https://huggingface.co/facebook/s2t-wav2vec2-large-en-de/resolve/main/config.json'
    ),
    # See all Speech2Text models at https://huggingface.co/models?filter=speech2text2
}
class     a_			(						SCREAMING_SNAKE_CASE						):






 '''simple docstring'''






 UpperCAmelCase_     			= 'speech_to_text_2'
 UpperCAmelCase_     			= ['past_key_values']
 UpperCAmelCase_     			= {'num_attention_heads': 'decoder_attention_heads', 'hidden_size': 'd_model'}




 def __init__(      self :  Tuple      ,   lowercase__ :  List[str]=10_000      ,   lowercase__ :  int=6      ,   lowercase__ :  List[Any]=2_048      ,   lowercase__ :  str=4      ,   lowercase__ :  Dict=0.0      ,   lowercase__ :  Any=True      ,   lowercase__ :  Optional[int]="relu"      ,   lowercase__ :  Optional[Any]=256      ,   lowercase__ :  Union[str, Any]=0.1      ,   lowercase__ :  Optional[int]=0.0      ,   lowercase__ :  Optional[int]=0.0      ,   lowercase__ :  int=0.02      ,   lowercase__ :  Dict=2      ,   lowercase__ :  int=True      ,   lowercase__ :  Union[str, Any]=1      ,   lowercase__ :  Union[str, Any]=0      ,   lowercase__ :  Optional[int]=2      ,   lowercase__ :  List[str]=1_024      ,   **lowercase__ :  str      ,   ):







        '''simple docstring'''



        lowerCAmelCase__					     = vocab_size
        lowerCAmelCase__					     = d_model
        lowerCAmelCase__					     = decoder_ffn_dim
        lowerCAmelCase__					     = decoder_layers
        lowerCAmelCase__					     = decoder_attention_heads
        lowerCAmelCase__					     = dropout
        lowerCAmelCase__					     = attention_dropout
        lowerCAmelCase__					     = activation_dropout
        lowerCAmelCase__					     = activation_function
        lowerCAmelCase__					     = init_std
        lowerCAmelCase__					     = decoder_layerdrop
        lowerCAmelCase__					     = use_cache
        lowerCAmelCase__					     = decoder_layers
        lowerCAmelCase__					     = scale_embedding  # scale factor will be sqrt(d_model) if True
        lowerCAmelCase__					     = max_target_positions

        super().__init__(
            pad_token_id=lowercase__      ,   bos_token_id=lowercase__      ,   eos_token_id=lowercase__      ,   decoder_start_token_id=lowercase__      ,   **lowercase__      ,   )

lowerCAmelCase__     						=			'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'






def 				__lowerCamelCase		(						lowerCAmelCase__     ):
       # Make sure the supplied data is a bytes-like object
       if not isinstance(lowerCAmelCase__     ,  lowerCAmelCase__     ):
              lowerCAmelCase__					     = F"""a bytes-like object is required, not '{data.__class__.__name__}'"""
              raise TypeError(lowerCAmelCase__     )

       lowerCAmelCase__					     = ''.join(bin(lowerCAmelCase__     )[2:].zfill(8     ) for byte in data     )

       lowerCAmelCase__					     = len(lowerCAmelCase__     ) % 6 != 0

       if padding_needed:
              # The padding that will be added later
              lowerCAmelCase__					     = b'=' * ((6 - len(lowerCAmelCase__     ) % 6) // 2)

              # Append binary_stream with arbitrary binary digits (0's by default) to make its
              # length a multiple of 6.
              binary_stream += "0" * (6 - len(lowerCAmelCase__     ) % 6)
       else:
              lowerCAmelCase__					     = b''

       # Encode every 6 binary digits to their corresponding Base64 character
       return (
           "".join(
               B64_CHARSET[int(binary_stream[index : index + 6]     ,  2     )]
               for index in range(0     ,  len(lowerCAmelCase__     )     ,  6     )     ).encode()
           + padding
       )






def 				__lowerCamelCase		(						lowerCAmelCase__     ):
       # Make sure encoded_data is either a string or a bytes-like object
       if not isinstance(lowerCAmelCase__     ,  lowerCAmelCase__     ) and not isinstance(lowerCAmelCase__     ,  lowerCAmelCase__     ):
              lowerCAmelCase__					     = (
                  'argument should be a bytes-like object or ASCII string, '
                  F"""not '{encoded_data.__class__.__name__}'"""
              )
              raise TypeError(lowerCAmelCase__     )

       # In case encoded_data is a bytes-like object, make sure it contains only
       # ASCII characters so we convert it to a string object
       if isinstance(lowerCAmelCase__     ,  lowerCAmelCase__     ):
              try:
                     lowerCAmelCase__					     = encoded_data.decode('utf-8'     )
              except UnicodeDecodeError:
                     raise ValueError('base64 encoded data should only contain ASCII characters'     )

       lowerCAmelCase__					     = encoded_data.count('='     )

       # Check if the encoded string contains non base64 characters
       if padding:
              assert all(
                  char in B64_CHARSET for char in encoded_data[:-padding]     ), "Invalid base64 character(s) found."
       else:
              assert all(
                  char in B64_CHARSET for char in encoded_data     ), "Invalid base64 character(s) found."

       # Check the padding
       assert len(lowerCAmelCase__     ) % 4 == 0 and padding < 3, "Incorrect padding"

       if padding:
              # Remove padding if there is one
              lowerCAmelCase__					     = encoded_data[:-padding]

              lowerCAmelCase__					     = ''.join(
                  bin(B64_CHARSET.index(lowerCAmelCase__     )     )[2:].zfill(6     ) for char in encoded_data     )[: -padding * 2]
       else:
              lowerCAmelCase__					     = ''.join(
                  bin(B64_CHARSET.index(lowerCAmelCase__     )     )[2:].zfill(6     ) for char in encoded_data     )

       lowerCAmelCase__					     = [
           int(binary_stream[index : index + 8]     ,  2     )
           for index in range(0     ,  len(lowerCAmelCase__     )     ,  8     )
       ]

       return bytes(lowerCAmelCase__     )


if __name__ == "__main__":
    import doctest

    doctest.testmod()
