



from queue import Queue
from typing import TYPE_CHECKING, Optional


if TYPE_CHECKING:
							from ..models.auto import AutoTokenizer


class   __lowerCAmelCase  :
					"""simple docstring"""






					def      _a				(  self       :							Dict					,       _snake_case       :							List[str]       ):






								"""simple docstring"""


								raise NotImplementedError()



					def      _a				(  self       :							Union[str, Any]       ):






								"""simple docstring"""


								raise NotImplementedError()







class   __lowerCAmelCase  (		UpperCAmelCase_   ):
					"""simple docstring"""






					def __init__(  self       :							List[str]					,       _snake_case       :							"AutoTokenizer"					,       _snake_case       :							bool = False					,       **_snake_case       :							Tuple       ):






								"""simple docstring"""


								A__	  =     tokenizer
								A__	  =     skip_prompt
								A__	  =     decode_kwargs

								# variables used in the streaming process
								A__	  =     []
								A__	  =     0
								A__	  =     True



					def      _a				(  self       :							Optional[int]					,       _snake_case       :							str       ):






								"""simple docstring"""


								if len(value.shape       ) > 1 and value.shape[0] > 1:
											raise ValueError('TextStreamer only supports batch size 1'       )
								elif len(value.shape       ) > 1:
											A__	  =     value[0]

								if self.skip_prompt and self.next_tokens_are_prompt:
											A__	  =     False
											return

								# Add the new token to the cache and decodes the entire thing.
								self.token_cache.extend(value.tolist()       )
								A__	  =     self.tokenizer.decode(self.token_cache					,       **self.decode_kwargs       )

								# After the symbol for a new line, we flush the cache.
								if text.endswith('\n'       ):
											A__	  =     text[self.print_len :]
											A__	  =     []
											A__	  =     0
								# If the last token is a CJK character, we print the characters.
								elif len(_snake_case       ) > 0 and self._is_chinese_char(ord(text[-1]       )       ):
											A__	  =     text[self.print_len :]
											self.print_len += len(_snake_case       )
								# Otherwise, prints until the last space char (simple heuristic to avoid printing incomplete words,
								# which may change with the subsequent token -- there are probably smarter ways to do this!)
								else:
											A__	  =     text[self.print_len : text.rfind(' '       ) + 1]
											self.print_len += len(_snake_case       )

								self.on_finalized_text(_snake_case       )



					def      _a				(  self       :							Optional[int]       ):






								"""simple docstring"""


								if len(self.token_cache       ) > 0:
											A__	  =     self.tokenizer.decode(self.token_cache					,       **self.decode_kwargs       )
											A__	  =     text[self.print_len :]
											A__	  =     []
											A__	  =     0
								else:
											A__	  =     ''

								A__	  =     True
								self.on_finalized_text(_snake_case					,       stream_end=_snake_case       )



					def      _a				(  self       :							Optional[int]					,       _snake_case       :							str					,       _snake_case       :							bool = False       ):






								"""simple docstring"""


								print(_snake_case					,       flush=_snake_case					,       end='' if not stream_end else None       )



					def      _a				(  self       :							Any					,       _snake_case       :							str       ):






								"""simple docstring"""


								if (
								    (cp >= 0x4E00 and cp <= 0x9FFF)
								    or (cp >= 0x3400 and cp <= 0x4DBF)  #
								    or (cp >= 0x20000 and cp <= 0x2A6DF)  #
								    or (cp >= 0x2A700 and cp <= 0x2B73F)  #
								    or (cp >= 0x2B740 and cp <= 0x2B81F)  #
								    or (cp >= 0x2B820 and cp <= 0x2CEAF)  #
								    or (cp >= 0xF900 and cp <= 0xFAFF)
								    or (cp >= 0x2F800 and cp <= 0x2FA1F)  #
								):  #
											return True

								return False







class   __lowerCAmelCase  (		UpperCAmelCase_   ):
					"""simple docstring"""






					def __init__(  self       :							Dict					,       _snake_case       :							"AutoTokenizer"					,       _snake_case       :							bool = False					,       _snake_case       :							Optional[float] = None					,       **_snake_case       :							str       ):






								"""simple docstring"""


								super().__init__(_snake_case					,       _snake_case					,       **_snake_case       )
								A__	  =     Queue()
								A__	  =     None
								A__	  =     timeout



					def      _a				(  self       :							Optional[int]					,       _snake_case       :							str					,       _snake_case       :							bool = False       ):






								"""simple docstring"""


								self.text_queue.put(_snake_case					,       timeout=self.timeout       )
								if stream_end:
											self.text_queue.put(self.stop_signal					,       timeout=self.timeout       )



					def __iter__(  self       :							Optional[int]       ):






								"""simple docstring"""


								return self



					def      _a				(  self       :							Dict       ):






								"""simple docstring"""


								A__	  =     self.text_queue.get(timeout=self.timeout       )
								if value == self.stop_signal:
											raise StopIteration()
								else:
											return value





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


SCREAMING_SNAKE_CASE		:     int         =	logging.get_logger(__name__)

SCREAMING_SNAKE_CASE		:     Union[str, Any]         =	{
    # See all MEGATRON_BERT models at https://huggingface.co/models?filter=bert
}

class        UpperCamelCase						(				__a				):
						a__		:List[str]      =			'''megatron-bert'''





						def __init__(self			,     __UpperCamelCase=29_056			,     __UpperCamelCase=1_024			,     __UpperCamelCase=24			,     __UpperCamelCase=16			,     __UpperCamelCase=4_096			,     __UpperCamelCase="gelu"			,     __UpperCamelCase=0.1			,     __UpperCamelCase=0.1			,     __UpperCamelCase=512			,     __UpperCamelCase=2			,     __UpperCamelCase=0.02			,     __UpperCamelCase=1E-1_2			,     __UpperCamelCase=0			,     __UpperCamelCase="absolute"			,     __UpperCamelCase=True			,     **__UpperCamelCase			,     )				->				List[Any]:
												super().__init__(pad_token_id=__UpperCamelCase			,     **__UpperCamelCase						)

												UpperCamelCase_		:							Union[str, Any]  =		vocab_size
												UpperCamelCase_		:							Union[str, Any]  =		hidden_size
												UpperCamelCase_		:							Any  =		num_hidden_layers
												UpperCamelCase_		:							str  =		num_attention_heads
												UpperCamelCase_		:							List[Any]  =		hidden_act
												UpperCamelCase_		:							Dict  =		intermediate_size
												UpperCamelCase_		:							Optional[int]  =		hidden_dropout_prob
												UpperCamelCase_		:							Dict  =		attention_probs_dropout_prob
												UpperCamelCase_		:							Any  =		max_position_embeddings
												UpperCamelCase_		:							str  =		type_vocab_size
												UpperCamelCase_		:							Tuple  =		initializer_range
												UpperCamelCase_		:							List[str]  =		layer_norm_eps
												UpperCamelCase_		:							Tuple  =		position_embedding_type
												UpperCamelCase_		:							Tuple  =		use_cache






