



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__       =	logging.getLogger()





def 							A     (					_UpperCAmelCase    :       List[str]   )    ->			Optional[Any]:







			'''simple docstring'''
			_UpperCAmelCase			=       {}
			_UpperCAmelCase			=       os.path.join(_UpperCAmelCase							,       'all_results.json'   )
			if os.path.exists(_UpperCAmelCase   ):
						with open(_UpperCAmelCase							,       'r'   ) as f:
									_UpperCAmelCase			=       json.load(_UpperCAmelCase   )
			else:
						raise ValueError(F"can't find {path}"   )
			return results


UpperCAmelCase__       =	logging.StreamHandler(sys.stdout)
logger.addHandler(stream_handler)







@require_torch_tpu
class       __lowerCAmelCase   (      A						):



			def    _lowerCamelCase	(						self       :  str)       ->   List[str]:



						"""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(A			,		'argv'			,		A):
									_UpperCAmelCase			=       time()
									xla_spawn.main()
									_UpperCAmelCase			=       time()

									_UpperCAmelCase			=       get_results(A)
									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			,		5_00)



			def    _lowerCamelCase	(						self       :  Tuple)       ->   Optional[Any]:



						"""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(A			,		'argv'			,		A):
									xla_spawn.main()











from typing import TYPE_CHECKING

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


UpperCAmelCase__       =	{
    "configuration_clip": [
        "CLIP_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "CLIPConfig",
        "CLIPOnnxConfig",
        "CLIPTextConfig",
        "CLIPVisionConfig",
    ],
    "processing_clip": ["CLIPProcessor"],
    "tokenization_clip": ["CLIPTokenizer"],
}

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

try:
							if not is_vision_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							UpperCAmelCase__       =	["CLIPFeatureExtractor"]
							UpperCAmelCase__       =	["CLIPImageProcessor"]

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							UpperCAmelCase__       =	[
							    "CLIP_PRETRAINED_MODEL_ARCHIVE_LIST",
							    "CLIPModel",
							    "CLIPPreTrainedModel",
							    "CLIPTextModel",
							    "CLIPTextModelWithProjection",
							    "CLIPVisionModel",
							    "CLIPVisionModelWithProjection",
							]

try:
							if not is_tf_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							UpperCAmelCase__       =	[
							    "TF_CLIP_PRETRAINED_MODEL_ARCHIVE_LIST",
							    "TFCLIPModel",
							    "TFCLIPPreTrainedModel",
							    "TFCLIPTextModel",
							    "TFCLIPVisionModel",
							]

try:
							if not is_flax_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							UpperCAmelCase__       =	[
							    "FlaxCLIPModel",
							    "FlaxCLIPPreTrainedModel",
							    "FlaxCLIPTextModel",
							    "FlaxCLIPTextPreTrainedModel",
							    "FlaxCLIPVisionModel",
							    "FlaxCLIPVisionPreTrainedModel",
							]


if TYPE_CHECKING:
							from .configuration_clip import (
							    CLIP_PRETRAINED_CONFIG_ARCHIVE_MAP,
							    CLIPConfig,
							    CLIPOnnxConfig,
							    CLIPTextConfig,
							    CLIPVisionConfig,
							)
							from .processing_clip import CLIPProcessor
							from .tokenization_clip import CLIPTokenizer

							try:
														if not is_tokenizers_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .tokenization_clip_fast import CLIPTokenizerFast

							try:
														if not is_vision_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .feature_extraction_clip import CLIPFeatureExtractor
														from .image_processing_clip import CLIPImageProcessor

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_clip import (
														    CLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
														    CLIPModel,
														    CLIPPreTrainedModel,
														    CLIPTextModel,
														    CLIPTextModelWithProjection,
														    CLIPVisionModel,
														    CLIPVisionModelWithProjection,
														)

							try:
														if not is_tf_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_tf_clip import (
														    TF_CLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
														    TFCLIPModel,
														    TFCLIPPreTrainedModel,
														    TFCLIPTextModel,
														    TFCLIPVisionModel,
														)

							try:
														if not is_flax_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_flax_clip import (
														    FlaxCLIPModel,
														    FlaxCLIPPreTrainedModel,
														    FlaxCLIPTextModel,
														    FlaxCLIPTextPreTrainedModel,
														    FlaxCLIPVisionModel,
														    FlaxCLIPVisionPreTrainedModel,
														)


else:
							import sys

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