



'''simple docstring'''





_UpperCamelCase											=		'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'

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

  __lowerCamelCase			:			Optional[Any]       			=					''.join(bin(_lowerCAmelCase			)[2:].zfill(8			) for byte in data			)

  __lowerCamelCase			:			Any       			=					len(_lowerCAmelCase			) % 6 != 0

  if padding_needed:
    # The padding that will be added later
    __lowerCamelCase			:			Any       			=					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			:			List[Any]       			=					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 			a_	(				_lowerCAmelCase			) -> bytes:
  # Make sure encoded_data is either a string or a bytes-like object
  if not isinstance(_lowerCAmelCase			,_lowerCAmelCase			) and not isinstance(_lowerCAmelCase			,_lowerCAmelCase			):
    __lowerCamelCase			:			Tuple       			=					(
        '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			:			Dict       			=					encoded_data.decode('utf-8'			)
    except UnicodeDecodeError:
      raise ValueError('base64 encoded data should only contain ASCII characters'			)

  __lowerCamelCase			:			Optional[int]       			=					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			:			Dict       			=					encoded_data[:-padding]

    __lowerCamelCase			:			Optional[Any]       			=					''.join(
        bin(B64_CHARSET.index(_lowerCAmelCase			)			)[2:].zfill(6			) for char in encoded_data			)[: -padding * 2]
  else:
    __lowerCamelCase			:			Tuple       			=					''.join(
        bin(B64_CHARSET.index(_lowerCAmelCase			)			)[2:].zfill(6			) for char in encoded_data			)

  __lowerCamelCase			:			Tuple       			=					[
      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()











'''simple docstring'''





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


_UpperCamelCase											=		logging.get_logger(__name__)

_UpperCamelCase											=		{
    'google/pegasus-large': 'https://huggingface.co/google/pegasus-large/resolve/main/config.json',
    # See all PEGASUS models at https://huggingface.co/models?filter=pegasus
}






class    lowerCamelCase_       (							SCREAMING_SNAKE_CASE_	):
  """simple docstring"""




  a_				   ="""pegasus"""
  a_				   =["""past_key_values"""]
  a_				   ={"""num_attention_heads""": """encoder_attention_heads""", """hidden_size""": """d_model"""}




  def __init__(					self :      Any     ,      _a :      int=5_0265     ,      _a :      Tuple=1024     ,      _a :      Optional[Any]=12     ,      _a :      int=4096     ,      _a :      str=16     ,      _a :      Union[str, Any]=12     ,      _a :      Optional[Any]=4096     ,      _a :      Optional[int]=16     ,      _a :      Union[str, Any]=0.0     ,      _a :      str=0.0     ,      _a :      List[Any]=True     ,      _a :      Optional[int]=True     ,      _a :      Tuple="gelu"     ,      _a :      Dict=1024     ,      _a :      int=0.1     ,      _a :      Any=0.0     ,      _a :      Union[str, Any]=0.0     ,      _a :      Any=0.02     ,      _a :      Optional[Any]=0     ,      _a :      str=False     ,      _a :      Tuple=0     ,      _a :      Optional[int]=1     ,      _a :      Union[str, Any]=1     ,      **_a :      Optional[int]     ,      )   ->   Any:
    __lowerCamelCase			:			Union[str, Any]       			=					vocab_size
    __lowerCamelCase			:			int       			=					max_position_embeddings
    __lowerCamelCase			:			Union[str, Any]       			=					d_model
    __lowerCamelCase			:			Union[str, Any]       			=					encoder_ffn_dim
    __lowerCamelCase			:			Union[str, Any]       			=					encoder_layers
    __lowerCamelCase			:			List[Any]       			=					encoder_attention_heads
    __lowerCamelCase			:			Optional[int]       			=					decoder_ffn_dim
    __lowerCamelCase			:			int       			=					decoder_layers
    __lowerCamelCase			:			Tuple       			=					decoder_attention_heads
    __lowerCamelCase			:			Optional[Any]       			=					dropout
    __lowerCamelCase			:			Tuple       			=					attention_dropout
    __lowerCamelCase			:			int       			=					activation_dropout
    __lowerCamelCase			:			Dict       			=					activation_function
    __lowerCamelCase			:			List[Any]       			=					init_std
    __lowerCamelCase			:			List[str]       			=					encoder_layerdrop
    __lowerCamelCase			:			Union[str, Any]       			=					decoder_layerdrop
    __lowerCamelCase			:			Union[str, Any]       			=					use_cache
    __lowerCamelCase			:			Tuple       			=					encoder_layers
    __lowerCamelCase			:			int       			=					scale_embedding  # scale factor will be sqrt(d_model) if True
    super().__init__(
        pad_token_id=_a     ,      eos_token_id=_a     ,      is_encoder_decoder=_a     ,      decoder_start_token_id=_a     ,      forced_eos_token_id=_a     ,      **_a     ,      )




  @property
  def 		_lowercase	(					self :      Optional[int]  )   ->   int:
    return self.encoder_attention_heads




  @property
  def 		_lowercase	(					self :      Any  )   ->   int:
    return self.d_model






