






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      	=  logging.get_logger(__name__)

_a      	=  {
    '''EleutherAI/gpt-j-6B''': '''https://huggingface.co/EleutherAI/gpt-j-6B/resolve/main/config.json''',
    # See all GPT-J models at https://huggingface.co/models?filter=gpt_j
}





class __lowerCamelCase (      __a):





	"""simple docstring"""






	UpperCamelCase__								=      """gptj"""
	UpperCamelCase__								=      {
	    """max_position_embeddings""": """n_positions""",
	    """hidden_size""": """n_embd""",
	    """num_attention_heads""": """n_head""",
	    """num_hidden_layers""": """n_layer""",
	}

	def __init__(							self       ,    UpperCAmelCase=5_0400       ,    UpperCAmelCase=2048       ,    UpperCAmelCase=4096       ,    UpperCAmelCase=28       ,    UpperCAmelCase=16       ,    UpperCAmelCase=64       ,    UpperCAmelCase=None       ,    UpperCAmelCase="gelu_new"       ,    UpperCAmelCase=0.0       ,    UpperCAmelCase=0.0       ,    UpperCAmelCase=0.0       ,    UpperCAmelCase=1e-5       ,    UpperCAmelCase=0.02       ,    UpperCAmelCase=True       ,    UpperCAmelCase=5_0256       ,    UpperCAmelCase=5_0256       ,    UpperCAmelCase=False       ,    **UpperCAmelCase       ,    ):
							"""simple docstring"""







							_UpperCAmelCase									=			vocab_size
							_UpperCAmelCase									=			n_positions
							_UpperCAmelCase									=			n_embd
							_UpperCAmelCase									=			n_layer
							_UpperCAmelCase									=			n_head
							_UpperCAmelCase									=			n_inner
							_UpperCAmelCase									=			rotary_dim
							_UpperCAmelCase									=			activation_function
							_UpperCAmelCase									=			resid_pdrop
							_UpperCAmelCase									=			embd_pdrop
							_UpperCAmelCase									=			attn_pdrop
							_UpperCAmelCase									=			layer_norm_epsilon
							_UpperCAmelCase									=			initializer_range
							_UpperCAmelCase									=			use_cache

							_UpperCAmelCase									=			bos_token_id
							_UpperCAmelCase									=			eos_token_id

							super().__init__(
							    bos_token_id=UpperCAmelCase       ,    eos_token_id=UpperCAmelCase       ,    tie_word_embeddings=UpperCAmelCase       ,    **UpperCAmelCase    )





class __lowerCamelCase (      __a):





	"""simple docstring"""






	def __init__(							self       ,    UpperCAmelCase       ,    UpperCAmelCase = "default"       ,    UpperCAmelCase = None       ,    UpperCAmelCase = False       ,    ):
							"""simple docstring"""







							super().__init__(UpperCAmelCase       ,    task=UpperCAmelCase       ,    patching_specs=UpperCAmelCase       ,    use_past=UpperCAmelCase    )
							if not getattr(self._config       ,    'pad_token_id'       ,    UpperCAmelCase    ):
													# TODO: how to do that better?
													_UpperCAmelCase									=			0

	@property
	def        UpperCamelCase    (							self    ):
							"""simple docstring"""







							_UpperCAmelCase									=			OrderedDict({'input_ids': {0: 'batch', 1: 'sequence'}}    )
							if self.use_past:
													self.fill_with_past_key_values_(UpperCAmelCase       ,    direction='inputs'    )
													_UpperCAmelCase									=			{0: 'batch', 1: 'past_sequence + sequence'}
							else:
													_UpperCAmelCase									=			{0: 'batch', 1: 'sequence'}

							return common_inputs

	@property
	def        UpperCamelCase    (							self    ):
							"""simple docstring"""







							return self._config.n_layer

	@property
	def        UpperCamelCase    (							self    ):
							"""simple docstring"""







							return self._config.n_head

	def        UpperCamelCase    (							self       ,    UpperCAmelCase       ,    UpperCAmelCase = -1       ,    UpperCAmelCase = -1       ,    UpperCAmelCase = False       ,    UpperCAmelCase = None       ,    ):
							"""simple docstring"""







							_UpperCAmelCase									=			super(UpperCAmelCase       ,    self    ).generate_dummy_inputs(
							    UpperCAmelCase       ,    batch_size=UpperCAmelCase       ,    seq_length=UpperCAmelCase       ,    is_pair=UpperCAmelCase       ,    framework=UpperCAmelCase    )

							# We need to order the input in the way they appears in the forward()
							_UpperCAmelCase									=			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									=			common_inputs['input_ids'].shape
																			# Not using the same length for past_key_values
																			_UpperCAmelCase									=			seqlen + 2
																			_UpperCAmelCase									=			(
																			    batch,
																			    self.num_attention_heads,
																			    past_key_values_length,
																			    self._config.hidden_size // self.num_attention_heads,
																			)
																			_UpperCAmelCase									=			[
																			    (torch.zeros(UpperCAmelCase    ), torch.zeros(UpperCAmelCase    )) for _ in range(self.num_layers    )
																			]

							_UpperCAmelCase									=			common_inputs['attention_mask']
							if self.use_past:
													_UpperCAmelCase									=			ordered_inputs['attention_mask'].dtype
													_UpperCAmelCase									=			torch.cat(
													    [ordered_inputs['attention_mask'], torch.ones(UpperCAmelCase       ,    UpperCAmelCase       ,    dtype=UpperCAmelCase    )]       ,    dim=1    )

							return ordered_inputs

	@property
	def        UpperCamelCase    (							self    ):
							"""simple docstring"""







							return 13






'''simple docstring'''







import os
from distutils.util import strtobool





def 						snake_case_							(_a	:							Union[str, Any]    ,   _a	:							List[Any]     ):
    for e in env_keys:
        UpperCAmelCase			       =		int(os.environ.get(_a    ,   -1     )     )
        if val >= 0:
            return val
    return default





def 						snake_case_							(_a	:							Dict    ,   _a	:							Any=False     ):
    UpperCAmelCase			       =		os.environ.get(_a    ,   str(_a     )     )
    return strtobool(_a     ) == 1  # As its name indicates `strtobool` actually returns an int...







def 						snake_case_							(_a	:							str    ,   _a	:							Optional[Any]="no"     ):
    UpperCAmelCase			       =		os.environ.get(_a    ,   str(_a     )     )
    return value




