
'''simple docstring'''



from typing import List, Optional, Tuple, Union

from . import logging
from .import_utils import is_torch_available, is_torch_version


if is_torch_available():
     import torch

UpperCamelCase__ :						str    							=					logging.get_logger(__name__)  # pylint: disable=invalid-name

try:
     from torch._dynamo import allow_in_graph as maybe_allow_in_graph
except (ImportError, ModuleNotFoundError):
     def 				lowerCAmelCase_		(			cls  )       ->       Tuple:




        """simple docstring"""
        return cls
def 				lowerCAmelCase_		(			SCREAMING_SNAKE_CASE_      , SCREAMING_SNAKE_CASE_ = None      , SCREAMING_SNAKE_CASE_ = None      , SCREAMING_SNAKE_CASE_ = None      , SCREAMING_SNAKE_CASE_ = None      , )       ->       Tuple:




   """simple docstring"""
   _SCREAMING_SNAKE_CASE       	=			device
   _SCREAMING_SNAKE_CASE       	=			shape[0]

   _SCREAMING_SNAKE_CASE       	=			layout or torch.strided
   _SCREAMING_SNAKE_CASE       	=			device or torch.device("""cpu"""  )

   if generator is not None:
      _SCREAMING_SNAKE_CASE       	=			generator.device.type if not isinstance(SCREAMING_SNAKE_CASE_      , SCREAMING_SNAKE_CASE_  ) else generator[0].device.type
      if gen_device_type != device.type and gen_device_type == "cpu":
         _SCREAMING_SNAKE_CASE       	=			"""cpu"""
         if device != "mps":
            logger.info(
                F"The passed generator was created on 'cpu' even though a tensor on {device} was expected."
                F" Tensors will be created on 'cpu' and then moved to {device}. Note that one can probably"
                F" slighly speed up this function by passing a generator that was created on the {device} device."  )
      elif gen_device_type != device.type and gen_device_type == "cuda":
         raise ValueError(F"Cannot generate a {device} tensor from a generator of type {gen_device_type}."  )

   if isinstance(SCREAMING_SNAKE_CASE_      , SCREAMING_SNAKE_CASE_  ):
      _SCREAMING_SNAKE_CASE       	=			(1,) + shape[1:]
      _SCREAMING_SNAKE_CASE       	=			[
          torch.randn(SCREAMING_SNAKE_CASE_      , generator=generator[i]      , device=SCREAMING_SNAKE_CASE_      , dtype=SCREAMING_SNAKE_CASE_      , layout=SCREAMING_SNAKE_CASE_  )
          for i in range(SCREAMING_SNAKE_CASE_  )
      ]
      _SCREAMING_SNAKE_CASE       	=			torch.cat(SCREAMING_SNAKE_CASE_      , dim=0  ).to(SCREAMING_SNAKE_CASE_  )
   else:
      _SCREAMING_SNAKE_CASE       	=			torch.randn(SCREAMING_SNAKE_CASE_      , generator=SCREAMING_SNAKE_CASE_      , device=SCREAMING_SNAKE_CASE_      , dtype=SCREAMING_SNAKE_CASE_      , layout=SCREAMING_SNAKE_CASE_  ).to(SCREAMING_SNAKE_CASE_  )

   return latents







def 				lowerCAmelCase_		(			SCREAMING_SNAKE_CASE_  )       ->       Any:




   """simple docstring"""
   if is_torch_version("""<"""      , """2.0.0"""  ) or not hasattr(SCREAMING_SNAKE_CASE_      , """_dynamo"""  ):
      return False
   return isinstance(SCREAMING_SNAKE_CASE_      , torch._dynamo.eval_frame.OptimizedModule  )








'''simple docstring'''



from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_torch_available,
)


UpperCamelCase__ :						List[str]    							=					{"configuration_gptj": ["GPTJ_PRETRAINED_CONFIG_ARCHIVE_MAP", "GPTJConfig", "GPTJOnnxConfig"]}

try:
     if not is_torch_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     UpperCamelCase__ :						Optional[Any]    							=					[
         "GPTJ_PRETRAINED_MODEL_ARCHIVE_LIST",
         "GPTJForCausalLM",
         "GPTJForQuestionAnswering",
         "GPTJForSequenceClassification",
         "GPTJModel",
         "GPTJPreTrainedModel",
     ]

try:
     if not is_tf_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     UpperCamelCase__ :						List[str]    							=					[
         "TFGPTJForCausalLM",
         "TFGPTJForQuestionAnswering",
         "TFGPTJForSequenceClassification",
         "TFGPTJModel",
         "TFGPTJPreTrainedModel",
     ]

try:
     if not is_flax_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     UpperCamelCase__ :						List[Any]    							=					[
         "FlaxGPTJForCausalLM",
         "FlaxGPTJModel",
         "FlaxGPTJPreTrainedModel",
     ]


if TYPE_CHECKING:
     from .configuration_gptj import GPTJ_PRETRAINED_CONFIG_ARCHIVE_MAP, GPTJConfig, GPTJOnnxConfig

     try:
          if not is_torch_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_gptj import (
              GPTJ_PRETRAINED_MODEL_ARCHIVE_LIST,
              GPTJForCausalLM,
              GPTJForQuestionAnswering,
              GPTJForSequenceClassification,
              GPTJModel,
              GPTJPreTrainedModel,
          )

     try:
          if not is_tf_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_tf_gptj import (
              TFGPTJForCausalLM,
              TFGPTJForQuestionAnswering,
              TFGPTJForSequenceClassification,
              TFGPTJModel,
              TFGPTJPreTrainedModel,
          )

     try:
          if not is_flax_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_flax_gptj import FlaxGPTJForCausalLM, FlaxGPTJModel, FlaxGPTJPreTrainedModel

else:
     import sys

     UpperCamelCase__ :						Any    							=					_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)






