






import gc
import random
import unittest

import numpy as np
import torch
from transformers import CLIPTextConfig, CLIPTextModel, CLIPTokenizer

from diffusers import AutoencoderKL, CycleDiffusionPipeline, DDIMScheduler, UNetaDConditionModel
from diffusers.utils import floats_tensor, load_image, load_numpy, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu, skip_mps

from ..pipeline_params import (
    IMAGE_TO_IMAGE_IMAGE_PARAMS,
    TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS,
    TEXT_GUIDED_IMAGE_VARIATION_PARAMS,
)
from ..test_pipelines_common import PipelineLatentTesterMixin, PipelineTesterMixin


enable_full_determinism()




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





       """simple docstring"""







       a    :		int									=CycleDiffusionPipeline
       a    :		List[str]									=TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {
           '''negative_prompt''',
           '''height''',
           '''width''',
           '''negative_prompt_embeds''',
       }
       a    :		Tuple									=PipelineTesterMixin.required_optional_params - {'''latents'''}
       a    :		List[str]									=TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS.union({'''source_prompt'''} )
       a    :		Optional[Any]									=IMAGE_TO_IMAGE_IMAGE_PARAMS
       a    :		List[Any]									=IMAGE_TO_IMAGE_IMAGE_PARAMS





       def       _a   ( self							):
         torch.manual_seed(0							)
         UpperCamelCase_: Tuple   				=    UNetaDConditionModel(
             block_out_channels=(3_2, 6_4)  ,      layers_per_block=2  ,      sample_size=3_2  ,      in_channels=4  ,      out_channels=4  ,      down_block_types=('DownBlock2D', 'CrossAttnDownBlock2D')  ,      up_block_types=('CrossAttnUpBlock2D', 'UpBlock2D')  ,      cross_attention_dim=3_2  ,      )
         UpperCamelCase_: Union[str, Any]   				=    DDIMScheduler(
             beta_start=0.0_0_0_8_5  ,      beta_end=0.0_1_2  ,      beta_schedule='scaled_linear'  ,      num_train_timesteps=1_0_0_0  ,      clip_sample=_lowerCamelCase  ,      set_alpha_to_one=_lowerCamelCase  ,      )
         torch.manual_seed(0							)
         UpperCamelCase_: int   				=    AutoencoderKL(
             block_out_channels=[3_2, 6_4]  ,      in_channels=3  ,      out_channels=3  ,      down_block_types=['DownEncoderBlock2D', 'DownEncoderBlock2D']  ,      up_block_types=['UpDecoderBlock2D', 'UpDecoderBlock2D']  ,      latent_channels=4  ,      )
         torch.manual_seed(0							)
         UpperCamelCase_: str   				=    CLIPTextConfig(
             bos_token_id=0  ,      eos_token_id=2  ,      hidden_size=3_2  ,      intermediate_size=3_7  ,      layer_norm_eps=1e-05  ,      num_attention_heads=4  ,      num_hidden_layers=5  ,      pad_token_id=1  ,      vocab_size=1_0_0_0  ,      )
         UpperCamelCase_: str   				=    CLIPTextModel(_lowerCamelCase							)
         UpperCamelCase_: int   				=    CLIPTokenizer.from_pretrained('hf-internal-testing/tiny-random-clip'							)

         UpperCamelCase_: str   				=    {
             'unet': unet,
             'scheduler': scheduler,
             'vae': vae,
             'text_encoder': text_encoder,
             'tokenizer': tokenizer,
             'safety_checker': None,
             'feature_extractor': None,
         }
         return components





       def       _a   ( self  ,      _lowerCamelCase  ,      _lowerCamelCase=0							):
         UpperCamelCase_: Any   				=    floats_tensor((1, 3, 3_2, 3_2)  ,      rng=random.Random(_lowerCamelCase							)							).to(_lowerCamelCase							)
         UpperCamelCase_: Optional[Any]   				=    image / 2 + 0.5
         if str(_lowerCamelCase							).startswith('mps'							):
           UpperCamelCase_: Optional[Any]   				=    torch.manual_seed(_lowerCamelCase							)
         else:
           UpperCamelCase_: Optional[Any]   				=    torch.Generator(device=_lowerCamelCase							).manual_seed(_lowerCamelCase							)
         UpperCamelCase_: List[Any]   				=    {
             'prompt': 'An astronaut riding an elephant',
             'source_prompt': 'An astronaut riding a horse',
             'image': image,
             'generator': generator,
             'num_inference_steps': 2,
             'eta': 0.1,
             'strength': 0.8,
             'guidance_scale': 3,
             'source_guidance_scale': 1,
             'output_type': 'numpy',
         }
         return inputs





       def       _a   ( self							):
         UpperCamelCase_: Optional[Any]   				=    'cpu'  # ensure determinism for the device-dependent torch.Generator

         UpperCamelCase_: Any   				=    self.get_dummy_components()
         UpperCamelCase_: Dict   				=    CycleDiffusionPipeline(**_lowerCamelCase							)
         UpperCamelCase_: List[str]   				=    pipe.to(_lowerCamelCase							)
         pipe.set_progress_bar_config(disable=_lowerCamelCase							)

         UpperCamelCase_: Optional[Any]   				=    self.get_dummy_inputs(_lowerCamelCase							)
         UpperCamelCase_: Optional[Any]   				=    pipe(**_lowerCamelCase							)
         UpperCamelCase_: Optional[Any]   				=    output.images

         UpperCamelCase_: Optional[Any]   				=    images[0, -3:, -3:, -1]

         assert images.shape == (1, 3_2, 3_2, 3)
         UpperCamelCase_: Optional[int]   				=    np.array([0.4_4_5_9, 0.4_9_4_3, 0.4_5_4_4, 0.6_6_4_3, 0.5_4_7_4, 0.4_3_2_7, 0.5_7_0_1, 0.5_9_5_9, 0.5_1_7_9]							)

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





       @unittest.skipIf(torch_device != 'cuda'  ,      'This test requires a GPU'							)
       def       _a   ( self							):
         UpperCamelCase_: Optional[Any]   				=    self.get_dummy_components()
         for name, module in components.items():
           if hasattr(_lowerCamelCase  ,      'half'							):
             UpperCamelCase_: Dict   				=    module.half()
         UpperCamelCase_: int   				=    CycleDiffusionPipeline(**_lowerCamelCase							)
         UpperCamelCase_: Optional[int]   				=    pipe.to(_lowerCamelCase							)
         pipe.set_progress_bar_config(disable=_lowerCamelCase							)

         UpperCamelCase_: Dict   				=    self.get_dummy_inputs(_lowerCamelCase							)
         UpperCamelCase_: str   				=    pipe(**_lowerCamelCase							)
         UpperCamelCase_: str   				=    output.images

         UpperCamelCase_: Optional[int]   				=    images[0, -3:, -3:, -1]

         assert images.shape == (1, 3_2, 3_2, 3)
         UpperCamelCase_: str   				=    np.array([0.3_5_0_6, 0.4_5_4_3, 0.4_4_6, 0.4_5_7_5, 0.5_1_9_5, 0.4_1_5_5, 0.5_2_7_3, 0.5_1_8, 0.4_1_1_6]							)

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





       @skip_mps
       def       _a   ( self							):
         return super().test_save_load_local()





       @unittest.skip('non-deterministic pipeline'							)
       def       _a   ( self							):
         return super().test_inference_batch_single_identical()





       @skip_mps
       def       _a   ( self							):
         return super().test_dict_tuple_outputs_equivalent()





       @skip_mps
       def       _a   ( self							):
         return super().test_save_load_optional_components()





       @skip_mps
       def       _a   ( self							):
         return super().test_attention_slicing_forward_pass()







