


'''simple docstring'''



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


_lowercase     :     Dict        =	logging.get_logger(__name__)

_lowercase     :     Optional[int]        =	{
    """facebook/s2t-small-librispeech-asr""": (
        """https://huggingface.co/facebook/s2t-small-librispeech-asr/resolve/main/config.json"""
    ),
    # See all Speech2Text models at https://huggingface.co/models?filter=speech_to_text
}






class 			UpperCamelCase__(  _snake_case			):
				__magic_name__							: Tuple    						=			"speech_to_text"
				__magic_name__							: Any    						=			["past_key_values"]
				__magic_name__							: Optional[Any]    						=			{"num_attention_heads": "encoder_attention_heads", "hidden_size": "d_model"}




				def __init__(						self     :					int ,       lowerCAmelCase     :					Dict=10000 ,       lowerCAmelCase     :					str=12 ,       lowerCAmelCase     :					Dict=2048 ,       lowerCAmelCase     :					int=4 ,       lowerCAmelCase     :					Optional[Any]=6 ,       lowerCAmelCase     :					str=2048 ,       lowerCAmelCase     :					Optional[Any]=4 ,       lowerCAmelCase     :					Dict=0.0 ,       lowerCAmelCase     :					List[str]=0.0 ,       lowerCAmelCase     :					Union[str, Any]=True ,       lowerCAmelCase     :					int=True ,       lowerCAmelCase     :					List[str]="relu" ,       lowerCAmelCase     :					Dict=256 ,       lowerCAmelCase     :					List[Any]=0.1 ,       lowerCAmelCase     :					str=0.0 ,       lowerCAmelCase     :					Tuple=0.0 ,       lowerCAmelCase     :					Dict=0.02 ,       lowerCAmelCase     :					List[Any]=2 ,       lowerCAmelCase     :					int=True ,       lowerCAmelCase     :					int=1 ,       lowerCAmelCase     :					Dict=0 ,       lowerCAmelCase     :					int=2 ,       lowerCAmelCase     :					Dict=6000 ,       lowerCAmelCase     :					List[str]=1024 ,       lowerCAmelCase     :					List[Any]=2 ,       lowerCAmelCase     :					List[str]=(5, 5) ,       lowerCAmelCase     :					Optional[int]=1024 ,       lowerCAmelCase     :					Optional[int]=80 ,       lowerCAmelCase     :					Optional[Any]=1 ,       **lowerCAmelCase     :					Optional[int] ,       )->	Dict:

										"""simple docstring"""




										UpperCAmelCase								=      vocab_size
										UpperCAmelCase								=      d_model
										UpperCAmelCase								=      encoder_ffn_dim
										UpperCAmelCase								=      encoder_layers
										UpperCAmelCase								=      encoder_attention_heads
										UpperCAmelCase								=      decoder_ffn_dim
										UpperCAmelCase								=      decoder_layers
										UpperCAmelCase								=      decoder_attention_heads
										UpperCAmelCase								=      dropout
										UpperCAmelCase								=      attention_dropout
										UpperCAmelCase								=      activation_dropout
										UpperCAmelCase								=      activation_function
										UpperCAmelCase								=      init_std
										UpperCAmelCase								=      encoder_layerdrop
										UpperCAmelCase								=      decoder_layerdrop
										UpperCAmelCase								=      use_cache
										UpperCAmelCase								=      encoder_layers
										UpperCAmelCase								=      scale_embedding  # scale factor will be sqrt(d_model) if True
										UpperCAmelCase								=      max_source_positions
										UpperCAmelCase								=      max_target_positions
										UpperCAmelCase								=      num_conv_layers
										UpperCAmelCase								=      list(UpperCamelCase__ )
										UpperCAmelCase								=      conv_channels
										UpperCAmelCase								=      input_feat_per_channel
										UpperCAmelCase								=      input_channels

										if len(self.conv_kernel_sizes ) != self.num_conv_layers:
																raise ValueError(
																    '''Configuration for convolutional module is incorrect. '''
																    '''It is required that `len(config.conv_kernel_sizes)` == `config.num_conv_layers` '''
																    F"""but is `len(config.conv_kernel_sizes) = {len(self.conv_kernel_sizes )}`, """
																    F"""`config.num_conv_layers = {self.num_conv_layers}`.""" )

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








