



"""simple docstring"""
from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


__a     =    {
    "configuration_openai": ["OPENAI_GPT_PRETRAINED_CONFIG_ARCHIVE_MAP", "OpenAIGPTConfig"],
    "tokenization_openai": ["OpenAIGPTTokenizer"],
}

try:
						if not is_tokenizers_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						__a     =    ["OpenAIGPTTokenizerFast"]

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						__a     =    [
						    "OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST",
						    "OpenAIGPTDoubleHeadsModel",
						    "OpenAIGPTForSequenceClassification",
						    "OpenAIGPTLMHeadModel",
						    "OpenAIGPTModel",
						    "OpenAIGPTPreTrainedModel",
						    "load_tf_weights_in_openai_gpt",
						]

try:
						if not is_tf_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						__a     =    [
						    "TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST",
						    "TFOpenAIGPTDoubleHeadsModel",
						    "TFOpenAIGPTForSequenceClassification",
						    "TFOpenAIGPTLMHeadModel",
						    "TFOpenAIGPTMainLayer",
						    "TFOpenAIGPTModel",
						    "TFOpenAIGPTPreTrainedModel",
						]


if TYPE_CHECKING:
						from .configuration_openai import OPENAI_GPT_PRETRAINED_CONFIG_ARCHIVE_MAP, OpenAIGPTConfig
						from .tokenization_openai import OpenAIGPTTokenizer

						try:
												if not is_tokenizers_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .tokenization_openai_fast import OpenAIGPTTokenizerFast

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_openai import (
												    OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST,
												    OpenAIGPTDoubleHeadsModel,
												    OpenAIGPTForSequenceClassification,
												    OpenAIGPTLMHeadModel,
												    OpenAIGPTModel,
												    OpenAIGPTPreTrainedModel,
												    load_tf_weights_in_openai_gpt,
												)

						try:
												if not is_tf_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_tf_openai import (
												    TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST,
												    TFOpenAIGPTDoubleHeadsModel,
												    TFOpenAIGPTForSequenceClassification,
												    TFOpenAIGPTLMHeadModel,
												    TFOpenAIGPTMainLayer,
												    TFOpenAIGPTModel,
												    TFOpenAIGPTPreTrainedModel,
												)

else:
						import sys

						__a     =    _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)





"""simple docstring"""
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxSeqaSeqConfigWithPast
from ...utils import logging


__a     =    logging.get_logger(__name__)

__a     =    {
    "google/long-t5-local-base": "https://huggingface.co/google/long-t5-local-base/blob/main/config.json",
    "google/long-t5-local-large": "https://huggingface.co/google/long-t5-local-large/blob/main/config.json",
    "google/long-t5-tglobal-base": "https://huggingface.co/google/long-t5-tglobal-base/blob/main/config.json",
    "google/long-t5-tglobal-large": "https://huggingface.co/google/long-t5-tglobal-large/blob/main/config.json",
}
class     lowerCamelCase  (      _lowerCAmelCase    ):






					'''simple docstring'''





					_A		:      List[Any]						=					"""longt5"""
					_A		:      Dict						=					["""past_key_values"""]
					_A		:      int						=					{"""hidden_size""": """d_model""", """num_attention_heads""": """num_heads""", """num_hidden_layers""": """num_layers"""}






					def __init__(	self:							str						,					snake_case:							List[Any]=32_128						,					snake_case:							Optional[int]=512						,					snake_case:							Union[str, Any]=64						,					snake_case:							str=2_048						,					snake_case:							Any=6						,					snake_case:							Optional[Any]=None						,					snake_case:							str=8						,					snake_case:							Tuple=127						,					snake_case:							Any=16						,					snake_case:							int=32						,					snake_case:							int=128						,					snake_case:							int=0.1						,					snake_case:							Optional[int]=1E-6						,					snake_case:							List[Any]=1.0						,					snake_case:							Optional[int]="relu"						,					snake_case:							str=True						,					snake_case:							Optional[int]="local"						,					snake_case:							Any=True						,					snake_case:							Tuple=0						,					snake_case:							Any=1						,					**snake_case:							Any						,					)       ->     List[str]:
											snake_case_			:Any						=      vocab_size
											snake_case_			:List[Any]						=      d_model
											snake_case_			:Any						=      d_kv
											snake_case_			:int						=      d_ff
											snake_case_			:Tuple						=      num_layers
											# default = symmetry
											snake_case_			:str						=      num_decoder_layers if num_decoder_layers is not None else self.num_layers
											snake_case_			:Any						=      num_heads
											snake_case_			:str						=      local_radius
											snake_case_			:Optional[int]						=      global_block_size
											snake_case_			:Union[str, Any]						=      relative_attention_num_buckets
											snake_case_			:List[str]						=      relative_attention_max_distance
											snake_case_			:Dict						=      dropout_rate
											snake_case_			:str						=      layer_norm_epsilon
											snake_case_			:str						=      initializer_factor
											snake_case_			:Any						=      feed_forward_proj
											snake_case_			:List[str]						=      encoder_attention_type
											snake_case_			:List[str]						=      use_cache

											snake_case_			:Tuple						=      self.feed_forward_proj.split("""-"""						)
											snake_case_			:Any						=      act_info[-1]
											snake_case_			:Union[str, Any]						=      act_info[0] == """gated"""

											if len(snake_case						) > 1 and act_info[0] != "gated" or len(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":
																	snake_case_			:Optional[int]						=      """gelu_new"""

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

class     lowerCamelCase  (      _lowerCAmelCase    ):






					'''simple docstring'''





					@property
					def        lowerCAmelCase_    (	self:							Dict						)       ->     Mapping[str, Mapping[int, str]]:
											snake_case_			:Dict						=      {
											    """input_ids""": {0: """batch""", 1: """encoder_sequence"""},
											    """attention_mask""": {0: """batch""", 1: """encoder_sequence"""},
											}
											if self.use_past:
																	snake_case_			:List[Any]						=      """past_encoder_sequence + sequence"""
																	snake_case_			:List[Any]						=      {0: """batch"""}
																	snake_case_			:List[Any]						=      {0: """batch""", 1: """past_decoder_sequence + sequence"""}
											else:
																	snake_case_			:List[str]						=      {0: """batch""", 1: """decoder_sequence"""}
																	snake_case_			:List[Any]						=      {0: """batch""", 1: """decoder_sequence"""}

											if self.use_past:
																	self.fill_with_past_key_values_(snake_case						,					direction="""inputs"""						)

											return common_inputs






					@property
					def        lowerCAmelCase_    (	self:							List[str]						)       ->     int:
											return 13
