


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


lowerCAmelCase__  :int             =							logging.get_logger(__name__)

lowerCAmelCase__  :Any             =							{
    '''google/switch-base-8''': '''https://huggingface.co/google/switch-base-8/blob/main/config.json''',
}

class 		__a				(    UpperCAmelCase      ):
		_a     :  Optional[Any]           =     'switch_transformers'
		_a     :  Any           =     ['past_key_values']
		_a     :  Any           =     {'hidden_size': 'd_model', 'num_attention_heads': 'num_heads', 'num_hidden_layers': 'num_layers'}
		def __init__(      self      ,   _SCREAMING_SNAKE_CASE=32128      ,   _SCREAMING_SNAKE_CASE=768      ,   _SCREAMING_SNAKE_CASE=64      ,   _SCREAMING_SNAKE_CASE=2048      ,   _SCREAMING_SNAKE_CASE=64      ,   _SCREAMING_SNAKE_CASE=12      ,   _SCREAMING_SNAKE_CASE=3      ,   _SCREAMING_SNAKE_CASE=12      ,   _SCREAMING_SNAKE_CASE=3      ,   _SCREAMING_SNAKE_CASE=12      ,   _SCREAMING_SNAKE_CASE=8      ,   _SCREAMING_SNAKE_CASE=False      ,   _SCREAMING_SNAKE_CASE=0.01      ,   _SCREAMING_SNAKE_CASE="float32"      ,   _SCREAMING_SNAKE_CASE=False      ,   _SCREAMING_SNAKE_CASE=32      ,   _SCREAMING_SNAKE_CASE=128      ,   _SCREAMING_SNAKE_CASE=0.1      ,   _SCREAMING_SNAKE_CASE=1e-6      ,   _SCREAMING_SNAKE_CASE=0.001      ,   _SCREAMING_SNAKE_CASE=0.001      ,   _SCREAMING_SNAKE_CASE=1.0      ,   _SCREAMING_SNAKE_CASE="relu"      ,   _SCREAMING_SNAKE_CASE=True      ,   _SCREAMING_SNAKE_CASE=False      ,   _SCREAMING_SNAKE_CASE=True      ,   _SCREAMING_SNAKE_CASE=0      ,   _SCREAMING_SNAKE_CASE=1      ,   **_SCREAMING_SNAKE_CASE      ,   )			->	Optional[Any]:




									"""simple docstring"""





									_UpperCAmelCase					=      vocab_size
									_UpperCAmelCase					=      d_model
									_UpperCAmelCase					=      d_kv
									_UpperCAmelCase					=      d_ff

									_UpperCAmelCase					=      num_sparse_encoder_layers

									_UpperCAmelCase					=      num_layers
									_UpperCAmelCase					=      (
									    num_decoder_layers if num_decoder_layers is not None else self.num_layers
									)  # default = symmetry
									_UpperCAmelCase					=      num_sparse_decoder_layers

									# This tells us, each how many encoder layer we'll have to set a sparse layer.
									if self.num_sparse_encoder_layers > 0:
																_UpperCAmelCase					=      self.num_layers // self.num_sparse_encoder_layers
									else:
																_UpperCAmelCase					=      self.num_layers  # HACK: this will create 0 sparse layers

									# This tells us, each how many encoder layer we'll have to set a sparse layer.
									if self.num_sparse_decoder_layers > 0:
																_UpperCAmelCase					=      self.num_decoder_layers // self.num_sparse_decoder_layers
									else:
																_UpperCAmelCase					=      self.num_decoder_layers  # HACK: this will create 0 sparse layers

									_UpperCAmelCase					=      num_heads
									_UpperCAmelCase					=      num_experts
									_UpperCAmelCase					=      expert_capacity
									_UpperCAmelCase					=      router_bias
									_UpperCAmelCase					=      router_jitter_noise
									if router_dtype not in ["float32", "float16", "bfloat16"]:
																raise ValueError(f'''`router_dtype` must be one of \'float32\', \'float16\' or \'bfloat16\', got {router_dtype}'''						)
									_UpperCAmelCase					=      router_dtype

									_UpperCAmelCase					=      router_ignore_padding_tokens
									_UpperCAmelCase					=      relative_attention_num_buckets
									_UpperCAmelCase					=      relative_attention_max_distance

									_UpperCAmelCase					=      dropout_rate
									_UpperCAmelCase					=      layer_norm_epsilon
									_UpperCAmelCase					=      initializer_factor
									_UpperCAmelCase					=      feed_forward_proj
									_UpperCAmelCase					=      use_cache
									_UpperCAmelCase					=      add_router_probs

									_UpperCAmelCase					=      router_z_loss_coef
									_UpperCAmelCase					=      router_aux_loss_coef

									_UpperCAmelCase					=      self.feed_forward_proj.split('-'						)
									_UpperCAmelCase					=      act_info[-1]
									_UpperCAmelCase					=      act_info[0] == 'gated'

									if len(_SCREAMING_SNAKE_CASE						) > 1 and act_info[0] != "gated" or len(_SCREAMING_SNAKE_CASE						) > 2:
																raise ValueError(
																    f'''`feed_forward_proj`: {feed_forward_proj} is not a valid activation function of the dense layer.'''
																    'Please make sure `feed_forward_proj` is of the format `gated-{ACT_FN}` or `{ACT_FN}`, e.g. '
																    '\'gated-gelu\' or \'relu\''						)

									# for backwards compatibility
									if feed_forward_proj == "gated-gelu":
																_UpperCAmelCase					=      'gelu_new'

									super().__init__(
									    pad_token_id=_SCREAMING_SNAKE_CASE      ,   eos_token_id=_SCREAMING_SNAKE_CASE      ,   is_encoder_decoder=_SCREAMING_SNAKE_CASE      ,   **_SCREAMING_SNAKE_CASE      ,   )




