





from queue import Queue
from typing import TYPE_CHECKING, Optional


if TYPE_CHECKING:
						from ..models.auto import AutoTokenizer

class SCREAMING_SNAKE_CASE_ :





					"""simple docstring"""


					def 					__magic_name__ ( self	,  _lowerCAmelCase	):
										raise NotImplementedError()






					def 					__magic_name__ ( self	):
										raise NotImplementedError()

class SCREAMING_SNAKE_CASE_ (					lowercase_   ):





					"""simple docstring"""


					def __init__( self	,  _lowerCAmelCase	,  _lowerCAmelCase = False	,  **_lowerCAmelCase	):
										lowerCamelCase__       =       tokenizer
										lowerCamelCase__       =       skip_prompt
										lowerCamelCase__       =       decode_kwargs

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





					def 					__magic_name__ ( self	,  _lowerCAmelCase	):
										if len(value.shape	) > 1 and value.shape[0] > 1:
															raise ValueError("TextStreamer only supports batch size 1"	)
										elif len(value.shape	) > 1:
															lowerCamelCase__       =       value[0]

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

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

										# After the symbol for a new line, we flush the cache.
										if text.endswith("\n"	):
															lowerCamelCase__       =       text[self.print_len :]
															lowerCamelCase__       =       []
															lowerCamelCase__       =       0
										# If the last token is a CJK character, we print the characters.
										elif len(_lowerCAmelCase	) > 0 and self._is_chinese_char(ord(text[-1]	)	):
															lowerCamelCase__       =       text[self.print_len :]
															self.print_len += len(_lowerCAmelCase	)
										# 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:
															lowerCamelCase__       =       text[self.print_len : text.rfind(" "	) + 1]
															self.print_len += len(_lowerCAmelCase	)

										self.on_finalized_text(_lowerCAmelCase	)





					def 					__magic_name__ ( self	):
										# Flush the cache, if it exists
										if len(self.token_cache	) > 0:
															lowerCamelCase__       =       self.tokenizer.decode(self.token_cache	,  **self.decode_kwargs	)
															lowerCamelCase__       =       text[self.print_len :]
															lowerCamelCase__       =       []
															lowerCamelCase__       =       0
										else:
															lowerCamelCase__       =       ""

										lowerCamelCase__       =       True
										self.on_finalized_text(_lowerCAmelCase	,  stream_end=_lowerCAmelCase	)





					def 					__magic_name__ ( self	,  _lowerCAmelCase	,  _lowerCAmelCase = False	):
										print(_lowerCAmelCase	,  flush=_lowerCAmelCase	,  end="" if not stream_end else None	)






					def 					__magic_name__ ( self	,  _lowerCAmelCase	):
										# This defines a "chinese character" as anything in the CJK Unicode block:
										#   https://en.wikipedia.org/wiki/CJK_Unified_Ideographs_(Unicode_block)
										#
										# Note that the CJK Unicode block is NOT all Japanese and Korean characters,
										# despite its name. The modern Korean Hangul alphabet is a different block,
										# as is Japanese Hiragana and Katakana. Those alphabets are used to write
										# space-separated words, so they are not treated specially and handled
										# like the all of the other languages.
										if (
										    (cp >= 0X4e00 and cp <= 0X9fff)
										    or (cp >= 0X3400 and cp <= 0X4dbf)  #
										    or (cp >= 0X2_0000 and cp <= 0X2_a6df)  #
										    or (cp >= 0X2_a700 and cp <= 0X2_b73f)  #
										    or (cp >= 0X2_b740 and cp <= 0X2_b81f)  #
										    or (cp >= 0X2_b820 and cp <= 0X2_ceaf)  #
										    or (cp >= 0Xf900 and cp <= 0Xfaff)
										    or (cp >= 0X2_f800 and cp <= 0X2_fa1f)  #
										):  #
															return True

										return False

