






from typing import Optional, Union

import torch
from torch import nn
from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss

from ...activations import ACTaFN
from ...modeling_outputs import BaseModelOutputWithPoolingAndNoAttention, ImageClassifierOutputWithNoAttention
from ...modeling_utils import PreTrainedModel
from ...utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward, logging
from .configuration_mobilenet_va import MobileNetVaConfig


A_		:		Union[str, Any]		     =			logging.get_logger(__name__)


# General docstring
A_		:		Dict		     =			"""MobileNetV1Config"""

# Base docstring
A_		:		int		     =			"""google/mobilenet_v1_1.0_224"""
A_		:		str		     =			[1, 1024, 7, 7]

# Image classification docstring
A_		:		List[Any]		     =			"""google/mobilenet_v1_1.0_224"""
A_		:		str		     =			"""tabby, tabby cat"""


A_		:		int		     =			[
    """google/mobilenet_v1_1.0_224""",
    """google/mobilenet_v1_0.75_192""",
    # See all MobileNetV1 models at https://huggingface.co/models?filter=mobilenet_v1
]

def   snake_case (UpperCAmelCase__     ,   UpperCAmelCase__     ,   UpperCAmelCase__=None  )	->    str:
  UpperCamelCase_: str   				=    {}

  if isinstance(_UpperCAmelCase     ,   _UpperCAmelCase  ):
    UpperCamelCase_: Dict   				=    model.mobilenet_va
  else:
    UpperCamelCase_: Any   				=    model

  UpperCamelCase_: Any   				=    'MobilenetV1/Conv2d_0/'
  UpperCamelCase_: List[Any]   				=    backbone.conv_stem.convolution.weight
  UpperCamelCase_: int   				=    backbone.conv_stem.normalization.bias
  UpperCamelCase_: List[Any]   				=    backbone.conv_stem.normalization.weight
  UpperCamelCase_: Tuple   				=    backbone.conv_stem.normalization.running_mean
  UpperCamelCase_: Tuple   				=    backbone.conv_stem.normalization.running_var

  for i in range(1_3  ):
    UpperCamelCase_: List[str]   				=    i + 1
    UpperCamelCase_: int   				=    i * 2

    UpperCamelCase_: Optional[int]   				=    backbone.layer[pt_index]
    UpperCamelCase_: List[Any]   				=    F'''MobilenetV1/Conv2d_{tf_index}_depthwise/'''
    UpperCamelCase_: Optional[int]   				=    pointer.convolution.weight
    UpperCamelCase_: Any   				=    pointer.normalization.bias
    UpperCamelCase_: Union[str, Any]   				=    pointer.normalization.weight
    UpperCamelCase_: Dict   				=    pointer.normalization.running_mean
    UpperCamelCase_: Optional[Any]   				=    pointer.normalization.running_var

    UpperCamelCase_: Union[str, Any]   				=    backbone.layer[pt_index + 1]
    UpperCamelCase_: Tuple   				=    F'''MobilenetV1/Conv2d_{tf_index}_pointwise/'''
    UpperCamelCase_: Any   				=    pointer.convolution.weight
    UpperCamelCase_: List[Any]   				=    pointer.normalization.bias
    UpperCamelCase_: int   				=    pointer.normalization.weight
    UpperCamelCase_: str   				=    pointer.normalization.running_mean
    UpperCamelCase_: Optional[int]   				=    pointer.normalization.running_var

  if isinstance(_UpperCAmelCase     ,   _UpperCAmelCase  ):
    UpperCamelCase_: List[str]   				=    'MobilenetV1/Logits/Conv2d_1c_1x1/'
    UpperCamelCase_: Any   				=    model.classifier.weight
    UpperCamelCase_: int   				=    model.classifier.bias

  return tf_to_pt_map