'''simple docstring'''







import numpy as np
def    UpperCAmelCase__     (   UpperCAmelCase__,							UpperCAmelCase__,							UpperCAmelCase__ = 1e-12,							UpperCAmelCase__ = 1_00,							)      ->      tuple[float, np.ndarray]:
       assert np.shape(UpperCAmelCase__					)[0] == np.shape(UpperCAmelCase__					)[1]
       # Ensure proper dimensionality.
       assert np.shape(UpperCAmelCase__					)[0] == np.shape(UpperCAmelCase__					)[0]
       # Ensure inputs are either both complex or both real
       assert np.iscomplexobj(UpperCAmelCase__					) == np.iscomplexobj(UpperCAmelCase__					)
       A_						       =   np.iscomplexobj(UpperCAmelCase__					)
       if is_complex:
              # Ensure complex input_matrix is Hermitian
              assert np.array_equal(UpperCAmelCase__,							input_matrix.conj().T					)

       # Set convergence to False. Will define convergence when we exceed max_iterations
       # or when we have small changes from one iteration to next.

       A_						       =   False
       A_						       =   0
       A_						       =   0
       A_						       =   1e12

       while not convergence:
              # Multiple matrix by the vector.
              A_						       =   np.dot(UpperCAmelCase__,							UpperCAmelCase__					)
              # Normalize the resulting output vector.
              A_						       =   w / np.linalg.norm(UpperCAmelCase__					)
              # Find rayleigh quotient
              # (faster than usual b/c we know vector is normalized already)
              A_						       =   vector.conj().T if is_complex else vector.T
              A_						       =   np.dot(UpperCAmelCase__,							np.dot(UpperCAmelCase__,							UpperCAmelCase__					)					)

              # Check convergence.
              A_						       =   np.abs(lambda_ - lambda_previous					) / lambda_
              iterations += 1

              if error <= error_tol or iterations >= max_iterations:
                     A_						       =   True

              A_						       =   lambda_

       if is_complex:
              A_						       =   np.real(lambda_					)

       return lambda_, vector
def    UpperCAmelCase__     (   )      ->      None:
       A_						       =   np.array([[41, 4, 20], [4, 26, 30], [20, 30, 50]]					)
       A_						       =   np.array([41, 4, 20]					)
       A_						       =   real_input_matrix.astype(np.complexaaa					)
       A_						       =   np.triu(1j * complex_input_matrix,							1					)
       complex_input_matrix += imag_matrix
       complex_input_matrix += -1 * imag_matrix.T
       A_						       =   np.array([41, 4, 20]					).astype(np.complexaaa					)

       for problem_type in ["real", "complex"]:
              if problem_type == "real":
                     A_						       =   real_input_matrix
                     A_						       =   real_vector
              elif problem_type == "complex":
                     A_						       =   complex_input_matrix
                     A_						       =   complex_vector

              # Our implementation.
              A_       ,      A_						       =   power_iteration(UpperCAmelCase__,							UpperCAmelCase__					)

              # Numpy implementation.

              # Get eigenvalues and eigenvectors using built-in numpy
              # eigh (eigh used for symmetric or hermetian matrices).
              A_       ,      A_						       =   np.linalg.eigh(UpperCAmelCase__					)
              # Last eigenvalue is the maximum one.
              A_						       =   eigen_values[-1]
              # Last column in this matrix is eigenvector corresponding to largest eigenvalue.
              A_						       =   eigen_vectors[:, -1]

              # Check our implementation and numpy gives close answers.
              assert np.abs(eigen_value - eigen_value_max					) <= 1e-6
              # Take absolute values element wise of each eigenvector.
              # as they are only unique to a minus sign.
              assert np.linalg.norm(np.abs(UpperCAmelCase__					) - np.abs(UpperCAmelCase__					)					) <= 1e-6


if __name__ == "__main__":
      import doctest

      doctest.testmod()
      test_power_iteration()
