




import gc
import unittest

import numpy as np
import torch
import torch.nn.functional as F
from transformers import (
    ClapTextConfig,
    ClapTextModelWithProjection,
    RobertaTokenizer,
    SpeechTaHifiGan,
    SpeechTaHifiGanConfig,
)

from diffusers import (
    AudioLDMPipeline,
    AutoencoderKL,
    DDIMScheduler,
    LMSDiscreteScheduler,
    PNDMScheduler,
    UNetaDConditionModel,
)
from diffusers.utils import is_xformers_available, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism

from ..pipeline_params import TEXT_TO_AUDIO_BATCH_PARAMS, TEXT_TO_AUDIO_PARAMS
from ..test_pipelines_common import PipelineTesterMixin


enable_full_determinism()







class 		lowercase							(     UpperCAmelCase_,unittest.TestCase	):
     _a											=		AudioLDMPipeline
     _a											=		TEXT_TO_AUDIO_PARAMS
     _a											=		TEXT_TO_AUDIO_BATCH_PARAMS
     _a											=		frozenset(
         [
             "num_inference_steps",
             "num_waveforms_per_prompt",
             "generator",
             "latents",
             "output_type",
             "return_dict",
             "callback",
             "callback_steps",
         ]	)

     def       a__			(						self       )		->							Any:
           torch.manual_seed(0       )
           _A							:  Optional[int]    =		UNetaDConditionModel(
               block_out_channels=(32, 64)	,  layers_per_block=2	,  sample_size=32	,  in_channels=4	,  out_channels=4	,  down_block_types=("""DownBlock2D""", """CrossAttnDownBlock2D""")	,  up_block_types=("""CrossAttnUpBlock2D""", """UpBlock2D""")	,  cross_attention_dim=(32, 64)	,  class_embed_type="""simple_projection"""	,  projection_class_embeddings_input_dim=32	,  class_embeddings_concat=_lowercase	,  )
           _A							:  int    =		DDIMScheduler(
               beta_start=0.00085	,  beta_end=0.012	,  beta_schedule="""scaled_linear"""	,  clip_sample=_lowercase	,  set_alpha_to_one=_lowercase	,  )
           torch.manual_seed(0       )
           _A							:  Optional[Any]    =		AutoencoderKL(
               block_out_channels=[32, 64]	,  in_channels=1	,  out_channels=1	,  down_block_types=["""DownEncoderBlock2D""", """DownEncoderBlock2D"""]	,  up_block_types=["""UpDecoderBlock2D""", """UpDecoderBlock2D"""]	,  latent_channels=4	,  )
           torch.manual_seed(0       )
           _A							:  Tuple    =		ClapTextConfig(
               bos_token_id=0	,  eos_token_id=2	,  hidden_size=32	,  intermediate_size=37	,  layer_norm_eps=1e-05	,  num_attention_heads=4	,  num_hidden_layers=5	,  pad_token_id=1	,  vocab_size=1000	,  projection_dim=32	,  )
           _A							:  Dict    =		ClapTextModelWithProjection(_lowercase       )
           _A							:  Tuple    =		RobertaTokenizer.from_pretrained("""hf-internal-testing/tiny-random-roberta"""	,  model_max_length=77       )

           _A							:  Union[str, Any]    =		SpeechTaHifiGanConfig(
               model_in_dim=8	,  sampling_rate=1_6000	,  upsample_initial_channel=16	,  upsample_rates=[2, 2]	,  upsample_kernel_sizes=[4, 4]	,  resblock_kernel_sizes=[3, 7]	,  resblock_dilation_sizes=[[1, 3, 5], [1, 3, 5]]	,  normalize_before=_lowercase	,  )

           _A							:  List[str]    =		SpeechTaHifiGan(_lowercase       )

           _A							:  int    =		{
               """unet""": unet,
               """scheduler""": scheduler,
               """vae""": vae,
               """text_encoder""": text_encoder,
               """tokenizer""": tokenizer,
               """vocoder""": vocoder,
           }
           return components

     def       a__			(						self	,  _a	,  _a=0       )		->							str:
           if str(_lowercase       ).startswith("""mps"""       ):
                 _A							:  int    =		torch.manual_seed(_lowercase       )
           else:
                 _A							:  Union[str, Any]    =		torch.Generator(device=_lowercase       ).manual_seed(_lowercase       )
           _A							:  Any    =		{
               """prompt""": """A hammer hitting a wooden surface""",
               """generator""": generator,
               """num_inference_steps""": 2,
               """guidance_scale""": 6.0,
           }
           return inputs

     def       a__			(						self       )		->							Tuple:
           _A							:  Tuple    =		"""cpu"""  # ensure determinism for the device-dependent torch.Generator

           _A							:  Tuple    =		self.get_dummy_components()
           _A							:  int    =		AudioLDMPipeline(**_lowercase       )
           _A							:  Optional[int]    =		audioldm_pipe.to(_lowercase       )
           audioldm_pipe.set_progress_bar_config(disable=_lowercase       )

           _A							:  Any    =		self.get_dummy_inputs(_lowercase       )
           _A							:  Any    =		audioldm_pipe(**_lowercase       )
           _A							:  List[str]    =		output.audios[0]

           assert audio.ndim == 1
           assert len(_lowercase       ) == 256

           _A							:  List[str]    =		audio[:10]
           _A							:  List[Any]    =		np.array(
               [-0.0050, 0.0050, -0.0060, 0.0033, -0.0026, 0.0033, -0.0027, 0.0033, -0.0028, 0.0033]       )

           assert np.abs(audio_slice - expected_slice       ).max() < 1e-2

     def       a__			(						self       )		->							Any:
           _A							:  Tuple    =		self.get_dummy_components()
           _A							:  Tuple    =		AudioLDMPipeline(**_lowercase       )
           _A							:  List[Any]    =		audioldm_pipe.to(_lowercase       )
           _A							:  Optional[Any]    =		audioldm_pipe.to(_lowercase       )
           audioldm_pipe.set_progress_bar_config(disable=_lowercase       )

           _A							:  Optional[int]    =		self.get_dummy_inputs(_lowercase       )
           _A							:  str    =		3 * [inputs["""prompt"""]]

           # forward
           _A							:  List[str]    =		audioldm_pipe(**_lowercase       )
           _A							:  Union[str, Any]    =		output.audios[0]

           _A							:  Any    =		self.get_dummy_inputs(_lowercase       )
           _A							:  Optional[int]    =		3 * [inputs.pop("""prompt"""       )]

           _A							:  int    =		audioldm_pipe.tokenizer(
               _lowercase	,  padding="""max_length"""	,  max_length=audioldm_pipe.tokenizer.model_max_length	,  truncation=_lowercase	,  return_tensors="""pt"""	,  )
           _A							:  int    =		text_inputs["""input_ids"""].to(_lowercase       )

           _A							:  str    =		audioldm_pipe.text_encoder(
               _lowercase	,  )
           _A							:  Dict    =		prompt_embeds.text_embeds
           # additional L_2 normalization over each hidden-state
           _A							:  List[str]    =		F.normalize(_lowercase	,  dim=-1       )

           _A							:  str    =		prompt_embeds

           # forward
           _A							:  Tuple    =		audioldm_pipe(**_lowercase       )
           _A							:  str    =		output.audios[0]

           assert np.abs(audio_a - audio_a       ).max() < 1e-2

     def       a__			(						self       )		->							List[Any]:
           _A							:  Any    =		self.get_dummy_components()
           _A							:  int    =		AudioLDMPipeline(**_lowercase       )
           _A							:  List[str]    =		audioldm_pipe.to(_lowercase       )
           _A							:  Optional[int]    =		audioldm_pipe.to(_lowercase       )
           audioldm_pipe.set_progress_bar_config(disable=_lowercase       )

           _A							:  int    =		self.get_dummy_inputs(_lowercase       )
           _A							:  List[Any]    =		3 * ["""this is a negative prompt"""]
           _A							:  Union[str, Any]    =		negative_prompt
           _A							:  List[str]    =		3 * [inputs["""prompt"""]]

           # forward
           _A							:  Dict    =		audioldm_pipe(**_lowercase       )
           _A							:  str    =		output.audios[0]

           _A							:  List[str]    =		self.get_dummy_inputs(_lowercase       )
           _A							:  int    =		3 * [inputs.pop("""prompt"""       )]

           _A							:  List[str]    =		[]
           for p in [prompt, negative_prompt]:
                 _A							:  List[Any]    =		audioldm_pipe.tokenizer(
                     _lowercase	,  padding="""max_length"""	,  max_length=audioldm_pipe.tokenizer.model_max_length	,  truncation=_lowercase	,  return_tensors="""pt"""	,  )
                 _A							:  List[str]    =		text_inputs["""input_ids"""].to(_lowercase       )

                 _A							:  Union[str, Any]    =		audioldm_pipe.text_encoder(
                     _lowercase	,  )
                 _A							:  Optional[Any]    =		text_embeds.text_embeds
                 # additional L_2 normalization over each hidden-state
                 _A							:  Any    =		F.normalize(_lowercase	,  dim=-1       )

                 embeds.append(_lowercase       )

           _A    ,     _A							:  Union[str, Any]    =		embeds

           # forward
           _A							:  List[str]    =		audioldm_pipe(**_lowercase       )
           _A							:  Optional[Any]    =		output.audios[0]

           assert np.abs(audio_a - audio_a       ).max() < 1e-2

     def       a__			(						self       )		->							Dict:
           _A							:  Dict    =		"""cpu"""  # ensure determinism for the device-dependent torch.Generator
           _A							:  List[Any]    =		self.get_dummy_components()
           _A							:  Dict    =		PNDMScheduler(skip_prk_steps=_lowercase       )
           _A							:  Optional[int]    =		AudioLDMPipeline(**_lowercase       )
           _A							:  str    =		audioldm_pipe.to(_lowercase       )
           audioldm_pipe.set_progress_bar_config(disable=_lowercase       )

           _A							:  List[Any]    =		self.get_dummy_inputs(_lowercase       )
           _A							:  Union[str, Any]    =		"""egg cracking"""
           _A							:  List[str]    =		audioldm_pipe(**_lowercase	,  negative_prompt=_lowercase       )
           _A							:  Tuple    =		output.audios[0]

           assert audio.ndim == 1
           assert len(_lowercase       ) == 256

           _A							:  List[str]    =		audio[:10]
           _A							:  Any    =		np.array(
               [-0.0051, 0.0050, -0.0060, 0.0034, -0.0026, 0.0033, -0.0027, 0.0033, -0.0028, 0.0032]       )

           assert np.abs(audio_slice - expected_slice       ).max() < 1e-2

     def       a__			(						self       )		->							Any:
           _A							:  Any    =		"""cpu"""  # ensure determinism for the device-dependent torch.Generator
           _A							:  int    =		self.get_dummy_components()
           _A							:  List[Any]    =		PNDMScheduler(skip_prk_steps=_lowercase       )
           _A							:  Dict    =		AudioLDMPipeline(**_lowercase       )
           _A							:  Dict    =		audioldm_pipe.to(_lowercase       )
           audioldm_pipe.set_progress_bar_config(disable=_lowercase       )

           _A							:  List[str]    =		"""A hammer hitting a wooden surface"""

           # test num_waveforms_per_prompt=1 (default)
           _A							:  Tuple    =		audioldm_pipe(_lowercase	,  num_inference_steps=2       ).audios

           assert audios.shape == (1, 256)

           # test num_waveforms_per_prompt=1 (default) for batch of prompts
           _A							:  Dict    =		2
           _A							:  Dict    =		audioldm_pipe([prompt] * batch_size	,  num_inference_steps=2       ).audios

           assert audios.shape == (batch_size, 256)

           # test num_waveforms_per_prompt for single prompt
           _A							:  int    =		2
           _A							:  List[str]    =		audioldm_pipe(_lowercase	,  num_inference_steps=2	,  num_waveforms_per_prompt=_lowercase       ).audios

           assert audios.shape == (num_waveforms_per_prompt, 256)

           # test num_waveforms_per_prompt for batch of prompts
           _A							:  Any    =		2
           _A							:  List[Any]    =		audioldm_pipe(
               [prompt] * batch_size	,  num_inference_steps=2	,  num_waveforms_per_prompt=_lowercase       ).audios

           assert audios.shape == (batch_size * num_waveforms_per_prompt, 256)

     def       a__			(						self       )		->							str:
           _A							:  List[Any]    =		"""cpu"""  # ensure determinism for the device-dependent torch.Generator
           _A							:  Any    =		self.get_dummy_components()
           _A							:  str    =		AudioLDMPipeline(**_lowercase       )
           _A							:  Dict    =		audioldm_pipe.to(_lowercase       )
           audioldm_pipe.set_progress_bar_config(disable=_lowercase       )
           _A							:  Union[str, Any]    =		audioldm_pipe.vocoder.config.sampling_rate

           _A							:  Optional[int]    =		self.get_dummy_inputs(_lowercase       )
           _A							:  Union[str, Any]    =		audioldm_pipe(audio_length_in_s=0.016	,  **_lowercase       )
           _A							:  List[str]    =		output.audios[0]

           assert audio.ndim == 1
           assert len(_lowercase       ) / vocoder_sampling_rate == 0.016

           _A							:  Optional[Any]    =		audioldm_pipe(audio_length_in_s=0.032	,  **_lowercase       )
           _A							:  str    =		output.audios[0]

           assert audio.ndim == 1
           assert len(_lowercase       ) / vocoder_sampling_rate == 0.032

     def       a__			(						self       )		->							str:
           _A							:  Tuple    =		self.get_dummy_components()
           _A							:  Union[str, Any]    =		AudioLDMPipeline(**_lowercase       )
           _A							:  Any    =		audioldm_pipe.to(_lowercase       )
           audioldm_pipe.set_progress_bar_config(disable=_lowercase       )

           _A							:  Optional[Any]    =		["""hey"""]

           _A							:  Optional[Any]    =		audioldm_pipe(_lowercase	,  num_inference_steps=1       )
           _A							:  Union[str, Any]    =		output.audios.shape
           assert audio_shape == (1, 256)

           _A							:  List[str]    =		audioldm_pipe.vocoder.config
           config.model_in_dim *= 2
           _A							:  int    =		SpeechTaHifiGan(_lowercase       ).to(_lowercase       )
           _A							:  Any    =		audioldm_pipe(_lowercase	,  num_inference_steps=1       )
           _A							:  List[str]    =		output.audios.shape
           # waveform shape is unchanged, we just have 2x the number of mel channels in the spectrogram
           assert audio_shape == (1, 256)

     def       a__			(						self       )		->							int:
           self._test_attention_slicing_forward_pass(test_mean_pixel_difference=_lowercase       )

     def       a__			(						self       )		->							int:
           self._test_inference_batch_single_identical(test_mean_pixel_difference=_lowercase       )



     @unittest.skipIf(
         torch_device != """cuda""" or not is_xformers_available()	,  reason="""XFormers attention is only available with CUDA and `xformers` installed"""	,  )
     def       a__			(						self       )		->							Any:
           self._test_xformers_attention_forwardGenerator_pass(test_mean_pixel_difference=_lowercase       )