def   snake_case (UpperCAmelCase__     ,   UpperCAmelCase__     ,   UpperCAmelCase__  )	->    Union[str, Any]:
  try:
    import numpy as np
    import tensorflow as tf
  except ImportError:
    logger.error(
        'Loading a TensorFlow models in PyTorch, requires TensorFlow to be installed. Please see '
        'https://www.tensorflow.org/install/ for installation instructions.'  )
    raise

  # Load weights from TF model
  UpperCamelCase_: List[str]   				=    tf.train.list_variables(_UpperCAmelCase  )
  UpperCamelCase_: Tuple   				=    {}
  for name, shape in init_vars:
    logger.info(F'''Loading TF weight {name} with shape {shape}'''  )
    UpperCamelCase_: Optional[int]   				=    tf.train.load_variable(_UpperCAmelCase     ,   _UpperCAmelCase  )
    UpperCamelCase_: Optional[Any]   				=    array

  # Build TF to PyTorch weights loading map
  UpperCamelCase_: int   				=    _build_tf_to_pytorch_map(_UpperCAmelCase     ,   _UpperCAmelCase     ,   _UpperCAmelCase  )

  for name, pointer in tf_to_pt_map.items():
    logger.info(F'''Importing {name}'''  )
    if name not in tf_weights:
      logger.info(F'''{name} not in tf pre-trained weights, skipping'''  )
      continue

    UpperCamelCase_: Optional[Any]   				=    tf_weights[name]

    if "depthwise_weights" in name:
      logger.info('Transposing depthwise'  )
      UpperCamelCase_: Any   				=    np.transpose(_UpperCAmelCase     ,   (2, 3, 0, 1)  )
    elif "weights" in name:
      logger.info('Transposing'  )
      if len(pointer.shape  ) == 2:  # copying into linear layer
        UpperCamelCase_: Optional[int]   				=    array.squeeze().transpose()
      else:
        UpperCamelCase_: Tuple   				=    np.transpose(_UpperCAmelCase     ,   (3, 2, 0, 1)  )

    if pointer.shape != array.shape:
      raise ValueError(F'''Pointer shape {pointer.shape} and array shape {array.shape} mismatched'''  )

    logger.info(F'''Initialize PyTorch weight {name} {array.shape}'''  )
    UpperCamelCase_: List[str]   				=    torch.from_numpy(_UpperCAmelCase  )

    tf_weights.pop(_UpperCAmelCase     ,   _UpperCAmelCase  )
    tf_weights.pop(name + '/RMSProp'     ,   _UpperCAmelCase  )
    tf_weights.pop(name + '/RMSProp_1'     ,   _UpperCAmelCase  )
    tf_weights.pop(name + '/ExponentialMovingAverage'     ,   _UpperCAmelCase  )

  logger.info(F'''Weights not copied to PyTorch model: {', '.join(tf_weights.keys()  )}'''  )
  return model

def   snake_case (UpperCAmelCase__     ,   UpperCAmelCase__  )	->    torch.Tensor:
  UpperCamelCase_: Dict   				=    features.shape[-2:]
  UpperCamelCase_: str   				=    conv_layer.stride
  UpperCamelCase_: Any   				=    conv_layer.kernel_size

  if in_height % stride_height == 0:
    UpperCamelCase_: str   				=    max(kernel_height - stride_height     ,   0  )
  else:
    UpperCamelCase_: Dict   				=    max(kernel_height - (in_height % stride_height)     ,   0  )

  if in_width % stride_width == 0:
    UpperCamelCase_: int   				=    max(kernel_width - stride_width     ,   0  )
  else:
    UpperCamelCase_: Tuple   				=    max(kernel_width - (in_width % stride_width)     ,   0  )

  UpperCamelCase_: Any   				=    pad_along_width // 2
  UpperCamelCase_: Optional[Any]   				=    pad_along_width - pad_left
  UpperCamelCase_: Any   				=    pad_along_height // 2
  UpperCamelCase_: Optional[int]   				=    pad_along_height - pad_top

  UpperCamelCase_: str   				=    (pad_left, pad_right, pad_top, pad_bottom)
  return nn.functional.pad(_UpperCAmelCase     ,   _UpperCAmelCase     ,   'constant'     ,   0.0  )




