


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

lowerCamelCase__    	=     logging.getLogger()






def  __lowerCAmelCase (__lowerCAmelCase   ):
		_UpperCAmelCase		:       Dict								=      {}
		_UpperCAmelCase		:       Dict								=      os.path.join(lowercase__      , "all_results.json"   )
		if os.path.exists(lowercase__   ):
				with open(lowercase__      , "r"   ) as f:
						_UpperCAmelCase		:       Optional[Any]								=      json.load(lowercase__   )
		else:
				raise ValueError(F"""can't find {path}"""   )
		return results


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






@require_torch_tpu
class 	lowerCAmelCase__			(			__a	):




			def 							lowerCAmelCase__    (		self  :     Optional[int] )   ->List[Any]:



					'''simple docstring'''







					import xla_spawn

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

					with patch.object(lowerCAmelCase_	,  "argv"	,  lowerCAmelCase_ ):
							_UpperCAmelCase		:       Union[str, Any]								=      time()
							xla_spawn.main()
							_UpperCAmelCase		:       List[Any]								=      time()

							_UpperCAmelCase		:       Any								=      get_results(lowerCAmelCase_ )
							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  :     Union[str, Any] )   ->Tuple:



					'''simple docstring'''







					import xla_spawn

					_UpperCAmelCase		:       Optional[int]								=      "\n            ./tests/test_trainer_tpu.py\n            --num_cores=8\n            ./tests/test_trainer_tpu.py\n            ".split()
					with patch.object(lowerCAmelCase_	,  "argv"	,  lowerCAmelCase_ ):
							xla_spawn.main()










'''simple docstring'''


from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


lowerCamelCase__    	=     {
    'configuration_instructblip': [
        'INSTRUCTBLIP_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'InstructBlipConfig',
        'InstructBlipQFormerConfig',
        'InstructBlipVisionConfig',
    ],
    'processing_instructblip': ['InstructBlipProcessor'],
}

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						lowerCamelCase__    	=     [
						    'INSTRUCTBLIP_PRETRAINED_MODEL_ARCHIVE_LIST',
						    'InstructBlipQFormerModel',
						    'InstructBlipPreTrainedModel',
						    'InstructBlipForConditionalGeneration',
						    'InstructBlipVisionModel',
						]

if TYPE_CHECKING:
						from .configuration_instructblip import (
						    INSTRUCTBLIP_PRETRAINED_CONFIG_ARCHIVE_MAP,
						    InstructBlipConfig,
						    InstructBlipQFormerConfig,
						    InstructBlipVisionConfig,
						)
						from .processing_instructblip import InstructBlipProcessor

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_instructblip import (
												    INSTRUCTBLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
												    InstructBlipForConditionalGeneration,
												    InstructBlipPreTrainedModel,
												    InstructBlipQFormerModel,
												    InstructBlipVisionModel,
												)

else:
						import sys

						lowerCamelCase__    	=     _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)



