




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


_lowerCamelCase     :		int								=       logging.get_logger(__name__)

_lowerCamelCase     :		int								=       {
    """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     UpperCamelCase_   (			__UpperCamelCase					):

    '''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				:     List[str] ,			UpperCAmelCase__				:     Optional[int]=50_400 ,			UpperCAmelCase__				:     Optional[int]=2_048 ,			UpperCAmelCase__				:     str=4_096 ,			UpperCAmelCase__				:     Any=28 ,			UpperCAmelCase__				:     Dict=16 ,			UpperCAmelCase__				:     List[str]=64 ,			UpperCAmelCase__				:     int=None ,			UpperCAmelCase__				:     Union[str, Any]="gelu_new" ,			UpperCAmelCase__				:     Tuple=0.0 ,			UpperCAmelCase__				:     Dict=0.0 ,			UpperCAmelCase__				:     str=0.0 ,			UpperCAmelCase__				:     Optional[Any]=1e-5 ,			UpperCAmelCase__				:     List[Any]=0.02 ,			UpperCAmelCase__				:     Optional[int]=True ,			UpperCAmelCase__				:     Dict=50_256 ,			UpperCAmelCase__				:     int=50_256 ,			UpperCAmelCase__				:     Tuple=False ,			**UpperCAmelCase__				:     Any ,			)						->List[str]:





        '''simple docstring'''

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

        A__							=   bos_token_id
        A__							=   eos_token_id

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


class     UpperCamelCase_   (			__UpperCamelCase					):

    '''simple docstring'''






    def __init__(      self				:     Any ,			UpperCAmelCase__				:     PretrainedConfig ,			UpperCAmelCase__				:     str = "default" ,			UpperCAmelCase__				:     List[PatchingSpec] = None ,			UpperCAmelCase__				:     bool = False ,			)						->Any:





        '''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?
            A__							=   0


    @property
    def 	SCREAMING_SNAKE_CASE							(      self				:     List[Any])						->List[str]:





        '''simple docstring'''

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

        return common_inputs


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





        '''simple docstring'''

        return self._config.n_layer


    @property
    def 	SCREAMING_SNAKE_CASE							(      self				:     Optional[Any])						->Optional[int]:





        '''simple docstring'''

        return self._config.n_head


    def 	SCREAMING_SNAKE_CASE							(      self				:     Optional[Any] ,			UpperCAmelCase__				:     PreTrainedTokenizer ,			UpperCAmelCase__				:     int = -1 ,			UpperCAmelCase__				:     int = -1 ,			UpperCAmelCase__				:     bool = False ,			UpperCAmelCase__				:     Optional[TensorType] = None ,			)						->List[str]:





        '''simple docstring'''

        A__							=   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()
        A__							=   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

                A__							=   common_inputs["""input_ids"""].shape
                # Not using the same length for past_key_values
                A__							=   seqlen + 2
                A__							=   (
                    batch,
                    self.num_attention_heads,
                    past_key_values_length,
                    self._config.hidden_size // self.num_attention_heads,
                )
                A__							=   [
                    (torch.zeros(UpperCAmelCase__), torch.zeros(UpperCAmelCase__)) for _ in range(self.num_layers)
                ]

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

        return ordered_inputs





    @property
    def 	SCREAMING_SNAKE_CASE							(      self				:     Optional[int])						->List[Any]:





        '''simple docstring'''

        return 13








from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


_lowerCamelCase     :		str								=       {"""configuration_focalnet""": ["""FOCALNET_PRETRAINED_CONFIG_ARCHIVE_MAP""", """FocalNetConfig"""]}


try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  _lowerCamelCase     :		Dict								=       [
      """FOCALNET_PRETRAINED_MODEL_ARCHIVE_LIST""",
      """FocalNetForImageClassification""",
      """FocalNetForMaskedImageModeling""",
      """FocalNetBackbone""",
      """FocalNetModel""",
      """FocalNetPreTrainedModel""",
  ]

if TYPE_CHECKING:
  from .configuration_focalnet import FOCALNET_PRETRAINED_CONFIG_ARCHIVE_MAP, FocalNetConfig

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_focalnet import (
        FOCALNET_PRETRAINED_MODEL_ARCHIVE_LIST,
        FocalNetBackbone,
        FocalNetForImageClassification,
        FocalNetForMaskedImageModeling,
        FocalNetModel,
        FocalNetPreTrainedModel,
    )

else:
  import sys

  _lowerCamelCase     :		Tuple								=       _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)


