


'''simple docstring'''

from typing import TYPE_CHECKING

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


__lowercase:		str    						=  {
    'configuration_openai': ['OPENAI_GPT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'OpenAIGPTConfig'],
    'tokenization_openai': ['OpenAIGPTTokenizer'],
}

try:
       if not is_tokenizers_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       __lowercase:		Tuple    						=  ['OpenAIGPTTokenizerFast']

try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       __lowercase:		List[Any]    						=  [
           '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:
       __lowercase:		List[str]    						=  [
           '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

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







'''simple docstring'''







import inspect
import os
import unittest

import torch

import accelerate
from accelerate import debug_launcher
from accelerate.test_utils import (
    execute_subprocess_async,
    require_cpu,
    require_multi_gpu,
    require_single_gpu,
    test_sync,
)
from accelerate.utils import patch_environment






class        a__     (      unittest.TestCase    ):
     '''simple docstring'''







     def      _UpperCamelCase (self     :						int       )	->							Optional[int]:
           __A		 =   inspect.getfile(accelerate.test_utils       )
           __A		 =   os.path.sep.join(mod_file.split(os.path.sep       )[:-1] + ["scripts", "test_sync.py"]       )






     @require_cpu
     def      _UpperCamelCase (self     :						str       )	->							Optional[Any]:
           debug_launcher(test_sync.main					,					num_processes=1       )






     @require_cpu
     def      _UpperCamelCase (self     :						Union[str, Any]       )	->							Optional[Any]:
           debug_launcher(test_sync.main       )






     @require_single_gpu
     def      _UpperCamelCase (self     :						Union[str, Any]       )	->							List[str]:
           test_sync.main()






     @require_multi_gpu
     def      _UpperCamelCase (self     :						Optional[int]       )	->							List[str]:
           print(f"Found {torch.cuda.device_count()} devices."       )
           __A		 =   ["torchrun", f"--nproc_per_node={torch.cuda.device_count()}", self.test_file_path]
           with patch_environment(omp_num_threads=1       ):
                 execute_subprocess_async(lowercase__					,					env=os.environ.copy()       )