@slow
@require_torch_gpu
class     _lowerCAmelCase(	unittest.TestCase ):





       """simple docstring"""







       def       _a   ( self							):
         # clean up the VRAM after each test
         super().tearDown()
         gc.collect()
         torch.cuda.empty_cache()





       def       _a   ( self							):
         UpperCamelCase_: Tuple   				=    load_image(
             'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'
             '/cycle-diffusion/black_colored_car.png'							)
         UpperCamelCase_: int   				=    load_numpy(
             'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/cycle-diffusion/blue_colored_car_fp16.npy'							)
         UpperCamelCase_: Optional[int]   				=    init_image.resize((5_1_2, 5_1_2)							)

         UpperCamelCase_: Dict   				=    'CompVis/stable-diffusion-v1-4'
         UpperCamelCase_: int   				=    DDIMScheduler.from_pretrained(_lowerCamelCase  ,      subfolder='scheduler'							)
         UpperCamelCase_: Dict   				=    CycleDiffusionPipeline.from_pretrained(
             _lowerCamelCase  ,      scheduler=_lowerCamelCase  ,      safety_checker=_lowerCamelCase  ,      torch_dtype=torch.floataa  ,      revision='fp16'							)

         pipe.to(_lowerCamelCase							)
         pipe.set_progress_bar_config(disable=_lowerCamelCase							)
         pipe.enable_attention_slicing()

         UpperCamelCase_: Optional[int]   				=    'A black colored car'
         UpperCamelCase_: List[str]   				=    'A blue colored car'

         UpperCamelCase_: List[Any]   				=    torch.manual_seed(0							)
         UpperCamelCase_: Tuple   				=    pipe(
             prompt=_lowerCamelCase  ,      source_prompt=_lowerCamelCase  ,      image=_lowerCamelCase  ,      num_inference_steps=1_0_0  ,      eta=0.1  ,      strength=0.8_5  ,      guidance_scale=3  ,      source_guidance_scale=1  ,      generator=_lowerCamelCase  ,      output_type='np'  ,      )
         UpperCamelCase_: List[str]   				=    output.images

         # the values aren't exactly equal, but the images look the same visually
         assert np.abs(image - expected_image							).max() < 5e-1





       def       _a   ( self							):
         UpperCamelCase_: int   				=    load_image(
             'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'
             '/cycle-diffusion/black_colored_car.png'							)
         UpperCamelCase_: Dict   				=    load_numpy(
             'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/cycle-diffusion/blue_colored_car.npy'							)
         UpperCamelCase_: int   				=    init_image.resize((5_1_2, 5_1_2)							)

         UpperCamelCase_: Optional[int]   				=    'CompVis/stable-diffusion-v1-4'
         UpperCamelCase_: Dict   				=    DDIMScheduler.from_pretrained(_lowerCamelCase  ,      subfolder='scheduler'							)
         UpperCamelCase_: Optional[Any]   				=    CycleDiffusionPipeline.from_pretrained(_lowerCamelCase  ,      scheduler=_lowerCamelCase  ,      safety_checker=_lowerCamelCase							)

         pipe.to(_lowerCamelCase							)
         pipe.set_progress_bar_config(disable=_lowerCamelCase							)
         pipe.enable_attention_slicing()

         UpperCamelCase_: List[str]   				=    'A black colored car'
         UpperCamelCase_: List[Any]   				=    'A blue colored car'

         UpperCamelCase_: Any   				=    torch.manual_seed(0							)
         UpperCamelCase_: List[str]   				=    pipe(
             prompt=_lowerCamelCase  ,      source_prompt=_lowerCamelCase  ,      image=_lowerCamelCase  ,      num_inference_steps=1_0_0  ,      eta=0.1  ,      strength=0.8_5  ,      guidance_scale=3  ,      source_guidance_scale=1  ,      generator=_lowerCamelCase  ,      output_type='np'  ,      )
         UpperCamelCase_: Optional[Any]   				=    output.images

         assert np.abs(image - expected_image							).max() < 2e-2







