



'''simple docstring'''
from ...configuration_utils import PretrainedConfig
from ...utils import logging


__SCREAMING_SNAKE_CASE			:   List[Any]							   =logging.get_logger(__name__)

__SCREAMING_SNAKE_CASE			:   Any							   ={}


class 	SCREAMING_SNAKE_CASE__					( lowercase_       ):
	"""simple docstring"""


	A__     :     Optional[int]    =					'''llama'''
	A__     :     Optional[Any]    =					['''past_key_values''']


	def __init__(		self       , A=3_20_00       , A=40_96       , A=1_10_08       , A=32       , A=32       , A=None       , A="silu"       , A=20_48       , A=0.02       , A=1e-6       , A=True       , A=0       , A=1       , A=2       , A=1       , A=False       , A=None       , **A       , )			->				Any:
				A:   List[str]								= vocab_size
				A:   List[Any]								= max_position_embeddings
				A:   Optional[int]								= hidden_size
				A:   Tuple								= intermediate_size
				A:   List[str]								= num_hidden_layers
				A:   int								= num_attention_heads

				# for backward compatibility
				if num_key_value_heads is None:
							A:   Dict								= num_attention_heads

				A:   int								= num_key_value_heads
				A:   Dict								= hidden_act
				A:   Tuple								= initializer_range
				A:   Optional[Any]								= rms_norm_eps
				A:   Dict								= pretraining_tp
				A:   List[str]								= use_cache
				A:   Tuple								= rope_scaling
				self._rope_scaling_validation()

				super().__init__(
				    pad_token_id=A       , bos_token_id=A       , eos_token_id=A       , tie_word_embeddings=A       , **A       , )





	def   a__			(		self      )			->				Optional[int]:
				if self.rope_scaling is None:
							return

				if not isinstance(self.rope_scaling       , A      ) or len(self.rope_scaling      ) != 2:
							raise ValueError(
							    """`rope_scaling` must be a dictionary with with two fields, `name` and `factor`, """
							    f'got {self.rope_scaling}'      )
				A:   Any								= self.rope_scaling.get("""type"""       , A      )
				A:   Optional[int]								= self.rope_scaling.get("""factor"""       , A      )
				if rope_scaling_type is None or rope_scaling_type not in ["linear", "dynamic"]:
							raise ValueError(
							    f'`rope_scaling`\'s name field must be one of [\'linear\', \'dynamic\'], got {rope_scaling_type}'      )
				if rope_scaling_factor is None or not isinstance(A       , A      ) or rope_scaling_factor <= 1.0:
							raise ValueError(f'`rope_scaling`\'s factor field must be an float > 1, got {rope_scaling_factor}'      )








import unittest

import numpy as np
import torch

from .utils_summarization import build_mask, compute_token_type_ids, process_story, truncate_or_pad







class 					lowercase							(			unittest.TestCase     ):




				def        a				(   self			):
											snake_case_     							=       10




				def        a				(   self			):
											snake_case_     							=       [1, 2, 3, 4]
											snake_case_     							=       [1, 2, 3, 4, 0, 0, 0, 0, 0, 0]
											self.assertEqual(truncate_or_pad(snake_case ,  self.block_size ,  0			) ,  snake_case			)




				def        a				(   self			):
											snake_case_     							=       [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
											snake_case_     							=       [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
											self.assertEqual(truncate_or_pad(snake_case ,  self.block_size ,  0			) ,  snake_case			)




				def        a				(   self			):
											snake_case_     							=       [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
											snake_case_     							=       [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
											self.assertEqual(truncate_or_pad(snake_case ,  self.block_size ,  0			) ,  snake_case			)




				def        a				(   self			):
											snake_case_     							=       'It was the year of Our Lord one thousand seven hundred and\n        seventy-five.\n\nSpiritual revelations were conceded to England at that\n        favoured period, as at this.'
											snake_case_							,       snake_case_     							=       process_story(snake_case			)
											self.assertEqual(snake_case ,  []			)




				def        a				(   self			):
											snake_case_     							=       ''
											snake_case_							,       snake_case_     							=       process_story(snake_case			)
											self.assertEqual(snake_case ,  []			)
											self.assertEqual(snake_case ,  []			)




				def        a				(   self			):
											snake_case_     							=       (
											    'It was the year of Our Lord one thousand seven hundred and '
											    'seventy-five\n\nSpiritual revelations were conceded to England '
											    'at that favoured period, as at this.\n@highlight\n\nIt was the best of times'
											)
											snake_case_							,       snake_case_     							=       process_story(snake_case			)

											snake_case_     							=       [
											    'It was the year of Our Lord one thousand seven hundred and seventy-five.',
											    'Spiritual revelations were conceded to England at that favoured period, as at this.',
											]
											self.assertEqual(snake_case ,  snake_case			)

											snake_case_     							=       ['It was the best of times.']
											self.assertEqual(snake_case ,  snake_case			)




				def        a				(   self			):
											snake_case_     							=       torch.tensor([1, 2, 3, 4]			)
											snake_case_     							=       torch.tensor([1, 1, 1, 1]			)
											np.testing.assert_array_equal(build_mask(snake_case ,  0			).numpy() ,  expected.numpy()			)




				def        a				(   self			):
											snake_case_     							=       torch.tensor([1, 2, 3, 4, 23, 23, 23]			)
											snake_case_     							=       torch.tensor([1, 1, 1, 1, 0, 0, 0]			)
											np.testing.assert_array_equal(build_mask(snake_case ,  23			).numpy() ,  expected.numpy()			)




				def        a				(   self			):
											snake_case_     							=       torch.tensor([8, 2, 3, 4, 1, 1, 1]			)
											snake_case_     							=       torch.tensor([1, 1, 1, 1, 0, 0, 0]			)
											np.testing.assert_array_equal(build_mask(snake_case ,  1			).numpy() ,  expected.numpy()			)




				def        a				(   self			):
											snake_case_     							=       101
											snake_case_     							=       torch.tensor([[1, 2, 3, 4, 5, 6], [1, 2, 3, 101, 5, 6], [1, 101, 3, 4, 101, 6]]			)
											snake_case_     							=       torch.tensor([[1, 1, 1, 1, 1, 1], [1, 1, 1, 0, 0, 0], [1, 0, 0, 0, 1, 1]]			)

											snake_case_     							=       compute_token_type_ids(snake_case ,  snake_case			)
											np.testing.assert_array_equal(snake_case ,  snake_case			)




