

'''simple docstring'''



from typing import TYPE_CHECKING

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


SCREAMING_SNAKE_CASE_    =   {
    "configuration_openai": ["OPENAI_GPT_PRETRAINED_CONFIG_ARCHIVE_MAP", "OpenAIGPTConfig"],
    "tokenization_openai": ["OpenAIGPTTokenizer"],
}

try:
   if not is_tokenizers_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   SCREAMING_SNAKE_CASE_    =   ["OpenAIGPTTokenizerFast"]

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   SCREAMING_SNAKE_CASE_    =   [
       "OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST",
       "OpenAIGPTDoubleHeadsModel",
       "OpenAIGPTForSequenceClassification",
       "OpenAIGPTLMHeadModel",
       "OpenAIGPTModel",
       "OpenAIGPTPreTrainedModel",
       "load_tf_weights_in_openai_gpt",
   ]

try:
   if not is_tf_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   SCREAMING_SNAKE_CASE_    =   [
       "TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST",
       "TFOpenAIGPTDoubleHeadsModel",
       "TFOpenAIGPTForSequenceClassification",
       "TFOpenAIGPTLMHeadModel",
       "TFOpenAIGPTMainLayer",
       "TFOpenAIGPTModel",
       "TFOpenAIGPTPreTrainedModel",
   ]


if TYPE_CHECKING:
   from .configuration_openai import OPENAI_GPT_PRETRAINED_CONFIG_ARCHIVE_MAP, OpenAIGPTConfig
   from .tokenization_openai import OpenAIGPTTokenizer

   try:
      if not is_tokenizers_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .tokenization_openai_fast import OpenAIGPTTokenizerFast

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_openai import (
          OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST,
          OpenAIGPTDoubleHeadsModel,
          OpenAIGPTForSequenceClassification,
          OpenAIGPTLMHeadModel,
          OpenAIGPTModel,
          OpenAIGPTPreTrainedModel,
          load_tf_weights_in_openai_gpt,
      )

   try:
      if not is_tf_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_tf_openai import (
          TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST,
          TFOpenAIGPTDoubleHeadsModel,
          TFOpenAIGPTForSequenceClassification,
          TFOpenAIGPTLMHeadModel,
          TFOpenAIGPTMainLayer,
          TFOpenAIGPTModel,
          TFOpenAIGPTPreTrainedModel,
      )

else:
   import sys

   SCREAMING_SNAKE_CASE_    =   _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)






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

SCREAMING_SNAKE_CASE_    =   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)		->    Optional[Any]:



       """simple docstring"""







       return cls

def   lowerCamelCase__       (      a__			,      a__ = None			,      a__ = None			,      a__ = None			,      a__ = None			,      )		->    Dict:



    """simple docstring"""







    _snake_case : Optional[Any]												=		device
    _snake_case : Any												=		shape[0]

    _snake_case : str												=		layout or torch.strided
    _snake_case : str												=		device or torch.device('cpu')

    if generator is not None:
        _snake_case : Any												=		generator.device.type if not isinstance(a__			,      a__) else generator[0].device.type
        if gen_device_type != device.type and gen_device_type == "cpu":
            _snake_case : Optional[Any]												=		'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(a__			,      a__):
        _snake_case : Any												=		(1,) + shape[1:]
        _snake_case : int												=		[
            torch.randn(a__			,      generator=generator[i]			,      device=a__			,      dtype=a__			,      layout=a__)
            for i in range(a__)
        ]
        _snake_case : Optional[int]												=		torch.cat(a__			,      dim=0).to(a__)
    else:
        _snake_case : Optional[Any]												=		torch.randn(a__			,      generator=a__			,      device=a__			,      dtype=a__			,      layout=a__).to(a__)

    return latents




def   lowerCamelCase__       (      a__)		->    Optional[Any]:



    """simple docstring"""







    if is_torch_version('<'			,      '2.0.0') or not hasattr(a__			,      '_dynamo'):
        return False
    return isinstance(a__			,      torch._dynamo.eval_frame.OptimizedModule)



