






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


A_			:Any	    =		logging.get_logger(__name__)

A_			:Tuple	    =		{
    '''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	(     a					):





				"""simple docstring"""







				UpperCamelCase__					: Tuple     					="""gpt2"""
				UpperCamelCase__					: List[Any]     					=["""past_key_values"""]
				UpperCamelCase__					: List[Any]     					={
				    """hidden_size""": """n_embd""",
				    """max_position_embeddings""": """n_positions""",
				    """num_attention_heads""": """n_head""",
				    """num_hidden_layers""": """n_layer""",
				}


				def __init__(					self				,    lowerCamelCase__=50257				,    lowerCamelCase__=1024				,    lowerCamelCase__=768				,    lowerCamelCase__=12				,    lowerCamelCase__=12				,    lowerCamelCase__=None				,    lowerCamelCase__="gelu_new"				,    lowerCamelCase__=0.1				,    lowerCamelCase__=0.1				,    lowerCamelCase__=0.1				,    lowerCamelCase__=1E-5				,    lowerCamelCase__=0.02				,    lowerCamelCase__="cls_index"				,    lowerCamelCase__=True				,    lowerCamelCase__=None				,    lowerCamelCase__=True				,    lowerCamelCase__=0.1				,    lowerCamelCase__=True				,    lowerCamelCase__=True				,    lowerCamelCase__=50256				,    lowerCamelCase__=50256				,    lowerCamelCase__=False				,    lowerCamelCase__=False				,    **lowerCamelCase__				,    ):




									"""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	(     a					):





				"""simple docstring"""







				def __init__(					self				,    lowerCamelCase__				,    lowerCamelCase__ = "default"				,    lowerCamelCase__ = None				,    lowerCamelCase__ = False				,    ):




									"""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  __lowercase				(					self       ):




									"""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  __lowercase				(					self       ):




									"""simple docstring"""

									return self._config.n_layer


				@property
				def  __lowercase				(					self       ):




									"""simple docstring"""

									return self._config.n_head


				def  __lowercase				(					self				,    lowerCamelCase__				,    lowerCamelCase__ = -1				,    lowerCamelCase__ = -1				,    lowerCamelCase__ = False				,    lowerCamelCase__ = None				,    ):




									"""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						,							__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  __lowercase				(					self       ):




									"""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_   )

