






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



def 				snake_case       (  a_				:			List[Any]						)							->					Optional[int]:





      """simple docstring"""

      UpperCamelCase_					: List[Any]            =				{}
      UpperCamelCase_					: Optional[Any]            =				os.path.join(a_     , """all_results.json"""						)
      if os.path.exists(a_						):
            with open(a_     , """r"""						) as f:
                  UpperCamelCase_					: Optional[Any]            =				json.load(a_						)
      else:
            raise ValueError(f"can't find {path}"						)
      return results


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




@require_torch_tpu
class      A     (   SCREAMING_SNAKE_CASE__    ):






 """simple docstring"""





 def 	_UpperCAmelCase							(				self			):
       import xla_spawn

       UpperCamelCase_					: Union[str, Any]            =				self.get_auto_remove_tmp_dir()
       UpperCamelCase_					: Union[str, Any]            =				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(__lowerCAmelCase      ,  """argv"""      ,  __lowerCAmelCase			):
             UpperCamelCase_					: Optional[int]            =				time()
             xla_spawn.main()
             UpperCamelCase_					: Tuple            =				time()

             UpperCamelCase_					: str            =				get_results(__lowerCAmelCase			)
             self.assertGreaterEqual(result["""eval_accuracy"""]      ,  0.75			)

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





 def 	_UpperCAmelCase							(				self			):
       import xla_spawn

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














'''simple docstring'''

import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin


UpperCamelCase      					="\nHugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf originally as a company that developed a chatbot app targeted at teenagers.[2] After open-sourcing the model behind the chatbot, the company pivoted to focus on being a platform for machine learning.\n\nIn March 2021, Hugging Face raised $40 million in a Series B funding round.[3]\n\nOn April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model.[4] In 2022, the workshop concluded with the announcement of BLOOM, a multilingual large language model with 176 billion parameters.[5]\n"




class      A     (   unittest.TestCase, SCREAMING_SNAKE_CASE__    ):






 """simple docstring"""





 def 	_UpperCAmelCase							(				self			):
       UpperCamelCase_					: Optional[Any]            =				load_tool("""text-question-answering"""			)
       self.tool.setup()
       UpperCamelCase_					: List[str]            =				load_tool("""text-question-answering"""      ,  remote=__lowerCAmelCase			)
 def 	_UpperCAmelCase							(				self			):
       UpperCamelCase_					: Union[str, Any]            =				self.tool(__lowerCAmelCase      ,  """What did Hugging Face do in April 2021?"""			)
       self.assertEqual(__lowerCAmelCase      ,  """launched the BigScience Research Workshop"""			)
 def 	_UpperCAmelCase							(				self			):
       UpperCamelCase_					: Optional[Any]            =				self.remote_tool(__lowerCAmelCase      ,  """What did Hugging Face do in April 2021?"""			)
       self.assertEqual(__lowerCAmelCase      ,  """launched the BigScience Research Workshop"""			)
 def 	_UpperCAmelCase							(				self			):
       UpperCamelCase_					: List[Any]            =				self.tool(text=__lowerCAmelCase      ,  question="""What did Hugging Face do in April 2021?"""			)
       self.assertEqual(__lowerCAmelCase      ,  """launched the BigScience Research Workshop"""			)





 def 	_UpperCAmelCase							(				self			):
       UpperCamelCase_					: Dict            =				self.remote_tool(text=__lowerCAmelCase      ,  question="""What did Hugging Face do in April 2021?"""			)
       self.assertEqual(__lowerCAmelCase      ,  """launched the BigScience Research Workshop"""			)






