'''simple docstring'''
import re
import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin






class 			__lowercase		(						__lowercase						):







					"""simple docstring"""






					SCREAMING_SNAKE_CASE__		   =						['''image_processor''', '''tokenizer''']
					SCREAMING_SNAKE_CASE__		   =						'''AutoImageProcessor'''
					SCREAMING_SNAKE_CASE__		   =						'''AutoTokenizer'''







					def __init__(		self     ,			_lowerCamelCase=None     ,			_lowerCamelCase=None     ,			**_lowerCamelCase    ):
									__UpperCamelCase	:	int		    =  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     ,			)
													__UpperCamelCase	:	str		    =  kwargs.pop('feature_extractor'    )

									__UpperCamelCase	:	List[Any]		    =  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    )
									__UpperCamelCase	:	Any		    =  self.image_processor
									__UpperCamelCase	:	Any		    =  False







					def __call__(		self     ,			*_lowerCamelCase     ,			**_lowerCamelCase    ):
									# For backward compatibility
									if self._in_target_context_manager:
													return self.current_processor(*__a     ,			**__a    )

									__UpperCamelCase	:	List[Any]		    =  kwargs.pop('images'     ,			__a    )
									__UpperCamelCase	:	List[str]		    =  kwargs.pop('text'     ,			__a    )
									if len(__a    ) > 0:
													__UpperCamelCase	:	Any		    =  args[0]
													__UpperCamelCase	:	List[Any]		    =  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:
													__UpperCamelCase	:	str		    =  self.image_processor(__a     ,			*__a     ,			**__a    )
									if text is not None:
													__UpperCamelCase	:	Union[str, Any]		    =  self.tokenizer(__a     ,			**__a    )

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







					def lowerCAmelCase     (		self     ,			*_lowerCamelCase     ,			**_lowerCamelCase    ):
									return self.tokenizer.batch_decode(*__a     ,			**__a    )







					def lowerCAmelCase     (		self     ,			*_lowerCamelCase     ,			**_lowerCamelCase    ):
									return self.tokenizer.decode(*__a     ,			**__a    )







					@contextmanager
					def lowerCAmelCase     (		self    ):
									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.'    )
									__UpperCamelCase	:	List[str]		    =  True
									__UpperCamelCase	:	int		    =  self.tokenizer
									yield
									__UpperCamelCase	:	str		    =  self.image_processor
									__UpperCamelCase	:	Union[str, Any]		    =  False







					def lowerCAmelCase     (		self     ,			_lowerCamelCase     ,			_lowerCamelCase=False     ,			_lowerCamelCase=None    ):
									if added_vocab is None:
													__UpperCamelCase	:	Optional[Any]		    =  self.tokenizer.get_added_vocab()

									__UpperCamelCase	:	Dict		    =  {}

									while tokens:
													__UpperCamelCase	:	Union[str, Any]		    =  re.search(R'<s_(.*?)>'     ,			__a     ,			re.IGNORECASE    )
													if start_token is None:
																	break
													__UpperCamelCase	:	List[Any]		    =  start_token.group(1    )
													__UpperCamelCase	:	Optional[int]		    =  re.search(Rf"""</s_{key}>"""     ,			__a     ,			re.IGNORECASE    )
													__UpperCamelCase	:	int		    =  start_token.group()
													if end_token is None:
																	__UpperCamelCase	:	Any		    =  tokens.replace(__a     ,			''    )
													else:
																	__UpperCamelCase	:	Any		    =  end_token.group()
																	__UpperCamelCase	:	Tuple		    =  re.escape(__a    )
																	__UpperCamelCase	:	Optional[Any]		    =  re.escape(__a    )
																	__UpperCamelCase	:	Dict		    =  re.search(f"""{start_token_escaped}(.*?){end_token_escaped}"""     ,			__a     ,			re.IGNORECASE    )
																	if content is not None:
																					__UpperCamelCase	:	List[str]		    =  content.group(1    ).strip()
																					if r"<s_" in content and r"</s_" in content:  # non-leaf node
																									__UpperCamelCase	:	Any		    =  self.tokenajson(__a     ,			is_inner_value=__a     ,			added_vocab=__a    )
																									if value:
																													if len(__a    ) == 1:
																																	__UpperCamelCase	:	str		    =  value[0]
																													__UpperCamelCase	:	List[Any]		    =  value
																					else:  # leaf nodes
																									__UpperCamelCase	:	List[Any]		    =  []
																									for leaf in content.split(R'<sep/>'    ):
																													__UpperCamelCase	:	Optional[Any]		    =  leaf.strip()
																													if leaf in added_vocab and leaf[0] == "<" and leaf[-2:] == "/>":
																																	__UpperCamelCase	:	Optional[Any]		    =  leaf[1:-2]  # for categorical special tokens
																													output[key].append(__a    )
																									if len(output[key]    ) == 1:
																													__UpperCamelCase	:	Optional[Any]		    =  output[key][0]

																	__UpperCamelCase	:	Tuple		    =  tokens[tokens.find(__a    ) + len(__a    ) :].strip()
																	if tokens[:6] == r"<sep/>":  # non-leaf nodes
																					return [output] + self.tokenajson(tokens[6:]     ,			is_inner_value=__a     ,			added_vocab=__a    )

									if len(__a    ):
													return [output] if is_inner_value else output
									else:
													return [] if is_inner_value else {"text_sequence": tokens}







					@property
					def lowerCAmelCase     (		self    ):
									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 lowerCAmelCase     (		self    ):
									warnings.warn(
									    '`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.'     ,			__a     ,			)
									return self.image_processor




'''simple docstring'''
a=  '''0.21.0'''

from .accelerator import Accelerator
from .big_modeling import (
    cpu_offload,
    cpu_offload_with_hook,
    disk_offload,
    dispatch_model,
    init_empty_weights,
    init_on_device,
    load_checkpoint_and_dispatch,
)
from .data_loader import skip_first_batches
from .launchers import debug_launcher, notebook_launcher
from .state import PartialState
from .utils import (
    DeepSpeedPlugin,
    DistributedDataParallelKwargs,
    DistributedType,
    FullyShardedDataParallelPlugin,
    GradScalerKwargs,
    InitProcessGroupKwargs,
    find_executable_batch_size,
    infer_auto_device_map,
    is_rich_available,
    load_checkpoint_in_model,
    synchronize_rng_states,
)


if is_rich_available():
  from .utils import rich



