






"""simple docstring"""







import logging
import os

from .state import PartialState







class    lowerCamelCase__   (			logging.LoggerAdapter					):






    @staticmethod
    def 							_UpperCamelCase				(					A   ):
          UpperCAmelCase							     =			PartialState()
          return not main_process_only or (main_process_only and state.is_main_process)






    def 							_UpperCamelCase				(					self      ,A      ,A      ,*A      ,**A   ):
          if PartialState._shared_state == {}:
                raise RuntimeError(
                    """You must initialize the accelerate state by calling either `PartialState()` or `Accelerator()` before using the logging utility."""   )
          UpperCAmelCase							     =			kwargs.pop("""main_process_only"""      ,snake_case_   )
          UpperCAmelCase							     =			kwargs.pop("""in_order"""      ,snake_case_   )

          if self.isEnabledFor(snake_case_   ):
                if self._should_log(snake_case_   ):
                      UpperCAmelCase							     =			self.process(snake_case_      ,snake_case_   )
                      self.logger.log(snake_case_      ,snake_case_      ,*snake_case_      ,**snake_case_   )

                elif in_order:
                      UpperCAmelCase							     =			PartialState()
                      for i in range(state.num_processes   ):
                            if i == state.process_index:
                                  UpperCAmelCase							     =			self.process(snake_case_      ,snake_case_   )
                                  self.logger.log(snake_case_      ,snake_case_      ,*snake_case_      ,**snake_case_   )
                            state.wait_for_everyone()







def _a					(						_snake_case ,			_snake_case = None				):







      """simple docstring"""






      if log_level is None:
            UpperCAmelCase							     =			os.environ.get("""ACCELERATE_LOG_LEVEL""" ,			_snake_case				)
      UpperCAmelCase							     =			logging.getLogger(_snake_case				)
      if log_level is not None:
            logger.setLevel(log_level.upper()				)
            logger.root.setLevel(log_level.upper()				)
      return MultiProcessAdapter(_snake_case ,			{}				)





import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin

class 							_UpperCamelCase					(       unittest.TestCase  ,							_A	):






			'''simple docstring'''

			def    lowerCAmelCase__						(							self			:							Tuple   ):
							UpperCamelCase_:				List[Any]						=    load_tool("""text-classification"""   )
							self.tool.setup()
							UpperCamelCase_:				Optional[int]						=    load_tool("""text-classification"""    ,						remote=snake_case_   )

			def    lowerCAmelCase__						(							self			:							Optional[Any]   ):
							UpperCamelCase_:				Union[str, Any]						=    self.tool("""That's quite cool"""    ,						["""positive""", """negative"""]   )
							self.assertEqual(snake_case_    ,						"""positive"""   )

			def    lowerCAmelCase__						(							self			:							int   ):
							UpperCamelCase_:				Tuple						=    self.remote_tool("""That's quite cool"""    ,						["""positive""", """negative"""]   )
							self.assertEqual(snake_case_    ,						"""positive"""   )

			def    lowerCAmelCase__						(							self			:							Optional[int]   ):
							UpperCamelCase_:				int						=    self.tool(text="""That's quite cool"""    ,						labels=["""positive""", """negative"""]   )
							self.assertEqual(snake_case_    ,						"""positive"""   )




			def    lowerCAmelCase__						(							self			:							Tuple   ):
							UpperCamelCase_:				List[Any]						=    self.remote_tool(text="""That's quite cool"""    ,						labels=["""positive""", """negative"""]   )
							self.assertEqual(snake_case_    ,						"""positive"""   )