class     _lowerCAmelCase(	nn.Module ):





       """simple docstring"""







       def __init__( self  ,      _lowerCamelCase  ,      _lowerCamelCase  ,      _lowerCamelCase  ,      _lowerCamelCase  ,      _lowerCamelCase = 1  ,      _lowerCamelCase = 1  ,      _lowerCamelCase = False  ,      _lowerCamelCase = True  ,      _lowerCamelCase = True  ,      ):
         super().__init__()
         UpperCamelCase_: Dict   				=    config

         if in_channels % groups != 0:
           raise ValueError(f'''Input channels ({in_channels}) are not divisible by {groups} groups.'''							)
         if out_channels % groups != 0:
           raise ValueError(f'''Output channels ({out_channels}) are not divisible by {groups} groups.'''							)

         UpperCamelCase_: List[str]   				=    0 if config.tf_padding else int((kernel_size - 1) / 2							)

         UpperCamelCase_: Any   				=    nn.Convad(
             in_channels=_lowerCamelCase  ,      out_channels=_lowerCamelCase  ,      kernel_size=_lowerCamelCase  ,      stride=_lowerCamelCase  ,      padding=_lowerCamelCase  ,      groups=_lowerCamelCase  ,      bias=_lowerCamelCase  ,      padding_mode='zeros'  ,      )

         if use_normalization:
           UpperCamelCase_: Optional[int]   				=    nn.BatchNormad(
               num_features=_lowerCamelCase  ,      eps=config.layer_norm_eps  ,      momentum=0.9_9_9_7  ,      affine=_lowerCamelCase  ,      track_running_stats=_lowerCamelCase  ,      )
         else:
           UpperCamelCase_: Tuple   				=    None

         if use_activation:
           if isinstance(_lowerCamelCase  ,      _lowerCamelCase							):
             UpperCamelCase_: Tuple   				=    ACTaFN[use_activation]
           elif isinstance(config.hidden_act  ,      _lowerCamelCase							):
             UpperCamelCase_: Any   				=    ACTaFN[config.hidden_act]
           else:
             UpperCamelCase_: Dict   				=    config.hidden_act
         else:
           UpperCamelCase_: Optional[int]   				=    None





       def       _a   ( self  ,      _lowerCamelCase							):
         if self.config.tf_padding:
           UpperCamelCase_: Dict   				=    apply_tf_padding(_lowerCamelCase  ,      self.convolution							)
         UpperCamelCase_: Union[str, Any]   				=    self.convolution(_lowerCamelCase							)
         if self.normalization is not None:
           UpperCamelCase_: Union[str, Any]   				=    self.normalization(_lowerCamelCase							)
         if self.activation is not None:
           UpperCamelCase_: List[str]   				=    self.activation(_lowerCamelCase							)
         return features







class     _lowerCAmelCase(	__UpperCamelCase ):





       """simple docstring"""







       a    :		List[Any]									=MobileNetVaConfig
       a    :		str									=load_tf_weights_in_mobilenet_va
       a    :		List[str]									='''mobilenet_v1'''
       a    :		Dict									='''pixel_values'''
       a    :		Dict									=False





       def       _a   ( self  ,      _lowerCamelCase							):
         if isinstance(_lowerCamelCase  ,      (nn.Linear, nn.Convad)							):
           module.weight.data.normal_(mean=0.0  ,      std=self.config.initializer_range							)
           if module.bias is not None:
             module.bias.data.zero_()
         elif isinstance(_lowerCamelCase  ,      nn.BatchNormad							):
           module.bias.data.zero_()
           module.weight.data.fill_(1.0							)







A_		:		str		     =			R"""
    This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass. Use it
    as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and
    behavior.

    Parameters:
        config ([`MobileNetV1Config`]): Model configuration class with all the parameters of the model.
            Initializing with a config file does not load the weights associated with the model, only the
            configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights.
"""

A_		:		Union[str, Any]		     =			R"""
    Args:
        pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):
            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See
            [`MobileNetV1ImageProcessor.__call__`] for details.
        output_hidden_states (`bool`, *optional*):
            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
            more detail.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
"""




@add_start_docstrings(
    '''The bare MobileNetV1 model outputting raw hidden-states without any specific head on top.'''							,     __UpperCamelCase							,     )
