




import numpy as np







def SCREAMING_SNAKE_CASE       ( lowercase_				,       lowercase_				,       lowercase_ = 1E-1_2				,       lowercase_ = 100				,       )     -> tuple[float, np.ndarray]:



       """simple docstring"""

       assert np.shape(lowercase_		)[0] == np.shape(lowercase_		)[1]
       # Ensure proper dimensionality.
       assert np.shape(lowercase_		)[0] == np.shape(lowercase_		)[0]
       # Ensure inputs are either both complex or both real
       assert np.iscomplexobj(lowercase_		) == np.iscomplexobj(lowercase_		)
       A__   				=					np.iscomplexobj(lowercase_		)
       if is_complex:
              # Ensure complex input_matrix is Hermitian
              assert np.array_equal(lowercase_				,       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__   				=					1E1_2

       while not convergence:
              # Multiple matrix by the vector.
              A__   				=					np.dot(lowercase_				,       lowercase_		)
              # Normalize the resulting output vector.
              A__   				=					w / np.linalg.norm(lowercase_		)
              # 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(lowercase_				,       np.dot(lowercase_				,       lowercase_		)		)

              # 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 SCREAMING_SNAKE_CASE       ( )     -> None:



       """simple docstring"""

       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(lowercase_				,       lowercase_		)

              # Numpy implementation.

              # Get eigenvalues and eigenvectors using built-in numpy
              # eigh (eigh used for symmetric or hermetian matrices).
              A__				,							A__   				=					np.linalg.eigh(lowercase_		)
              # 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(lowercase_		) - np.abs(lowercase_		)		) <= 1E-6


if __name__ == "__main__":
  import doctest

  doctest.testmod()
  test_power_iteration()








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


_lowerCamelCase			:	Tuple							 =     logging.get_logger(__name__)

_lowerCamelCase			:	Tuple							 =     {
    """tiiuae/falcon-40b""": """https://huggingface.co/tiiuae/falcon-40b/resolve/main/config.json""",
    """tiiuae/falcon-7b""": """https://huggingface.co/tiiuae/falcon-7b/resolve/main/config.json""",
}


class        UpperCamelCase_					(				UpperCAmelCase__  ):

    '''simple docstring'''






    UpperCAmelCase__													=   '''falcon'''
    UpperCAmelCase__													=   ['''past_key_values''']


    def __init__(    self   :			Optional[Any]      ,				UpperCAmelCase__   :			str=65_024      ,				UpperCAmelCase__   :			List[Any]=4_544      ,				UpperCAmelCase__   :			Optional[Any]=32      ,				UpperCAmelCase__   :			Dict=71      ,				UpperCAmelCase__   :			Any=1e-5      ,				UpperCAmelCase__   :			Optional[int]=0.02      ,				UpperCAmelCase__   :			Optional[int]=True      ,				UpperCAmelCase__   :			Union[str, Any]=0.0      ,				UpperCAmelCase__   :			List[str]=0.0      ,				UpperCAmelCase__   :			str=None      ,				UpperCAmelCase__   :			Dict=False      ,				UpperCAmelCase__   :			List[str]=False      ,				UpperCAmelCase__   :			Optional[Any]=True      ,				UpperCAmelCase__   :			Optional[Any]=True      ,				UpperCAmelCase__   :			Optional[Any]=False      ,				UpperCAmelCase__   :			Dict=11      ,				UpperCAmelCase__   :			str=11      ,				**UpperCAmelCase__   :			Dict      ,				)		->Any:





           '''simple docstring'''

           A__   				=					vocab_size
           # Backward compatibility with n_embed kwarg
           A__   				=					kwargs.pop('''n_embed'''      ,				UpperCAmelCase__)
           A__   				=					hidden_size if n_embed is None else n_embed
           A__   				=					num_hidden_layers
           A__   				=					num_attention_heads
           A__   				=					layer_norm_epsilon
           A__   				=					initializer_range
           A__   				=					use_cache
           A__   				=					hidden_dropout
           A__   				=					attention_dropout

           A__   				=					bos_token_id
           A__   				=					eos_token_id
           A__   				=					num_attention_heads if num_kv_heads is None else num_kv_heads
           A__   				=					alibi
           A__   				=					new_decoder_architecture
           A__   				=					multi_query  # Ignored when new_decoder_architecture is True
           A__   				=					parallel_attn
           A__   				=					bias

           super().__init__(bos_token_id=UpperCAmelCase__      ,				eos_token_id=UpperCAmelCase__      ,				**UpperCAmelCase__)


    @property
    def  SCREAMING_SNAKE_CASE							(    self   :			str)		->int:





           '''simple docstring'''

           return self.hidden_size // self.num_attention_heads





    @property
    def  SCREAMING_SNAKE_CASE							(    self   :			str)		->Dict:





           '''simple docstring'''

           return not self.alibi