@slow
class 		lowercase							(     unittest.TestCase	):

     def       a__			(						self       )		->							List[str]:
           super().tearDown()
           gc.collect()
           torch.cuda.empty_cache()

     def       a__			(						self	,  _a	,  _a="cpu"	,  _a=torch.floataa	,  _a=0       )		->							Optional[Any]:
           _A							:  int    =		torch.Generator(device=_lowercase       ).manual_seed(_lowercase       )
           _A							:  Optional[Any]    =		np.random.RandomState(_lowercase       ).standard_normal((1, 8, 128, 16)       )
           _A							:  Tuple    =		torch.from_numpy(_lowercase       ).to(device=_lowercase	,  dtype=_lowercase       )
           _A							:  int    =		{
               """prompt""": """A hammer hitting a wooden surface""",
               """latents""": latents,
               """generator""": generator,
               """num_inference_steps""": 3,
               """guidance_scale""": 2.5,
           }
           return inputs

     def       a__			(						self       )		->							int:
           _A							:  List[Any]    =		AudioLDMPipeline.from_pretrained("""cvssp/audioldm"""       )
           _A							:  List[str]    =		audioldm_pipe.to(_lowercase       )
           audioldm_pipe.set_progress_bar_config(disable=_lowercase       )

           _A							:  Union[str, Any]    =		self.get_inputs(_lowercase       )
           _A							:  Tuple    =		25
           _A							:  List[str]    =		audioldm_pipe(**_lowercase       ).audios[0]

           assert audio.ndim == 1
           assert len(_lowercase       ) == 8_1920

           _A							:  Any    =		audio[7_7230:7_7240]
           _A							:  Dict    =		np.array(
               [-0.4884, -0.4607, 0.0023, 0.5007, 0.5896, 0.5151, 0.3813, -0.0208, -0.3687, -0.4315]       )
           _A							:  str    =		np.abs(expected_slice - audio_slice       ).max()
           assert max_diff < 1e-2



     def       a__			(						self       )		->							int:
           _A							:  Dict    =		AudioLDMPipeline.from_pretrained("""cvssp/audioldm"""       )
           _A							:  Dict    =		LMSDiscreteScheduler.from_config(audioldm_pipe.scheduler.config       )
           _A							:  List[str]    =		audioldm_pipe.to(_lowercase       )
           audioldm_pipe.set_progress_bar_config(disable=_lowercase       )

           _A							:  List[Any]    =		self.get_inputs(_lowercase       )
           _A							:  Dict    =		audioldm_pipe(**_lowercase       ).audios[0]

           assert audio.ndim == 1
           assert len(_lowercase       ) == 8_1920

           _A							:  List[str]    =		audio[2_7780:2_7790]
           _A							:  List[Any]    =		np.array([-0.2131, -0.0873, -0.0124, -0.0189, 0.0569, 0.1373, 0.1883, 0.2886, 0.3297, 0.2212]       )
           _A							:  Optional[Any]    =		np.abs(expected_slice - audio_slice       ).max()
           assert max_diff < 3e-2







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 		lowercase							(     UpperCamelCase__,unittest.TestCase	):
     _a											=		CLIPTokenizer
     _a											=		CLIPTokenizerFast
     _a											=		True
     _a											=		{}
     _a											=		False

     def       a__			(						self       )		->							Optional[Any]:
           super().setUp()

           # fmt: off
           _A							:  int    =		["""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
           _A							:  str    =		dict(zip(_a	,  range(len(_a       )       )       )       )
           _A							:  Optional[int]    =		["""#version: 0.2""", """l o""", """lo w</w>""", """e r</w>"""]
           _A							:  str    =		{"""unk_token""": """<unk>"""}

           _A							:  Union[str, Any]    =		os.path.join(self.tmpdirname	,  VOCAB_FILES_NAMES["""vocab_file"""]       )
           _A							:  Union[str, Any]    =		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(_a       ) + """\n"""       )
           with open(self.merges_file	,  """w"""	,  encoding="""utf-8"""       ) as fp:
                 fp.write("""\n""".join(_a       )       )

     def       a__			(						self	,  **_a       )		->							List[Any]:
           kwargs.update(self.special_tokens_map       )
           return CLIPTokenizer.from_pretrained(self.tmpdirname	,  **_a       )

     def       a__			(						self	,  **_a       )		->							Union[str, Any]:
           kwargs.update(self.special_tokens_map       )
           return CLIPTokenizerFast.from_pretrained(self.tmpdirname	,  **_a       )

     def       a__			(						self	,  _a       )		->							str:
           _A							:  Tuple    =		"""lower newer"""
           _A							:  Optional[Any]    =		"""lower newer"""
           return input_text, output_text

     def       a__			(						self       )		->							List[Any]:
           _A							:  Optional[int]    =		CLIPTokenizer(self.vocab_file	,  self.merges_file	,  **self.special_tokens_map       )
           _A							:  str    =		"""lower newer"""
           _A							:  List[str]    =		["""lo""", """w""", """er</w>""", """n""", """e""", """w""", """er</w>"""]
           _A							:  int    =		tokenizer.tokenize(_a       )
           self.assertListEqual(_a	,  _a       )

           _A							:  str    =		tokens + [tokenizer.unk_token]
           _A							:  Dict    =		[10, 2, 16, 9, 3, 2, 16, 20]
           self.assertListEqual(tokenizer.convert_tokens_to_ids(_a       )	,  _a       )

     @require_ftfy
     def       a__			(						self       )		->							Tuple:
           for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
                 with self.subTest(F'''{tokenizer.__class__.__name__} ({pretrained_name})'''       ):
                       _A							:  Dict    =		self.tokenizer_class.from_pretrained(_a	,  **_a       )
                       _A							:  str    =		self.rust_tokenizer_class.from_pretrained(_a	,  **_a       )

                       _A							:  List[str]    =		"""A\n'll 11p223RF☆ho!!to?'d'd''d of a cat to-$''d."""
                       _A							:  Dict    =		tokenizer_s.tokenize(_a       )
                       _A							:  Dict    =		tokenizer_r.tokenize(_a       )

                       self.assertListEqual(_a	,  _a       )

                       # Test that the tokenization is identical on an example containing a character (Latin Small Letter A
                       # with Tilde) encoded in 2 different ways
                       _A							:  Tuple    =		"""xa\u0303y""" + """ """ + """x\xe3y"""
                       _A							:  Dict    =		tokenizer_s.tokenize(_a       )
                       _A							:  Dict    =		tokenizer_r.tokenize(_a       )

                       self.assertListEqual(_a	,  _a       )

                       # Test that the tokenization is identical on unicode of space type
                       _A							:  Any    =		[
                           """\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:
                             _A							:  Optional[int]    =		tokenizer_s.tokenize(_a       )
                             _A							:  List[Any]    =		tokenizer_r.tokenize(_a       )

                             self.assertListEqual(_a	,  _a       )

                       # Test that the tokenization is identical on unicode of line break type
                       _A							:  int    =		[
                           """\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:
                             _A							:  Optional[Any]    =		tokenizer_s.tokenize(_a       )
                             _A							:  Tuple    =		tokenizer_r.tokenize(_a       )

                             self.assertListEqual(_a	,  _a       )

     def       a__			(						self       )		->							Any:
           # 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})'''       ):
                       _A							:  List[Any]    =		"""hello"""  # `hello` is a token in the vocabulary of `pretrained_name`
                       _A							:  str    =		F'''{text_of_1_token} {text_of_1_token}'''

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

                       _A							:  Any    =		F''' {text}'''

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

     def       a__			(						self       )		->							List[Any]:
           # 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(_a       ) 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       )		->							str:
           super().test_tokenization_python_rust_equals()



     def       a__			(						self       )		->							Union[str, Any]:
           # CLIP always lower cases letters
           pass