class     _lowerCAmelCase(	__UpperCamelCase ):





       """simple docstring"""







       def __init__( self  ,      _lowerCamelCase  ,      _lowerCamelCase = True							):
         super().__init__(_lowerCamelCase							)
         UpperCamelCase_: Optional[Any]   				=    config

         UpperCamelCase_: Dict   				=    3_2
         UpperCamelCase_: List[str]   				=    max(int(depth * config.depth_multiplier							)  ,      config.min_depth							)

         UpperCamelCase_: str   				=    MobileNetVaConvLayer(
             _lowerCamelCase  ,      in_channels=config.num_channels  ,      out_channels=_lowerCamelCase  ,      kernel_size=3  ,      stride=2  ,      )

         UpperCamelCase_: List[str]   				=    [1, 2, 1, 2, 1, 2, 1, 1, 1, 1, 1, 2, 1]

         UpperCamelCase_: Any   				=    nn.ModuleList()
         for i in range(1_3							):
           UpperCamelCase_: Tuple   				=    out_channels

           if strides[i] == 2 or i == 0:
             depth *= 2
             UpperCamelCase_: List[Any]   				=    max(int(depth * config.depth_multiplier							)  ,      config.min_depth							)

           self.layer.append(
               MobileNetVaConvLayer(
                   _lowerCamelCase  ,      in_channels=_lowerCamelCase  ,      out_channels=_lowerCamelCase  ,      kernel_size=3  ,      stride=strides[i]  ,      groups=_lowerCamelCase  ,      )							)

           self.layer.append(
               MobileNetVaConvLayer(
                   _lowerCamelCase  ,      in_channels=_lowerCamelCase  ,      out_channels=_lowerCamelCase  ,      kernel_size=1  ,      )							)

         UpperCamelCase_: Optional[int]   				=    nn.AdaptiveAvgPoolad((1, 1)							) if add_pooling_layer else None

         # Initialize weights and apply final processing
         self.post_init()





       def       _a   ( self  ,      _lowerCamelCase							):
         raise NotImplementedError





       @add_start_docstrings_to_model_forward(_lowerCamelCase							)
       @add_code_sample_docstrings(
           checkpoint=_CHECKPOINT_FOR_DOC  ,      output_type=_lowerCamelCase  ,      config_class=_CONFIG_FOR_DOC  ,      modality='vision'  ,      expected_output=_EXPECTED_OUTPUT_SHAPE  ,      )
       def       _a   ( self  ,      _lowerCamelCase = None  ,      _lowerCamelCase = None  ,      _lowerCamelCase = None  ,      ):
         UpperCamelCase_: Optional[Any]   				=    (
             output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
         )
         UpperCamelCase_: int   				=    return_dict if return_dict is not None else self.config.use_return_dict

         if pixel_values is None:
           raise ValueError('You have to specify pixel_values'							)

         UpperCamelCase_: Tuple   				=    self.conv_stem(_lowerCamelCase							)

         UpperCamelCase_: Optional[Any]   				=    () if output_hidden_states else None

         for i, layer_module in enumerate(self.layer							):
           UpperCamelCase_: Any   				=    layer_module(_lowerCamelCase							)

           if output_hidden_states:
             UpperCamelCase_: Union[str, Any]   				=    all_hidden_states + (hidden_states,)

         UpperCamelCase_: List[Any]   				=    hidden_states

         if self.pooler is not None:
           UpperCamelCase_: Tuple   				=    torch.flatten(self.pooler(_lowerCamelCase							)  ,      start_dim=1							)
         else:
           UpperCamelCase_: Any   				=    None

         if not return_dict:
           return tuple(v for v in [last_hidden_state, pooled_output, all_hidden_states] if v is not None							)

         return BaseModelOutputWithPoolingAndNoAttention(
             last_hidden_state=_lowerCamelCase  ,      pooler_output=_lowerCamelCase  ,      hidden_states=_lowerCamelCase  ,      )







@add_start_docstrings(
    '''
    MobileNetV1 model with an image classification head on top (a linear layer on top of the pooled features), e.g. for
    ImageNet.
    '''							,     __UpperCamelCase							,     )
