


'''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


lowerCamelCase__    	=     logging.get_logger(__name__)

lowerCamelCase__    	=     {
    '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__			(			UpperCAmelCase__	):
			lowerCAmelCase :	int          =     "gptj"
			lowerCAmelCase :	Tuple          =     {
			    "max_position_embeddings": "n_positions",
			    "hidden_size": "n_embd",
			    "num_attention_heads": "n_head",
			    "num_hidden_layers": "n_layer",
			}




			def __init__(		self  :     List[Any]	,  lowerCamelCase__  :     str=5_04_00	,  lowerCamelCase__  :     Optional[Any]=20_48	,  lowerCamelCase__  :     List[str]=40_96	,  lowerCamelCase__  :     List[str]=28	,  lowerCamelCase__  :     List[str]=16	,  lowerCamelCase__  :     List[str]=64	,  lowerCamelCase__  :     Dict=None	,  lowerCamelCase__  :     Optional[int]="gelu_new"	,  lowerCamelCase__  :     Dict=0.0	,  lowerCamelCase__  :     List[Any]=0.0	,  lowerCamelCase__  :     Optional[int]=0.0	,  lowerCamelCase__  :     Tuple=1E-5	,  lowerCamelCase__  :     Tuple=0.0_2	,  lowerCamelCase__  :     List[str]=True	,  lowerCamelCase__  :     Tuple=5_02_56	,  lowerCamelCase__  :     Dict=5_02_56	,  lowerCamelCase__  :     List[str]=False	,  **lowerCamelCase__  :     Optional[int]	,  )   ->Union[str, Any]:



					'''simple docstring'''







					_UpperCAmelCase		:       Union[str, Any]								=      vocab_size
					_UpperCAmelCase		:       List[str]								=      n_positions
					_UpperCAmelCase		:       List[Any]								=      n_embd
					_UpperCAmelCase		:       str								=      n_layer
					_UpperCAmelCase		:       List[Any]								=      n_head
					_UpperCAmelCase		:       str								=      n_inner
					_UpperCAmelCase		:       List[Any]								=      rotary_dim
					_UpperCAmelCase		:       Optional[int]								=      activation_function
					_UpperCAmelCase		:       Any								=      resid_pdrop
					_UpperCAmelCase		:       str								=      embd_pdrop
					_UpperCAmelCase		:       List[str]								=      attn_pdrop
					_UpperCAmelCase		:       Any								=      layer_norm_epsilon
					_UpperCAmelCase		:       List[Any]								=      initializer_range
					_UpperCAmelCase		:       List[str]								=      use_cache

					_UpperCAmelCase		:       Dict								=      bos_token_id
					_UpperCAmelCase		:       str								=      eos_token_id

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






class 	lowerCAmelCase__			(			UpperCAmelCase__	):




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



					'''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		:       Any								=      0




			@property
			def 							lowerCAmelCase__    (		self  :     List[str] )   ->Mapping[str, Mapping[int, str]]:



					'''simple docstring'''







					_UpperCAmelCase		:       Optional[int]								=      OrderedDict({"input_ids": {0: "batch", 1: "sequence"}} )
					if self.use_past:
							self.fill_with_past_key_values_(lowerCamelCase__	,  direction="inputs" )
							_UpperCAmelCase		:       Optional[Any]								=      {0: "batch", 1: "past_sequence + sequence"}
					else:
							_UpperCAmelCase		:       Dict								=      {0: "batch", 1: "sequence"}

					return common_inputs




			@property
			def 							lowerCAmelCase__    (		self  :     List[str] )   ->int:



					'''simple docstring'''







					return self._config.n_layer




			@property
			def 							lowerCAmelCase__    (		self  :     Dict )   ->int:



					'''simple docstring'''







					return self._config.n_head




			def 							lowerCAmelCase__    (		self  :     int	,  lowerCamelCase__  :     PreTrainedTokenizer	,  lowerCamelCase__  :     int = -1	,  lowerCamelCase__  :     int = -1	,  lowerCamelCase__  :     bool = False	,  lowerCamelCase__  :     Optional[TensorType] = None	,  )   ->Mapping[str, 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		:       Optional[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		:       int								=      seqlen + 2
									_UpperCAmelCase		:       Optional[Any]								=      (
									    batch,
									    self.num_attention_heads,
									    past_key_values_length,
									    self._config.hidden_size // self.num_attention_heads,
									)
									_UpperCAmelCase		:       Optional[int]								=      [
									    (torch.zeros(lowerCamelCase__ ), torch.zeros(lowerCamelCase__ )) for _ in range(self.num_layers )
									]

					_UpperCAmelCase		:       Optional[int]								=      common_inputs["attention_mask"]
					if self.use_past:
							_UpperCAmelCase		:       str								=      ordered_inputs["attention_mask"].dtype
							_UpperCAmelCase		:       List[str]								=      torch.cat(
							    [ordered_inputs["attention_mask"], torch.ones(lowerCamelCase__	,  lowerCamelCase__	,  dtype=lowerCamelCase__ )]	,  dim=1 )

					return ordered_inputs






			@property
			def 							lowerCAmelCase__    (		self  :     List[str] )   ->int:



					'''simple docstring'''







					return 13







'''simple docstring'''


from ...utils import (
    OptionalDependencyNotAvailable,
    is_flax_available,
    is_torch_available,
    is_transformers_available,
)


try:
						if not (is_transformers_available() and is_torch_available()):
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						from ...utils.dummy_torch_and_transformers_objects import *  # noqa F403
else:
						from .multicontrolnet import MultiControlNetModel
						from .pipeline_controlnet import StableDiffusionControlNetPipeline
						from .pipeline_controlnet_imgaimg import StableDiffusionControlNetImgaImgPipeline
						from .pipeline_controlnet_inpaint import StableDiffusionControlNetInpaintPipeline


if is_transformers_available() and is_flax_available():
						from .pipeline_flax_controlnet import FlaxStableDiffusionControlNetPipeline