import itertools
import json
import os
import unittest

from transformers import AddedToken, LongformerTokenizer, LongformerTokenizerFast
from transformers.models.longformer.tokenization_longformer import VOCAB_FILES_NAMES
from transformers.testing_utils import require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin




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





       """simple docstring"""







       a    :		Optional[int]									=LongformerTokenizer
       a    :		Optional[int]									=True
       a    :		Tuple									=LongformerTokenizerFast
       a    :		Dict									=True





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

         # Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
         UpperCamelCase_: int   				=    [
             'l',
             'o',
             'w',
             'e',
             'r',
             's',
             't',
             'i',
             'd',
             'n',
             '\u0120',
             '\u0120l',
             '\u0120n',
             '\u0120lo',
             '\u0120low',
             'er',
             '\u0120lowest',
             '\u0120newer',
             '\u0120wider',
             '<unk>',
         ]
         UpperCamelCase_: Optional[Any]   				=    dict(zip(_lowerCamelCase  ,      range(len(_lowerCamelCase							)							)							)							)
         UpperCamelCase_: Any   				=    ['#version: 0.2', '\u0120 l', '\u0120l o', '\u0120lo w', 'e r', '']
         UpperCamelCase_: Tuple   				=    {'unk_token': '<unk>'}

         UpperCamelCase_: str   				=    os.path.join(self.tmpdirname  ,      VOCAB_FILES_NAMES['vocab_file']							)
         UpperCamelCase_: Tuple   				=    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 self.tokenizer_class.from_pretrained(self.tmpdirname  ,      **_lowerCamelCase							)





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





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





       def       _a   ( self							):
         UpperCamelCase_: int   				=    self.tokenizer_class(self.vocab_file  ,      self.merges_file  ,      **self.special_tokens_map							)
         UpperCamelCase_: Any   				=    'lower newer'
         UpperCamelCase_: Any   				=    ['l', 'o', 'w', 'er', '\u0120', 'n', 'e', 'w', 'er']
         UpperCamelCase_: str   				=    tokenizer.tokenize(_lowerCamelCase							)  # , add_prefix_space=True)
         self.assertListEqual(_lowerCamelCase  ,      _lowerCamelCase							)

         UpperCamelCase_: Dict   				=    tokens + [tokenizer.unk_token]
         UpperCamelCase_: int   				=    [0, 1, 2, 1_5, 1_0, 9, 3, 2, 1_5, 1_9]
         self.assertListEqual(tokenizer.convert_tokens_to_ids(_lowerCamelCase							)  ,      _lowerCamelCase							)





       def       _a   ( self							):
         UpperCamelCase_: Tuple   				=    self.get_tokenizer()

         self.assertListEqual(tokenizer.encode('Hello world!'  ,      add_special_tokens=_lowerCamelCase							)  ,      [0, 3_1_4_1_4, 2_3_2, 3_2_8, 2]							)
         self.assertListEqual(
             tokenizer.encode('Hello world! cécé herlolip 418'  ,      add_special_tokens=_lowerCamelCase							)  ,      [0, 3_1_4_1_4, 2_3_2, 3_2_8, 7_4_0, 1_1_4_0, 1_2_6_9_5, 6_9, 4_6_0_7_8, 1_5_8_8, 2]  ,      )





       @slow
       def       _a   ( self							):
         UpperCamelCase_: int   				=    self.tokenizer_class.from_pretrained('allenai/longformer-base-4096'							)

         UpperCamelCase_: Dict   				=    tokenizer.encode('sequence builders'  ,      add_special_tokens=_lowerCamelCase							)
         UpperCamelCase_: Any   				=    tokenizer.encode('multi-sequence build'  ,      add_special_tokens=_lowerCamelCase							)

         UpperCamelCase_: Union[str, Any]   				=    tokenizer.encode(
             'sequence builders'  ,      add_special_tokens=_lowerCamelCase  ,      add_prefix_space=_lowerCamelCase							)
         UpperCamelCase_: Any   				=    tokenizer.encode(
             'sequence builders'  ,      'multi-sequence build'  ,      add_special_tokens=_lowerCamelCase  ,      add_prefix_space=_lowerCamelCase							)

         UpperCamelCase_: int   				=    tokenizer.build_inputs_with_special_tokens(_lowerCamelCase							)
         UpperCamelCase_: Tuple   				=    tokenizer.build_inputs_with_special_tokens(_lowerCamelCase  ,      _lowerCamelCase							)

         assert encoded_sentence == encoded_text_from_decode
         assert encoded_pair == encoded_pair_from_decode





       def       _a   ( self							):
         UpperCamelCase_: Optional[int]   				=    self.get_tokenizer()

         UpperCamelCase_: Optional[int]   				=    'Encode this sequence.'
         UpperCamelCase_: List[Any]   				=    tokenizer.byte_encoder[' '.encode('utf-8'							)[0]]

         # Testing encoder arguments
         UpperCamelCase_: Dict   				=    tokenizer.encode(_lowerCamelCase  ,      add_special_tokens=_lowerCamelCase  ,      add_prefix_space=_lowerCamelCase							)
         UpperCamelCase_: List[str]   				=    tokenizer.convert_ids_to_tokens(encoded[0]							)[0]
         self.assertNotEqual(_lowerCamelCase  ,      _lowerCamelCase							)

         UpperCamelCase_: List[Any]   				=    tokenizer.encode(_lowerCamelCase  ,      add_special_tokens=_lowerCamelCase  ,      add_prefix_space=_lowerCamelCase							)
         UpperCamelCase_: int   				=    tokenizer.convert_ids_to_tokens(encoded[0]							)[0]
         self.assertEqual(_lowerCamelCase  ,      _lowerCamelCase							)

         tokenizer.add_special_tokens({'bos_token': '<s>'}							)
         UpperCamelCase_: Optional[Any]   				=    tokenizer.encode(_lowerCamelCase  ,      add_special_tokens=_lowerCamelCase							)
         UpperCamelCase_: Any   				=    tokenizer.convert_ids_to_tokens(encoded[1]							)[0]
         self.assertNotEqual(_lowerCamelCase  ,      _lowerCamelCase							)

         # Testing spaces after special tokens
         UpperCamelCase_: List[Any]   				=    '<mask>'
         tokenizer.add_special_tokens(
             {'mask_token': AddedToken(_lowerCamelCase  ,      lstrip=_lowerCamelCase  ,      rstrip=_lowerCamelCase							)}							)  # mask token has a left space
         UpperCamelCase_: List[Any]   				=    tokenizer.convert_tokens_to_ids(_lowerCamelCase							)

         UpperCamelCase_: Dict   				=    'Encode <mask> sequence'
         UpperCamelCase_: Dict   				=    'Encode <mask>sequence'

         UpperCamelCase_: Any   				=    tokenizer.encode(_lowerCamelCase							)
         UpperCamelCase_: Optional[Any]   				=    encoded.index(_lowerCamelCase							)
         UpperCamelCase_: Optional[Any]   				=    tokenizer.convert_ids_to_tokens(encoded[mask_loc + 1]							)[0]
         self.assertEqual(_lowerCamelCase  ,      _lowerCamelCase							)

         UpperCamelCase_: List[str]   				=    tokenizer.encode(_lowerCamelCase							)
         UpperCamelCase_: List[Any]   				=    encoded.index(_lowerCamelCase							)
         UpperCamelCase_: Optional[int]   				=    tokenizer.convert_ids_to_tokens(encoded[mask_loc + 1]							)[0]
         self.assertNotEqual(_lowerCamelCase  ,      _lowerCamelCase							)





       def       _a   ( self							):
         pass





       def       _a   ( self							):
         for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
           with self.subTest(f'''{tokenizer.__class__.__name__} ({pretrained_name})'''							):
             UpperCamelCase_: Any   				=    self.rust_tokenizer_class.from_pretrained(_lowerCamelCase  ,      **_lowerCamelCase							)
             UpperCamelCase_: Tuple   				=    self.tokenizer_class.from_pretrained(_lowerCamelCase  ,      **_lowerCamelCase							)
             UpperCamelCase_: List[Any]   				=    'A, <mask> AllenNLP sentence.'
             UpperCamelCase_: int   				=    tokenizer_r.encode_plus(_lowerCamelCase  ,      add_special_tokens=_lowerCamelCase  ,      return_token_type_ids=_lowerCamelCase							)
             UpperCamelCase_: Any   				=    tokenizer_p.encode_plus(_lowerCamelCase  ,      add_special_tokens=_lowerCamelCase  ,      return_token_type_ids=_lowerCamelCase							)

             # token_type_ids should put 0 everywhere
             self.assertEqual(sum(tokens_r['token_type_ids']							)  ,      sum(tokens_p['token_type_ids']							)							)

             # attention_mask should put 1 everywhere, so sum over length should be 1
             self.assertEqual(
                 sum(tokens_r['attention_mask']							) / len(tokens_r['attention_mask']							)  ,      sum(tokens_p['attention_mask']							) / len(tokens_p['attention_mask']							)  ,      )

             UpperCamelCase_: List[str]   				=    tokenizer_r.convert_ids_to_tokens(tokens_r['input_ids']							)
             UpperCamelCase_: str   				=    tokenizer_p.convert_ids_to_tokens(tokens_p['input_ids']							)

             # Rust correctly handles the space before the mask while python doesnt
             self.assertSequenceEqual(tokens_p['input_ids']  ,      [0, 2_5_0, 6, 5_0_2_6_4, 3_8_2_3, 4_8_7, 2_1_9_9_2, 3_6_4_5, 4, 2]							)
             self.assertSequenceEqual(tokens_r['input_ids']  ,      [0, 2_5_0, 6, 5_0_2_6_4, 3_8_2_3, 4_8_7, 2_1_9_9_2, 3_6_4_5, 4, 2]							)

             self.assertSequenceEqual(
                 _lowerCamelCase  ,      ['<s>', 'A', ',', '<mask>', 'ĠAllen', 'N', 'LP', 'Ġsentence', '.', '</s>']							)
             self.assertSequenceEqual(
                 _lowerCamelCase  ,      ['<s>', 'A', ',', '<mask>', 'ĠAllen', 'N', 'LP', 'Ġsentence', '.', '</s>']							)





       def       _a   ( self							):
         for trim_offsets, add_prefix_space in itertools.product([True, False]  ,      repeat=2							):
           UpperCamelCase_: Optional[Any]   				=    self.rust_tokenizer_class.from_pretrained(
               self.tmpdirname  ,      use_fast=_lowerCamelCase  ,      add_prefix_space=_lowerCamelCase  ,      trim_offsets=_lowerCamelCase							)

           UpperCamelCase_: Union[str, Any]   				=    json.loads(tokenizer_r.backend_tokenizer.pre_tokenizer.__getstate__()							)
           UpperCamelCase_: Optional[int]   				=    json.loads(tokenizer_r.backend_tokenizer.post_processor.__getstate__()							)

           self.assertEqual(pre_tokenizer_state['add_prefix_space']  ,      _lowerCamelCase							)

           self.assertEqual(post_processor_state['add_prefix_space']  ,      _lowerCamelCase							)
           self.assertEqual(post_processor_state['trim_offsets']  ,      _lowerCamelCase							)





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

             UpperCamelCase_: Optional[int]   				=    self.rust_tokenizer_class.from_pretrained(
                 _lowerCamelCase  ,      use_fast=_lowerCamelCase  ,      add_prefix_space=_lowerCamelCase  ,      trim_offsets=_lowerCamelCase							)
             UpperCamelCase_: str   				=    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_: Optional[int]   				=    self.rust_tokenizer_class.from_pretrained(
                 _lowerCamelCase  ,      use_fast=_lowerCamelCase  ,      add_prefix_space=_lowerCamelCase  ,      trim_offsets=_lowerCamelCase							)
             UpperCamelCase_: str   				=    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_: Optional[Any]   				=    self.rust_tokenizer_class.from_pretrained(
                 _lowerCamelCase  ,      use_fast=_lowerCamelCase  ,      add_prefix_space=_lowerCamelCase  ,      trim_offsets=_lowerCamelCase							)
             UpperCamelCase_: Dict   				=    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							), len(_lowerCamelCase							) + 1 + len(_lowerCamelCase							))  ,      )

             UpperCamelCase_: List[str]   				=    self.rust_tokenizer_class.from_pretrained(
                 _lowerCamelCase  ,      use_fast=_lowerCamelCase  ,      add_prefix_space=_lowerCamelCase  ,      trim_offsets=_lowerCamelCase							)
             UpperCamelCase_: Optional[Any]   				=    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							), len(_lowerCamelCase							) + 1 + len(_lowerCamelCase							))  ,      )

             UpperCamelCase_: Optional[int]   				=    f''' {text}'''

             # tokenizer_r = self.rust_tokenizer_class.from_pretrained(
             #     pretrained_name, use_fast=True, add_prefix_space=True, trim_offsets=True
             # )
             # encoding = tokenizer_r(text, return_offsets_mapping=True, add_special_tokens=False)
             # self.assertEqual(encoding.offset_mapping[0], (1, 1 + len(text_of_1_token)))
             # self.assertEqual(
             #     encoding.offset_mapping[1],
             #     (1 + len(text_of_1_token) + 1, 1 + len(text_of_1_token) + 1 + len(text_of_1_token)),
             # )

             UpperCamelCase_: Optional[int]   				=    self.rust_tokenizer_class.from_pretrained(
                 _lowerCamelCase  ,      use_fast=_lowerCamelCase  ,      add_prefix_space=_lowerCamelCase  ,      trim_offsets=_lowerCamelCase							)
             UpperCamelCase_: Tuple   				=    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							))  ,      )

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

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