
"""simple docstring"""

import json
import logging
import os
import sys
from time import time
from unittest.mock import patch

from transformers.testing_utils import TestCasePlus, require_torch_tpu


logging.basicConfig(level=logging.DEBUG)

UpperCamelCase			:       List[Any]									=				logging.getLogger()






def 							A		(       snake_case   :Any	)   ->			Union[str, Any]:
 __UpperCamelCase       						= {}
 __UpperCamelCase       						= os.path.join(snake_case       ,      'all_results.json'	)
 if os.path.exists(snake_case	):
  with open(snake_case       ,      'r'	) as f:
   __UpperCamelCase       						= json.load(snake_case	)
 else:
  raise ValueError(f'can\'t find {path}'	)
 return results


UpperCamelCase			:       Union[str, Any]									=				logging.StreamHandler(sys.stdout)
logger.addHandler(stream_handler)





@require_torch_tpu
class __lowerCAmelCase	(   __SCREAMING_SNAKE_CASE    ):





     def 		UpperCAmelCase      (			self   ):

      '''simple docstring'''




      import xla_spawn

      __UpperCamelCase       						= self.get_auto_remove_tmp_dir()
      __UpperCamelCase       						= F'\n            ./examples/pytorch/text-classification/run_glue.py\n            --num_cores=8\n            ./examples/pytorch/text-classification/run_glue.py\n            --model_name_or_path distilbert-base-uncased\n            --output_dir {tmp_dir}\n            --overwrite_output_dir\n            --train_file ./tests/fixtures/tests_samples/MRPC/train.csv\n            --validation_file ./tests/fixtures/tests_samples/MRPC/dev.csv\n            --do_train\n            --do_eval\n            --debug tpu_metrics_debug\n            --per_device_train_batch_size=2\n            --per_device_eval_batch_size=1\n            --learning_rate=1e-4\n            --max_steps=10\n            --warmup_steps=2\n            --seed=42\n            --max_seq_length=128\n            '.split()

      with patch.object(__UpperCAmelCase			,  'argv'			,  __UpperCAmelCase   ):
       __UpperCamelCase       						= time()
       xla_spawn.main()
       __UpperCamelCase       						= time()

       __UpperCamelCase       						= get_results(__UpperCAmelCase   )
       self.assertGreaterEqual(result['eval_accuracy']			,  0.7_5   )

       # Assert that the script takes less than 500 seconds to make sure it doesn't hang.
       self.assertLess(end - start			,  500   )







     def 		UpperCAmelCase      (			self   ):

      '''simple docstring'''




      import xla_spawn

      __UpperCamelCase       						= '\n            ./tests/test_trainer_tpu.py\n            --num_cores=8\n            ./tests/test_trainer_tpu.py\n            '.split()
      with patch.object(__UpperCAmelCase			,  'argv'			,  __UpperCAmelCase   ):
       xla_spawn.main()





"""simple docstring"""

from typing import TYPE_CHECKING

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


UpperCamelCase			:       Dict									=				{
    "configuration_lxmert": ["LXMERT_PRETRAINED_CONFIG_ARCHIVE_MAP", "LxmertConfig"],
    "tokenization_lxmert": ["LxmertTokenizer"],
}

try:
      if not is_tokenizers_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      UpperCamelCase			:       List[str]									=				["LxmertTokenizerFast"]

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      UpperCamelCase			:       Optional[Any]									=				[
          "LxmertEncoder",
          "LxmertForPreTraining",
          "LxmertForQuestionAnswering",
          "LxmertModel",
          "LxmertPreTrainedModel",
          "LxmertVisualFeatureEncoder",
          "LxmertXLayer",
      ]

try:
      if not is_tf_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      UpperCamelCase			:       List[Any]									=				[
          "TF_LXMERT_PRETRAINED_MODEL_ARCHIVE_LIST",
          "TFLxmertForPreTraining",
          "TFLxmertMainLayer",
          "TFLxmertModel",
          "TFLxmertPreTrainedModel",
          "TFLxmertVisualFeatureEncoder",
      ]


if TYPE_CHECKING:
      from .configuration_lxmert import LXMERT_PRETRAINED_CONFIG_ARCHIVE_MAP, LxmertConfig
      from .tokenization_lxmert import LxmertTokenizer

      try:
            if not is_tokenizers_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .tokenization_lxmert_fast import LxmertTokenizerFast

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_lxmert import (
                LxmertEncoder,
                LxmertForPreTraining,
                LxmertForQuestionAnswering,
                LxmertModel,
                LxmertPreTrainedModel,
                LxmertVisualFeatureEncoder,
                LxmertXLayer,
            )

      try:
            if not is_tf_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_tf_lxmert import (
                TF_LXMERT_PRETRAINED_MODEL_ARCHIVE_LIST,
                TFLxmertForPreTraining,
                TFLxmertMainLayer,
                TFLxmertModel,
                TFLxmertPreTrainedModel,
                TFLxmertVisualFeatureEncoder,
            )

else:
      import sys

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