class SCREAMING_SNAKE_CASE_ (					lowercase_   ):





					"""simple docstring"""


					def __init__( self	,  _lowerCAmelCase	,  _lowerCAmelCase = False	,  _lowerCAmelCase = None	,  **_lowerCAmelCase	):
										super().__init__(_lowerCAmelCase	,  _lowerCAmelCase	,  **_lowerCAmelCase	)
										lowerCamelCase__       =       Queue()
										lowerCamelCase__       =       None
										lowerCamelCase__       =       timeout





					def 					__magic_name__ ( self	,  _lowerCAmelCase	,  _lowerCAmelCase = False	):
										self.text_queue.put(_lowerCAmelCase	,  timeout=self.timeout	)
										if stream_end:
															self.text_queue.put(self.stop_signal	,  timeout=self.timeout	)





					def __iter__( self	):
										return self






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








from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig


A_												=     {
    "albert-base-v1": "https://huggingface.co/albert-base-v1/resolve/main/config.json",
    "albert-large-v1": "https://huggingface.co/albert-large-v1/resolve/main/config.json",
    "albert-xlarge-v1": "https://huggingface.co/albert-xlarge-v1/resolve/main/config.json",
    "albert-xxlarge-v1": "https://huggingface.co/albert-xxlarge-v1/resolve/main/config.json",
    "albert-base-v2": "https://huggingface.co/albert-base-v2/resolve/main/config.json",
    "albert-large-v2": "https://huggingface.co/albert-large-v2/resolve/main/config.json",
    "albert-xlarge-v2": "https://huggingface.co/albert-xlarge-v2/resolve/main/config.json",
    "albert-xxlarge-v2": "https://huggingface.co/albert-xxlarge-v2/resolve/main/config.json",
}

class SCREAMING_SNAKE_CASE_ (					lowercase_   ):





					"""simple docstring"""


					A__				 =    "albert"





					def __init__( self	,  _lowerCAmelCase=3_0000	,  _lowerCAmelCase=128	,  _lowerCAmelCase=4096	,  _lowerCAmelCase=12	,  _lowerCAmelCase=1	,  _lowerCAmelCase=64	,  _lowerCAmelCase=1_6384	,  _lowerCAmelCase=1	,  _lowerCAmelCase="gelu_new"	,  _lowerCAmelCase=0	,  _lowerCAmelCase=0	,  _lowerCAmelCase=512	,  _lowerCAmelCase=2	,  _lowerCAmelCase=0.02	,  _lowerCAmelCase=1E-12	,  _lowerCAmelCase=0.1	,  _lowerCAmelCase="absolute"	,  _lowerCAmelCase=0	,  _lowerCAmelCase=2	,  _lowerCAmelCase=3	,  **_lowerCAmelCase	,  ):
										super().__init__(pad_token_id=_lowerCAmelCase	,  bos_token_id=_lowerCAmelCase	,  eos_token_id=_lowerCAmelCase	,  **_lowerCAmelCase	)

										lowerCamelCase__       =       vocab_size
										lowerCamelCase__       =       embedding_size
										lowerCamelCase__       =       hidden_size
										lowerCamelCase__       =       num_hidden_layers
										lowerCamelCase__       =       num_hidden_groups
										lowerCamelCase__       =       num_attention_heads
										lowerCamelCase__       =       inner_group_num
										lowerCamelCase__       =       hidden_act
										lowerCamelCase__       =       intermediate_size
										lowerCamelCase__       =       hidden_dropout_prob
										lowerCamelCase__       =       attention_probs_dropout_prob
										lowerCamelCase__       =       max_position_embeddings
										lowerCamelCase__       =       type_vocab_size
										lowerCamelCase__       =       initializer_range
										lowerCamelCase__       =       layer_norm_eps
										lowerCamelCase__       =       classifier_dropout_prob
										lowerCamelCase__       =       position_embedding_type

class SCREAMING_SNAKE_CASE_ (					lowercase_   ):





					"""simple docstring"""


					@property
					def 					__magic_name__ ( self	):
										if self.task == "multiple-choice":
															lowerCamelCase__       =       {0: "batch", 1: "choice", 2: "sequence"}
										else:
															lowerCamelCase__       =       {0: "batch", 1: "sequence"}
										return OrderedDict(
										    [
										        ("input_ids", dynamic_axis),
										        ("attention_mask", dynamic_axis),
										        ("token_type_ids", dynamic_axis),
										    ]	)