def 	lowerCAmelCase__			(      a__:		int	)  ->		None:


							'''simple docstring'''





							_UpperCAmelCase					=      generate_pascal_triangle(a__	)
							for row_idx in range(a__	):
														# Print left spaces
														for _ in range(num_rows - row_idx - 1	):
																					print(end=' '	)
														# Print row values
														for col_idx in range(row_idx + 1	):
																					if col_idx != row_idx:
																												print(triangle[row_idx][col_idx]      ,  end=' '	)
																					else:
																												print(triangle[row_idx][col_idx]      ,  end=''	)
														print()

def 	lowerCAmelCase__			(      a__:		int	)  ->		list[list[int]]:


							'''simple docstring'''





							if not isinstance(a__      ,  a__	):
														raise TypeError('The input value of \'num_rows\' should be \'int\''	)

							if num_rows == 0:
														return []
							elif num_rows < 0:
														raise ValueError(
														    'The input value of \'num_rows\' should be greater than or equal to 0'	)

							_UpperCAmelCase					=      []
							for current_row_idx in range(a__	):
														_UpperCAmelCase					=      populate_current_row(a__      ,  a__	)
														triangle.append(a__	)
							return triangle

def 	lowerCAmelCase__			(      a__:		list[list[int]]      ,  a__:		int	)  ->		list[int]:


							'''simple docstring'''





							_UpperCAmelCase					=      [-1] * (current_row_idx + 1)
							# first and last elements of current row are equal to 1
							_UpperCAmelCase		,	_UpperCAmelCase					=      1, 1
							for current_col_idx in range(1      ,  a__	):
														calculate_current_element(
														    a__      ,  a__      ,  a__      ,  a__	)
							return current_row

def 	lowerCAmelCase__			(      a__:		list[list[int]]      ,  a__:		list[int]      ,  a__:		int      ,  a__:		int      ,  )  ->		None:


							'''simple docstring'''





							_UpperCAmelCase					=      triangle[current_row_idx - 1][current_col_idx - 1]
							_UpperCAmelCase					=      triangle[current_row_idx - 1][current_col_idx]
							_UpperCAmelCase					=      above_to_left_elt + above_to_right_elt

def 	lowerCAmelCase__			(      a__:		int	)  ->		list[list[int]]:


							'''simple docstring'''





							if not isinstance(a__      ,  a__	):
														raise TypeError('The input value of \'num_rows\' should be \'int\''	)

							if num_rows == 0:
														return []
							elif num_rows < 0:
														raise ValueError(
														    'The input value of \'num_rows\' should be greater than or equal to 0'	)

							_UpperCAmelCase					=      [[1]]

							for row_index in range(1      ,  a__	):
														_UpperCAmelCase					=      [0] + result[-1] + [0]
														_UpperCAmelCase					=      row_index + 1
														# Calculate the number of distinct elements in a row
														_UpperCAmelCase					=      sum(divmod(a__      ,  2	)	)
														_UpperCAmelCase					=      [
														    temp_row[i - 1] + temp_row[i] for i in range(1      ,  distinct_elements + 1	)
														]
														_UpperCAmelCase					=      row_first_half[: (row_index + 1) // 2]
														row_second_half.reverse()
														_UpperCAmelCase					=      row_first_half + row_second_half
														result.append(a__	)

							return result

def 	lowerCAmelCase__			(      )  ->		None:


							'''simple docstring'''





							from collections.abc import Callable
							from timeit import timeit

							def benchmark_a_function(a__:		Callable      ,  a__:		int	) -> None:
														_UpperCAmelCase					=      F'''{func.__name__}({value})'''
														_UpperCAmelCase					=      timeit(F'''__main__.{call}'''      ,  setup='import __main__'	)
														# print(f"{call:38} = {func(value)} -- {timing:.4f} seconds")
														print(F'''{call:38} -- {timing:.4f} seconds'''	)

							for value in range(1_5	):  # (1, 7, 14):
														for func in (generate_pascal_triangle, generate_pascal_triangle_optimized):
																					benchmark_a_function(a__      ,  a__	)
														print()


if __name__ == "__main__":
		import doctest

		doctest.testmod()
		benchmark()
