




'''simple docstring'''





import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin







class 		__UpperCAmelCase(		lowerCamelCase_ ):





     """simple docstring"""



     __UpperCAmelCase	: Union[str, Any]						=    ["""image_processor""", """tokenizer"""]
     __UpperCAmelCase	: Union[str, Any]						=    """AutoImageProcessor"""
     __UpperCAmelCase	: Any						=    """AutoTokenizer"""

     def __init__(      self :       int						,				A :       Tuple=None						,				A :       Union[str, Any]=None						,				**A :       Any    )			->			Optional[Any]:






         """simple docstring"""
         a__      =       None
         if "feature_extractor" in kwargs:
             warnings.warn(
                 """The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"""
                 """ instead."""						,				A						,				)
             a__      =       kwargs.pop("""feature_extractor"""    )

         a__      =       image_processor if image_processor is not None else feature_extractor
         if image_processor is None:
             raise ValueError("""You need to specify an `image_processor`."""    )
         if tokenizer is None:
             raise ValueError("""You need to specify a `tokenizer`."""    )

         super().__init__(A						,				A    )
         a__      =       self.image_processor
         a__      =       False

     def __call__(      self :       Optional[Any]						,				*A :       int						,				**A :       List[str]    )			->			Union[str, Any]:






         """simple docstring"""







         if self._in_target_context_manager:
             return self.current_processor(*A						,				**A    )

         a__      =       kwargs.pop("""images"""						,				A    )
         a__      =       kwargs.pop("""text"""						,				A    )
         if len(A    ) > 0:
             a__      =       args[0]
             a__      =       args[1:]

         if images is None and text is None:
             raise ValueError("""You need to specify either an `images` or `text` input to process."""    )

         if images is not None:
             a__      =       self.image_processor(A						,				*A						,				**A    )
         if text is not None:
             a__      =       self.tokenizer(A						,				**A    )

         if text is None:
             return inputs
         elif images is None:
             return encodings
         else:
             a__      =       encodings["input_ids"]
             return inputs

     def 				__SCREAMING_SNAKE_CASE		(      self :       Optional[Any]						,				*A :       Optional[Any]						,				**A :       int    )			->			Dict:






         """simple docstring"""
         return self.tokenizer.batch_decode(*A						,				**A    )

     def 				__SCREAMING_SNAKE_CASE		(      self :       List[str]						,				*A :       Any						,				**A :       List[Any]    )			->			Optional[int]:






         """simple docstring"""
         return self.tokenizer.decode(*A						,				**A    )

     @contextmanager
     def 				__SCREAMING_SNAKE_CASE		(      self :       Tuple    )			->			Dict:






         """simple docstring"""
         warnings.warn(
             """`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your """
             """labels by using the argument `text` of the regular `__call__` method (either in the same call as """
             """your images inputs, or in a separate call."""    )
         a__      =       True
         a__      =       self.tokenizer
         yield
         a__      =       self.image_processor
         a__      =       False

     @property
     def 				__SCREAMING_SNAKE_CASE		(      self :       Optional[int]    )			->			Optional[Any]:






         """simple docstring"""
         warnings.warn(
             """`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead."""						,				A						,				)
         return self.image_processor_class






     @property
     def 				__SCREAMING_SNAKE_CASE		(      self :       int    )			->			Any:






         """simple docstring"""
         warnings.warn(
             """`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead."""						,				A						,				)
         return self.image_processor












import warnings
from dataclasses import dataclass, field
from typing import Optional, Tuple

from .training_args import TrainingArguments
from .utils import cached_property, is_tf_available, logging, requires_backends


SCREAMING_SNAKE_CASE_						:					Optional[Any]			   =       logging.get_logger(__name__)

if is_tf_available():
 import tensorflow as tf







