
import logging
import os

from .state import PartialState

class 							_UpperCamelCase					(       logging.LoggerAdapter	):






			'''simple docstring'''

			@staticmethod
			def    lowerCAmelCase__						(							snake_case_			:							Optional[int]   ):
							UpperCamelCase_:				str						=    PartialState()
							return not main_process_only or (main_process_only and state.is_main_process)




			def    lowerCAmelCase__						(							self			:							Any    ,						snake_case_			:							Union[str, Any]    ,						snake_case_			:							Union[str, Any]    ,						*snake_case_			:							Tuple    ,						**snake_case_			:							Optional[int]   ):
							if PartialState._shared_state == {}:
											raise RuntimeError(
											    """You must initialize the accelerate state by calling either `PartialState()` or `Accelerator()` before using the logging utility."""   )
							UpperCamelCase_:				Union[str, Any]						=    kwargs.pop("""main_process_only"""    ,						snake_case_   )
							UpperCamelCase_:				Union[str, Any]						=    kwargs.pop("""in_order"""    ,						snake_case_   )

							if self.isEnabledFor(snake_case_   ):
											if self._should_log(snake_case_   ):
															UpperCamelCase_, UpperCamelCase_:				Union[str, Any]						=    self.process(snake_case_    ,						snake_case_   )
															self.logger.log(snake_case_    ,						snake_case_    ,						*snake_case_    ,						**snake_case_   )

											elif in_order:
															UpperCamelCase_:				List[Any]						=    PartialState()
															for i in range(state.num_processes   ):
																			if i == state.process_index:
																							UpperCamelCase_, UpperCamelCase_:				Union[str, Any]						=    self.process(snake_case_    ,						snake_case_   )
																							self.logger.log(snake_case_    ,						snake_case_    ,						*snake_case_    ,						**snake_case_   )
																			state.wait_for_everyone()







def 							A__       (    lowerCamelCase  ,     lowerCamelCase = None    )	->						str:
				if log_level is None:
								UpperCamelCase_:				str						=    os.environ.get("""ACCELERATE_LOG_LEVEL"""  ,     lowerCamelCase    )
				UpperCamelCase_:				Union[str, Any]						=    logging.getLogger(lowerCamelCase    )
				if log_level is not None:
								logger.setLevel(log_level.upper()    )
								logger.root.setLevel(log_level.upper()    )
				return MultiProcessAdapter(lowerCamelCase  ,     {}    )








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