class     _lowerCAmelCase(	__UpperCamelCase ):





       """simple docstring"""







       def __init__( self  ,      _lowerCamelCase							):
         super().__init__(_lowerCamelCase							)

         UpperCamelCase_: List[str]   				=    config.num_labels
         UpperCamelCase_: Dict   				=    MobileNetVaModel(_lowerCamelCase							)

         UpperCamelCase_: Optional[int]   				=    self.mobilenet_va.layer[-1].convolution.out_channels

         # Classifier head
         UpperCamelCase_: str   				=    nn.Dropout(config.classifier_dropout_prob  ,      inplace=_lowerCamelCase							)
         UpperCamelCase_: str   				=    nn.Linear(_lowerCamelCase  ,      config.num_labels							) if config.num_labels > 0 else nn.Identity()

         # Initialize weights and apply final processing
         self.post_init()





       @add_start_docstrings_to_model_forward(_lowerCamelCase							)
       @add_code_sample_docstrings(
           checkpoint=_IMAGE_CLASS_CHECKPOINT  ,      output_type=_lowerCamelCase  ,      config_class=_CONFIG_FOR_DOC  ,      expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT  ,      )
       def       _a   ( self  ,      _lowerCamelCase = None  ,      _lowerCamelCase = None  ,      _lowerCamelCase = None  ,      _lowerCamelCase = None  ,      ):
         UpperCamelCase_: List[Any]   				=    return_dict if return_dict is not None else self.config.use_return_dict

         UpperCamelCase_: List[str]   				=    self.mobilenet_va(_lowerCamelCase  ,      output_hidden_states=_lowerCamelCase  ,      return_dict=_lowerCamelCase							)

         UpperCamelCase_: Optional[Any]   				=    outputs.pooler_output if return_dict else outputs[1]

         UpperCamelCase_: List[Any]   				=    self.classifier(self.dropout(_lowerCamelCase							)							)

         UpperCamelCase_: Tuple   				=    None
         if labels is not None:
           if self.config.problem_type is None:
             if self.num_labels == 1:
               UpperCamelCase_: Dict   				=    'regression'
             elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
               UpperCamelCase_: Tuple   				=    'single_label_classification'
             else:
               UpperCamelCase_: Dict   				=    'multi_label_classification'

           if self.config.problem_type == "regression":
             UpperCamelCase_: Union[str, Any]   				=    MSELoss()
             if self.num_labels == 1:
               UpperCamelCase_: int   				=    loss_fct(logits.squeeze()  ,      labels.squeeze()							)
             else:
               UpperCamelCase_: Dict   				=    loss_fct(_lowerCamelCase  ,      _lowerCamelCase							)
           elif self.config.problem_type == "single_label_classification":
             UpperCamelCase_: Optional[int]   				=    CrossEntropyLoss()
             UpperCamelCase_: List[str]   				=    loss_fct(logits.view(-1  ,      self.num_labels							)  ,      labels.view(-1							)							)
           elif self.config.problem_type == "multi_label_classification":
             UpperCamelCase_: Union[str, Any]   				=    BCEWithLogitsLoss()
             UpperCamelCase_: int   				=    loss_fct(_lowerCamelCase  ,      _lowerCamelCase							)

         if not return_dict:
           UpperCamelCase_: Any   				=    (logits,) + outputs[2:]
           return ((loss,) + output) if loss is not None else output

         return ImageClassifierOutputWithNoAttention(
             loss=_lowerCamelCase  ,      logits=_lowerCamelCase  ,      hidden_states=outputs.hidden_states  ,      )







import json
import os
import unittest

from transformers import CLIPTokenizer, CLIPTokenizerFast
from transformers.models.clip.tokenization_clip import VOCAB_FILES_NAMES
from transformers.testing_utils import require_ftfy, require_tokenizers

from ...test_tokenization_common import TokenizerTesterMixin