@dataclass
class 		__UpperCAmelCase(		lowercase__ ):





     """simple docstring"""



     __UpperCAmelCase	: int						=    """tf"""
     __UpperCAmelCase	: Optional[str]						=    field(
         default=lowercase__       ,	metadata={"""help""": """Name of TPU"""}       ,	)

     __UpperCAmelCase	: Optional[str]						=    field(
         default=lowercase__       ,	metadata={"""help""": """Zone of TPU"""}       ,	)

     __UpperCAmelCase	: Optional[str]						=    field(
         default=lowercase__       ,	metadata={"""help""": """Name of Cloud TPU-enabled project"""}       ,	)

     __UpperCAmelCase	: float						=    field(
         default=1.0       ,	metadata={"""help""": """Power for the Polynomial decay LR scheduler."""}       ,	)

     __UpperCAmelCase	: bool						=    field(default=lowercase__       ,	metadata={"""help""": """Whether to activate the XLA compilation or not"""} )

     @cached_property
     def 				__SCREAMING_SNAKE_CASE		(      self :       Dict    )			->			Tuple["tf.distribute.Strategy", int]:






         """simple docstring"""
         requires_backends(self						,				["""tf"""]    )
         logger.info("""Tensorflow: setting up strategy"""    )

         a__      =       tf.config.list_physical_devices("""GPU"""    )

         # Set to float16 at first
         if self.fpaa:
             tf.keras.mixed_precision.set_global_policy("""mixed_float16"""    )

         if self.no_cuda:
             a__      =       tf.distribute.OneDeviceStrategy(device="""/cpu:0"""    )
         else:
             try:
                 if self.tpu_name:
                     a__      =       tf.distribute.cluster_resolver.TPUClusterResolver(
                         self.tpu_name						,				zone=self.tpu_zone						,				project=self.gcp_project    )
                 else:
                     a__      =       tf.distribute.cluster_resolver.TPUClusterResolver()
             except ValueError:
                 if self.tpu_name:
                     raise RuntimeError(f"""Couldn't connect to TPU {self.tpu_name}!"""    )
                 else:
                     a__      =       None

             if tpu:
                 # Set to bfloat16 in case of TPU
                 if self.fpaa:
                     tf.keras.mixed_precision.set_global_policy("""mixed_bfloat16"""    )

                 tf.config.experimental_connect_to_cluster(A    )
                 tf.tpu.experimental.initialize_tpu_system(A    )

                 a__      =       tf.distribute.TPUStrategy(A    )

             elif len(A    ) == 0:
                 a__      =       tf.distribute.OneDeviceStrategy(device="""/cpu:0"""    )
             elif len(A    ) == 1:
                 a__      =       tf.distribute.OneDeviceStrategy(device="""/gpu:0"""    )
             elif len(A    ) > 1:
                 # If you only want to use a specific subset of GPUs use `CUDA_VISIBLE_DEVICES=0`
                 a__      =       tf.distribute.MirroredStrategy()
             else:
                 raise ValueError("""Cannot find the proper strategy, please check your environment properties."""    )

         return strategy

     @property
     def 				__SCREAMING_SNAKE_CASE		(      self :       Tuple    )			->			"tf.distribute.Strategy":






         """simple docstring"""
         requires_backends(self						,				["""tf"""]    )
         return self._setup_strategy

     @property
     def 				__SCREAMING_SNAKE_CASE		(      self :       Dict    )			->			int:






         """simple docstring"""
         requires_backends(self						,				["""tf"""]    )
         return self._setup_strategy.num_replicas_in_sync

     @property
     def 				__SCREAMING_SNAKE_CASE		(      self :       Dict    )			->			List[Any]:






         """simple docstring"""
         return False  # TF Logging is handled by Keras not the Trainer

     @property
     def 				__SCREAMING_SNAKE_CASE		(      self :       Optional[Any]    )			->			int:






         """simple docstring"""
         if self.per_gpu_train_batch_size:
             logger.warning(
                 """Using deprecated `--per_gpu_train_batch_size` argument which will be removed in a future """
                 """version. Using `--per_device_train_batch_size` is preferred."""    )
         a__      =       self.per_gpu_train_batch_size or self.per_device_train_batch_size
         return per_device_batch_size * self.n_replicas

     @property
     def 				__SCREAMING_SNAKE_CASE		(      self :       List[str]    )			->			int:






         """simple docstring"""
         if self.per_gpu_eval_batch_size:
             logger.warning(
                 """Using deprecated `--per_gpu_eval_batch_size` argument which will be removed in a future """
                 """version. Using `--per_device_eval_batch_size` is preferred."""    )
         a__      =       self.per_gpu_eval_batch_size or self.per_device_eval_batch_size
         return per_device_batch_size * self.n_replicas






     @property
     def 				__SCREAMING_SNAKE_CASE		(      self :       str    )			->			int:






         """simple docstring"""
         requires_backends(self						,				["""tf"""]    )
         warnings.warn(
             """The n_gpu argument is deprecated and will be removed in a future version, use n_replicas instead."""						,				A						,				)
         return self._setup_strategy.num_replicas_in_sync






