



'''simple docstring'''
from collections import OrderedDict
from typing import Any, List, Mapping, Optional

from ... import PreTrainedTokenizer, TensorType, is_torch_available
from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfigWithPast, PatchingSpec
from ...utils import logging


_UpperCamelCase									=      logging.get_logger(__name__)

_UpperCamelCase									=      {
    '''gpt2''': '''https://huggingface.co/gpt2/resolve/main/config.json''',
    '''gpt2-medium''': '''https://huggingface.co/gpt2-medium/resolve/main/config.json''',
    '''gpt2-large''': '''https://huggingface.co/gpt2-large/resolve/main/config.json''',
    '''gpt2-xl''': '''https://huggingface.co/gpt2-xl/resolve/main/config.json''',
    '''distilgpt2''': '''https://huggingface.co/distilgpt2/resolve/main/config.json''',
}



class _A	(     __SCREAMING_SNAKE_CASE     ):
		_SCREAMING_SNAKE_CASE       :     Tuple       =      """gpt2"""
		_SCREAMING_SNAKE_CASE       :     List[Any]       =      ["""past_key_values"""]
		_SCREAMING_SNAKE_CASE       :     List[Any]       =      {
		    """hidden_size""": """n_embd""",
		    """max_position_embeddings""": """n_positions""",
		    """num_attention_heads""": """n_head""",
		    """num_hidden_layers""": """n_layer""",
		}





		def __init__(  self			,							__UpperCAmelCase=50_257			,							__UpperCAmelCase=1_024			,							__UpperCAmelCase=768			,							__UpperCAmelCase=12			,							__UpperCAmelCase=12			,							__UpperCAmelCase=None			,							__UpperCAmelCase="gelu_new"			,							__UpperCAmelCase=0.1			,							__UpperCAmelCase=0.1			,							__UpperCAmelCase=0.1			,							__UpperCAmelCase=1E-5			,							__UpperCAmelCase=0.02			,							__UpperCAmelCase="cls_index"			,							__UpperCAmelCase=True			,							__UpperCAmelCase=None			,							__UpperCAmelCase=True			,							__UpperCAmelCase=0.1			,							__UpperCAmelCase=True			,							__UpperCAmelCase=True			,							__UpperCAmelCase=50_256			,							__UpperCAmelCase=50_256			,							__UpperCAmelCase=False			,							__UpperCAmelCase=False			,							**__UpperCAmelCase			,							)							->  List[Any]:

					'''simple docstring'''
					__UpperCAmelCase :   Tuple    					=  vocab_size
					__UpperCAmelCase :   Optional[Any]    					=  n_positions
					__UpperCAmelCase :   Tuple    					=  n_embd
					__UpperCAmelCase :   Optional[Any]    					=  n_layer
					__UpperCAmelCase :   int    					=  n_head
					__UpperCAmelCase :   str    					=  n_inner
					__UpperCAmelCase :   List[Any]    					=  activation_function
					__UpperCAmelCase :   Tuple    					=  resid_pdrop
					__UpperCAmelCase :   List[Any]    					=  embd_pdrop
					__UpperCAmelCase :   Optional[Any]    					=  attn_pdrop
					__UpperCAmelCase :   Optional[int]    					=  layer_norm_epsilon
					__UpperCAmelCase :   List[Any]    					=  initializer_range
					__UpperCAmelCase :   Dict    					=  summary_type
					__UpperCAmelCase :   Union[str, Any]    					=  summary_use_proj
					__UpperCAmelCase :   List[Any]    					=  summary_activation
					__UpperCAmelCase :   Any    					=  summary_first_dropout
					__UpperCAmelCase :   List[str]    					=  summary_proj_to_labels
					__UpperCAmelCase :   List[str]    					=  scale_attn_weights
					__UpperCAmelCase :   Optional[Any]    					=  use_cache
					__UpperCAmelCase :   Tuple    					=  scale_attn_by_inverse_layer_idx
					__UpperCAmelCase :   List[str]    					=  reorder_and_upcast_attn

					__UpperCAmelCase :   Any    					=  bos_token_id
					__UpperCAmelCase :   Optional[Any]    					=  eos_token_id

					super().__init__(bos_token_id=lowerCamelCase__			,							eos_token_id=lowerCamelCase__			,							**lowerCamelCase__					)