@require_tokenizers
class     _lowerCAmelCase(	UpperCAmelCase_							,     unittest.TestCase ):





       """simple docstring"""







       a    :		Optional[Any]									=CLIPTokenizer
       a    :		List[Any]									=CLIPTokenizerFast
       a    :		str									=True
       a    :		List[Any]									={}
       a    :		str									=False





       def       _a   ( self							):
         super().setUp()

         # fmt: off
         UpperCamelCase_: str   				=    ['l', 'o', 'w', 'e', 'r', 's', 't', 'i', 'd', 'n', 'lo', 'l</w>', 'w</w>', 'r</w>', 't</w>', 'low</w>', 'er</w>', 'lowest</w>', 'newer</w>', 'wider', '<unk>', '<|startoftext|>', '<|endoftext|>']
         # fmt: on
         UpperCamelCase_: Any   				=    dict(zip(_lowerCamelCase  ,      range(len(_lowerCamelCase							)							)							)							)
         UpperCamelCase_: Optional[int]   				=    ['#version: 0.2', 'l o', 'lo w</w>', 'e r</w>']
         UpperCamelCase_: Any   				=    {'unk_token': '<unk>'}

         UpperCamelCase_: List[Any]   				=    os.path.join(self.tmpdirname  ,      VOCAB_FILES_NAMES['vocab_file']							)
         UpperCamelCase_: Optional[int]   				=    os.path.join(self.tmpdirname  ,      VOCAB_FILES_NAMES['merges_file']							)
         with open(self.vocab_file  ,      'w'  ,      encoding='utf-8'							) as fp:
           fp.write(json.dumps(_lowerCamelCase							) + '\n'							)
         with open(self.merges_file  ,      'w'  ,      encoding='utf-8'							) as fp:
           fp.write('\n'.join(_lowerCamelCase							)							)





       def       _a   ( self  ,      **_lowerCamelCase							):
         kwargs.update(self.special_tokens_map							)
         return CLIPTokenizer.from_pretrained(self.tmpdirname  ,      **_lowerCamelCase							)





       def       _a   ( self  ,      **_lowerCamelCase							):
         kwargs.update(self.special_tokens_map							)
         return CLIPTokenizerFast.from_pretrained(self.tmpdirname  ,      **_lowerCamelCase							)





       def       _a   ( self  ,      _lowerCamelCase							):
         UpperCamelCase_: Union[str, Any]   				=    'lower newer'
         UpperCamelCase_: Tuple   				=    'lower newer'
         return input_text, output_text





       def       _a   ( self							):
         UpperCamelCase_: Dict   				=    CLIPTokenizer(self.vocab_file  ,      self.merges_file  ,      **self.special_tokens_map							)
         UpperCamelCase_: Optional[int]   				=    'lower newer'
         UpperCamelCase_: Any   				=    ['lo', 'w', 'er</w>', 'n', 'e', 'w', 'er</w>']
         UpperCamelCase_: Union[str, Any]   				=    tokenizer.tokenize(_lowerCamelCase							)
         self.assertListEqual(_lowerCamelCase  ,      _lowerCamelCase							)

         UpperCamelCase_: str   				=    tokens + [tokenizer.unk_token]
         UpperCamelCase_: Optional[Any]   				=    [1_0, 2, 1_6, 9, 3, 2, 1_6, 2_0]
         self.assertListEqual(tokenizer.convert_tokens_to_ids(_lowerCamelCase							)  ,      _lowerCamelCase							)





       @require_ftfy
       def       _a   ( self							):
         for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
           with self.subTest(f'''{tokenizer.__class__.__name__} ({pretrained_name})'''							):
             UpperCamelCase_: Optional[int]   				=    self.tokenizer_class.from_pretrained(_lowerCamelCase  ,      **_lowerCamelCase							)
             UpperCamelCase_: List[str]   				=    self.rust_tokenizer_class.from_pretrained(_lowerCamelCase  ,      **_lowerCamelCase							)

             UpperCamelCase_: Optional[int]   				=    'A\n\'ll 11p223RF☆ho!!to?\'d\'d\'\'d of a cat to-$\'\'d.'
             UpperCamelCase_: Tuple   				=    tokenizer_s.tokenize(_lowerCamelCase							)
             UpperCamelCase_: Any   				=    tokenizer_r.tokenize(_lowerCamelCase							)

             self.assertListEqual(_lowerCamelCase  ,      _lowerCamelCase							)

             # Test that the tokenization is identical on an example containing a character (Latin Small Letter A
             # with Tilde) encoded in 2 different ways
             UpperCamelCase_: List[str]   				=    'xa\u0303y' + ' ' + 'x\xe3y'
             UpperCamelCase_: List[Any]   				=    tokenizer_s.tokenize(_lowerCamelCase							)
             UpperCamelCase_: int   				=    tokenizer_r.tokenize(_lowerCamelCase							)

             self.assertListEqual(_lowerCamelCase  ,      _lowerCamelCase							)

             # Test that the tokenization is identical on unicode of space type
             UpperCamelCase_: Dict   				=    [
                 '\u0009',  # (horizontal tab, '\t')
                 '\u000B',  # (vertical tab)
                 '\u000C',  # (form feed)
                 '\u0020',  # (space, ' ')
                 '\u200E',  # (left-to-right mark):w
                 '\u200F',  # (right-to-left mark)
             ]
             for unicode_seq in spaces_unicodes:
               UpperCamelCase_: int   				=    tokenizer_s.tokenize(_lowerCamelCase							)
               UpperCamelCase_: Dict   				=    tokenizer_r.tokenize(_lowerCamelCase							)

               self.assertListEqual(_lowerCamelCase  ,      _lowerCamelCase							)

             # Test that the tokenization is identical on unicode of line break type
             UpperCamelCase_: List[str]   				=    [
                 '\u000A',  # (line feed, '\n')
                 '\r\n',  # (carriage return and line feed, '\r\n')
                 '\u000D',  # (carriage return, '\r')
                 '\r',  # (carriage return, '\r')
                 '\u000D',  # (carriage return, '\r')
                 '\u2028',  # (line separator)
                 '\u2029',  # (paragraph separator)
                 # "\u0085", # (next line)
             ]

             # The tokenization is not identical for the character "\u0085" (next line). The slow version using ftfy transforms
             # it into the Horizontal Ellipsis character "…" ("\u2026") while the fast version transforms it into a
             # space (and thus into an empty list).

             for unicode_seq in line_break_unicodes:
               UpperCamelCase_: Optional[Any]   				=    tokenizer_s.tokenize(_lowerCamelCase							)
               UpperCamelCase_: str   				=    tokenizer_r.tokenize(_lowerCamelCase							)

               self.assertListEqual(_lowerCamelCase  ,      _lowerCamelCase							)





       def       _a   ( self							):
         # Test which aims to verify that the offsets are well adapted to the argument `add_prefix_space`
         for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
           with self.subTest(f'''{tokenizer.__class__.__name__} ({pretrained_name})'''							):
             UpperCamelCase_: str   				=    'hello'  # `hello` is a token in the vocabulary of `pretrained_name`
             UpperCamelCase_: str   				=    f'''{text_of_1_token} {text_of_1_token}'''

             UpperCamelCase_: Optional[Any]   				=    self.rust_tokenizer_class.from_pretrained(
                 _lowerCamelCase  ,      use_fast=_lowerCamelCase  ,      )
             UpperCamelCase_: int   				=    tokenizer_r(_lowerCamelCase  ,      return_offsets_mapping=_lowerCamelCase  ,      add_special_tokens=_lowerCamelCase							)
             self.assertEqual(encoding.offset_mapping[0]  ,      (0, len(_lowerCamelCase							))							)
             self.assertEqual(
                 encoding.offset_mapping[1]  ,      (len(_lowerCamelCase							) + 1, len(_lowerCamelCase							) + 1 + len(_lowerCamelCase							))  ,      )

             UpperCamelCase_: List[str]   				=    f''' {text}'''

             UpperCamelCase_: str   				=    self.rust_tokenizer_class.from_pretrained(
                 _lowerCamelCase  ,      use_fast=_lowerCamelCase  ,      )
             UpperCamelCase_: Dict   				=    tokenizer_r(_lowerCamelCase  ,      return_offsets_mapping=_lowerCamelCase  ,      add_special_tokens=_lowerCamelCase							)
             self.assertEqual(encoding.offset_mapping[0]  ,      (1, 1 + len(_lowerCamelCase							))							)
             self.assertEqual(
                 encoding.offset_mapping[1]  ,      (1 + len(_lowerCamelCase							) + 1, 1 + len(_lowerCamelCase							) + 1 + len(_lowerCamelCase							))  ,      )





       def       _a   ( self							):
         # Test related to the breaking change introduced in transformers v4.17.0
         # We need to check that an error in raised when the user try to load a previous version of the tokenizer.
         with self.assertRaises(_lowerCamelCase							) as context:
           self.rust_tokenizer_class.from_pretrained('robot-test/old-clip-tokenizer'							)

         self.assertTrue(
             context.exception.args[0].startswith(
                 'The `backend_tokenizer` provided does not match the expected format.'							)							)





       @require_ftfy
       def       _a   ( self							):
         super().test_tokenization_python_rust_equals()





       def       _a   ( self							):
         # CLIP always lower cases letters
         pass