




'''simple docstring'''





import warnings

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding

class   _a							(		__lowerCAmelCase				):
     SCREAMING_SNAKE_CASE_				:       Optional[int]       							=		["""image_processor""", """tokenizer"""]
     SCREAMING_SNAKE_CASE_				:       Tuple       							=		"""CLIPImageProcessor"""
     SCREAMING_SNAKE_CASE_				:       Dict       							=		("""XLMRobertaTokenizer""", """XLMRobertaTokenizerFast""")






     def __init__(					self   ,_SCREAMING_SNAKE_CASE=None   ,_SCREAMING_SNAKE_CASE=None   ,**_SCREAMING_SNAKE_CASE       )				->     Any:
          _snake_case				= None
          if "feature_extractor" in kwargs:
               warnings.warn(
                   "The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"
                   " instead."   ,_SCREAMING_SNAKE_CASE   ,)
               _snake_case				= kwargs.pop("feature_extractor"       )

          _snake_case				= 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__(_SCREAMING_SNAKE_CASE   ,_SCREAMING_SNAKE_CASE       )






     def __call__(					self   ,_SCREAMING_SNAKE_CASE=None   ,_SCREAMING_SNAKE_CASE=None   ,_SCREAMING_SNAKE_CASE=None   ,**_SCREAMING_SNAKE_CASE       )				->     Optional[int]:

          if text is None and images is None:
               raise ValueError("You have to specify either text or images. Both cannot be none."       )

          if text is not None:
               _snake_case				= self.tokenizer(_SCREAMING_SNAKE_CASE   ,return_tensors=_SCREAMING_SNAKE_CASE   ,**_SCREAMING_SNAKE_CASE       )

          if images is not None:
               _snake_case				= self.image_processor(_SCREAMING_SNAKE_CASE   ,return_tensors=_SCREAMING_SNAKE_CASE   ,**_SCREAMING_SNAKE_CASE       )

          if text is not None and images is not None:
               _snake_case				= image_features.pixel_values
               return encoding
          elif text is not None:
               return encoding
          else:
               return BatchEncoding(data=dict(**_SCREAMING_SNAKE_CASE       )   ,tensor_type=_SCREAMING_SNAKE_CASE       )






     def 							_lowercase      (					self   ,*_SCREAMING_SNAKE_CASE   ,**_SCREAMING_SNAKE_CASE       )				->     int:
          return self.tokenizer.batch_decode(*_SCREAMING_SNAKE_CASE   ,**_SCREAMING_SNAKE_CASE       )






     def 							_lowercase      (					self   ,*_SCREAMING_SNAKE_CASE   ,**_SCREAMING_SNAKE_CASE       )				->     str:
          return self.tokenizer.decode(*_SCREAMING_SNAKE_CASE   ,**_SCREAMING_SNAKE_CASE       )






     @property
     def 							_lowercase      (					self       )				->     Optional[int]:
          _snake_case				= self.tokenizer.model_input_names
          _snake_case				= self.image_processor.model_input_names
          return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names       )       )








'''simple docstring'''





import re

from flax.core.frozen_dict import freeze
from flax.traverse_util import flatten_dict, unflatten_dict
from jax.experimental import PartitionSpec as P


# Sentinels
UpperCamelCase_		:     Optional[int]          =		object()

# For specifying empty leaf dict `{}`
UpperCamelCase_		:     Optional[int]          =		object()





def       __a      (  _UpperCamelCase:       Union[str, Any]   ,		_UpperCamelCase:       Optional[Any]       )		->					Optional[Any]:

     """simple docstring"""




     _snake_case				= tuple((re.compile(x + "$"       ) for x in qs)       )
     for i in range(len(_UpperCamelCase       ) - len(_UpperCamelCase       ) + 1       ):
          _snake_case				= [x.match(_UpperCamelCase       ) for x, y in zip(_UpperCamelCase   ,		ks[i:]       )]
          if matches and all(_UpperCamelCase       ):
               return True
     return False





def       __a      (  _UpperCamelCase:       Optional[Any]       )		->					Union[str, Any]:

     """simple docstring"""




     def replace(_UpperCamelCase:       Tuple   ,		_UpperCamelCase:       List[str]       ):
          for rule, replacement in rules:
               if _match(_UpperCamelCase   ,		_UpperCamelCase       ):
                    return replacement
          return val

     return replace





def       __a      (  )		->					Any:

     """simple docstring"""




     return [
         # embeddings
         (("transformer", "wpe", "embedding"), P("mp"   ,		_UpperCamelCase       )),
         (("transformer", "wte", "embedding"), P("mp"   ,		_UpperCamelCase       )),
         # atention
         (("attention", "(q_proj|k_proj|v_proj)", "kernel"), P(_UpperCamelCase   ,		"mp"       )),
         (("attention", "out_proj", "kernel"), P("mp"   ,		_UpperCamelCase       )),
         (("attention", "out_proj", "bias"), None),
         # mlp
         (("mlp", "c_fc", "kernel"), P(_UpperCamelCase   ,		"mp"       )),
         (("mlp", "c_fc", "bias"), P("mp"       )),
         (("mlp", "c_proj", "kernel"), P("mp"   ,		_UpperCamelCase       )),
         (("mlp", "c_proj", "bias"), None),
         # layer norms
         ((r"ln_\d+", "bias"), None),
         ((r"\d+", r"ln_\d+", "scale"), None),
         (("ln_f", "bias"), None),
         (("ln_f", "scale"), None),
     ]





def       __a      (  _UpperCamelCase:       Union[str, Any]       )		->					Any:

     """simple docstring"""




     _snake_case				= _get_partition_rules()
     _snake_case				= _replacement_rules(_UpperCamelCase       )
     _snake_case				= {k: _unmatched for k in flatten_dict(_UpperCamelCase       )}
     _snake_case				= {k: replace(_UpperCamelCase   ,		_UpperCamelCase       ) for k, v in initd.items()}
     assert _unmatched not in result.values(), "Incomplete partition spec."
     return freeze(unflatten_dict(_UpperCamelCase       )       )