class _A	(     __SCREAMING_SNAKE_CASE     ):





		def __init__(  self			,							__UpperCAmelCase			,							__UpperCAmelCase = "default"			,							__UpperCAmelCase = None			,							__UpperCAmelCase = False			,							)							->  List[Any]:

					'''simple docstring'''
					super().__init__(lowerCamelCase__			,							task=lowerCamelCase__			,							patching_specs=lowerCamelCase__			,							use_past=lowerCamelCase__					)
					if not getattr(self._config			,							"""pad_token_id"""			,							lowerCamelCase__					):
								# TODO: how to do that better?
								__UpperCAmelCase :   str    					=  0





		@property
		def 				__A							(  self					)							->  Union[str, Any]:

					'''simple docstring'''
					__UpperCAmelCase :   List[Any]    					=  OrderedDict({"""input_ids""": {0: """batch""", 1: """sequence"""}}					)
					if self.use_past:
								self.fill_with_past_key_values_(lowerCamelCase__			,							direction="""inputs"""					)
								__UpperCAmelCase :   str    					=  {0: 'batch', 1: 'past_sequence + sequence'}
					else:
								__UpperCAmelCase :   str    					=  {0: 'batch', 1: 'sequence'}

					return common_inputs





		@property
		def 				__A							(  self					)							->  Any:

					'''simple docstring'''
					return self._config.n_layer





		@property
		def 				__A							(  self					)							->  Dict:

					'''simple docstring'''
					return self._config.n_head





		def 				__A							(  self			,							__UpperCAmelCase			,							__UpperCAmelCase = -1			,							__UpperCAmelCase = -1			,							__UpperCAmelCase = False			,							__UpperCAmelCase = None			,							)							->  Any:

					'''simple docstring'''
					__UpperCAmelCase :   str    					=  super(lowerCamelCase__			,							self					).generate_dummy_inputs(
					    lowerCamelCase__			,							batch_size=lowerCamelCase__			,							seq_length=lowerCamelCase__			,							is_pair=lowerCamelCase__			,							framework=lowerCamelCase__					)

					# We need to order the input in the way they appears in the forward()
					__UpperCAmelCase :   Any    					=  OrderedDict({"""input_ids""": common_inputs["""input_ids"""]}					)

					# Need to add the past_keys
					if self.use_past:
								if not is_torch_available():
											raise ValueError("""Cannot generate dummy past_keys inputs without PyTorch installed."""					)
								else:
											import torch

											__UpperCAmelCase :   Tuple    					=  common_inputs['input_ids'].shape
											# Not using the same length for past_key_values
											__UpperCAmelCase :   Dict    					=  seqlen + 2
											__UpperCAmelCase :   Optional[int]    					=  (
											    batch,
											    self.num_attention_heads,
											    past_key_values_length,
											    self._config.hidden_size // self.num_attention_heads,
											)
											__UpperCAmelCase :   Any    					=  [
											    (torch.zeros(lowerCamelCase__					), torch.zeros(lowerCamelCase__					)) for _ in range(self.num_layers					)
											]

					__UpperCAmelCase :   Any    					=  common_inputs['attention_mask']
					if self.use_past:
								__UpperCAmelCase :   Any    					=  ordered_inputs['attention_mask'].dtype
								__UpperCAmelCase :   Optional[Any]    					=  torch.cat(
								    [ordered_inputs["""attention_mask"""], torch.ones(lowerCamelCase__			,							lowerCamelCase__			,							dtype=lowerCamelCase__					)]			,							dim=1					)

					return ordered_inputs





		@property
		def 				__A							(  self					)							->  Union[str, Any]:

					'''simple docstring'''
					return 13












import os

from packaging import version

from .. import __version__
from .accelerate_utils import apply_forward_hook
from .constants import (
    CONFIG_NAME,
    DEPRECATED_REVISION_ARGS,
    DIFFUSERS_CACHE,
    DIFFUSERS_DYNAMIC_MODULE_NAME,
    FLAX_WEIGHTS_NAME,
    HF_MODULES_CACHE,
    HUGGINGFACE_CO_RESOLVE_ENDPOINT,
    ONNX_EXTERNAL_WEIGHTS_NAME,
    ONNX_WEIGHTS_NAME,
    SAFETENSORS_WEIGHTS_NAME,
    TEXT_ENCODER_ATTN_MODULE,
    WEIGHTS_NAME,
)
from .deprecation_utils import deprecate
from .doc_utils import replace_example_docstring
from .dynamic_modules_utils import get_class_from_dynamic_module
from .hub_utils import (
    HF_HUB_OFFLINE,
    _add_variant,
    _get_model_file,
    extract_commit_hash,
    http_user_agent,
)
from .import_utils import (
    BACKENDS_MAPPING,
    ENV_VARS_TRUE_AND_AUTO_VALUES,
    ENV_VARS_TRUE_VALUES,
    USE_JAX,
    USE_TF,
    USE_TORCH,
    DummyObject,
    OptionalDependencyNotAvailable,
    is_accelerate_available,
    is_accelerate_version,
    is_bsa_available,
    is_flax_available,
    is_ftfy_available,
    is_inflect_available,
    is_invisible_watermark_available,
    is_k_diffusion_available,
    is_k_diffusion_version,
    is_librosa_available,
    is_note_seq_available,
    is_omegaconf_available,
    is_onnx_available,
    is_safetensors_available,
    is_scipy_available,
    is_tensorboard_available,
    is_tf_available,
    is_torch_available,
    is_torch_version,
    is_torchsde_available,
    is_transformers_available,
    is_transformers_version,
    is_unidecode_available,
    is_wandb_available,
    is_xformers_available,
    requires_backends,
)
from .logging import get_logger
from .outputs import BaseOutput
from .pil_utils import PIL_INTERPOLATION, numpy_to_pil, pt_to_pil
from .torch_utils import is_compiled_module, randn_tensor


if is_torch_available():
							from .testing_utils import (
							    floats_tensor,
							    load_hf_numpy,
							    load_image,
							    load_numpy,
							    load_pt,
							    nightly,
							    parse_flag_from_env,
							    print_tensor_test,
							    require_torch_a,
							    require_torch_gpu,
							    skip_mps,
							    slow,
							    torch_all_close,
							    torch_device,
							)
							from .torch_utils import maybe_allow_in_graph

from .testing_utils import export_to_gif, export_to_video


A_			:List[str]	    =		get_logger(__name__)






def 				A	(			a_   )	->		Tuple:
					if version.parse(a_   ) < version.parse(a_   ):
										if "dev" in min_version:
															__UpperCamelCase :   List[str]									=(
															    'This example requires a source install from HuggingFace diffusers (see '
															    '`https://huggingface.co/docs/diffusers/installation#install-from-source`),'
															)
										else:
															__UpperCamelCase :   Tuple									=F'This example requires a minimum version of {min_version},'
										error_message += F' but the version found is {__version__}.\n'
										raise ImportError(a_   )

