





import torch

from accelerate import Accelerator, DistributedType







class 						_lowerCAmelCase:

  """simple docstring"""







  def __enter__( self     )-> List[Any]:
     if self.enabled:
        __A				 =       self.model.no_sync()
        self.model_sync_obj.__enter__()

     return self

  def __exit__( self  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase     )-> List[str]:
     if self.enabled:
        # Average all models on exit
        self._sync_and_avg_model_params()
        self.model_sync_obj.__exit__(UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase     )

  def __init__( self  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase  ,    UpperCAmelCase = True     )-> List[Any]:
     if accelerator.distributed_type not in [
         DistributedType.NO,
         DistributedType.MULTI_CPU,
         DistributedType.MULTI_GPU,
     ]:
        raise NotImplementedError('''LocalSGD is supported only for CPUs and GPUs (no DeepSpeed or MegatronLM)'''     )
     __A				 =       enabled and accelerator.distributed_type != DistributedType.NO
     __A				 =       0
     if self.enabled:
        __A				 =       accelerator
        __A				 =       model
        __A				 =       local_sgd_steps

  def 		SCREAMING_SNAKE_CASE__	( self     )-> Union[str, Any]:
     self.num_steps += 1
     if not self.enabled:
        return

     if self.num_steps % self.local_sgd_steps == 0:
        self._sync_and_avg_model_params()





  def 		SCREAMING_SNAKE_CASE__	( self     )-> List[Any]:
     self.accelerator.wait_for_everyone()
     with self.accelerator.autocast():
        for param in self.model.parameters():
           __A				 =       self.accelerator.reduce(param.data  ,    reduction='''mean'''     )








import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin


_UpperCamelCase   :							str     =	"""
Hugging 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.

In March 2021, Hugging Face raised $40 million in a Series B funding round.[3]

On 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]
"""







class 						_lowerCAmelCase(						unittest.TestCase		,   _a):

  """simple docstring"""







  def 		SCREAMING_SNAKE_CASE__	( self     )-> int:
     __A				 =       load_tool('''summarization'''     )
     self.tool.setup()
     __A				 =       load_tool('''summarization'''  ,    remote=UpperCAmelCase     )

  def 		SCREAMING_SNAKE_CASE__	( self     )-> List[str]:
     __A				 =       self.tool(UpperCAmelCase     )
     self.assertEqual(
         UpperCAmelCase  ,    '''Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'''  ,    )

  def 		SCREAMING_SNAKE_CASE__	( self     )-> Dict:
     __A				 =       self.remote_tool(UpperCAmelCase     )
     self.assertEqual(
         UpperCAmelCase  ,    '''Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'''  ,    )

  def 		SCREAMING_SNAKE_CASE__	( self     )-> Union[str, Any]:
     __A				 =       self.tool(text=UpperCAmelCase     )
     self.assertEqual(
         UpperCAmelCase  ,    '''Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'''  ,    )





  def 		SCREAMING_SNAKE_CASE__	( self     )-> Optional[Any]:
     __A				 =       self.remote_tool(text=UpperCAmelCase     )
     self.assertEqual(
         UpperCAmelCase  ,    '''Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'''  ,    )

