

import gc
import unittest

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

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    EulerAncestralDiscreteScheduler,
    PNDMScheduler,
    StableDiffusionModelEditingPipeline,
    UNetaDConditionModel,
)
from diffusers.utils import slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu, skip_mps

from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS
from ..test_pipelines_common import PipelineKarrasSchedulerTesterMixin, PipelineLatentTesterMixin, PipelineTesterMixin


enable_full_determinism()
@skip_mps
class 		SCREAMING_SNAKE_CASE__					(		lowerCamelCase__						,	lowerCamelCase__						,	lowerCamelCase__						,	unittest.TestCase   ):







						"""simple docstring"""




						lowercase  :				Dict											=							StableDiffusionModelEditingPipeline
						lowercase  :				List[Any]											=							TEXT_TO_IMAGE_PARAMS
						lowercase  :				List[Any]											=							TEXT_TO_IMAGE_BATCH_PARAMS
						lowercase  :				List[Any]											=							TEXT_TO_IMAGE_IMAGE_PARAMS
						lowercase  :				List[Any]											=							TEXT_TO_IMAGE_IMAGE_PARAMS

						def __lowerCamelCase					(				self    )							->	Union[str, Any]:




									'''simple docstring'''


									torch.manual_seed(0    )
									__UpperCamelCase    :    Tuple								=      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 , )
									__UpperCamelCase    :    str								=      DDIMScheduler()
									torch.manual_seed(0    )
									__UpperCamelCase    :    Optional[Any]								=      AutoencoderKL(
									    block_out_channels=[32, 64] , in_channels=3 , out_channels=3 , down_block_types=["DownEncoderBlock2D", "DownEncoderBlock2D"] , up_block_types=["UpDecoderBlock2D", "UpDecoderBlock2D"] , latent_channels=4 , )
									torch.manual_seed(0    )
									__UpperCamelCase    :    Union[str, Any]								=      CLIPTextConfig(
									    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=10_00 , )
									__UpperCamelCase    :    Union[str, Any]								=      CLIPTextModel(__UpperCamelCase    )
									__UpperCamelCase    :    Tuple								=      CLIPTokenizer.from_pretrained("hf-internal-testing/tiny-random-clip"    )

									__UpperCamelCase    :    Any								=      {
									    "unet": unet,
									    "scheduler": scheduler,
									    "vae": vae,
									    "text_encoder": text_encoder,
									    "tokenizer": tokenizer,
									    "safety_checker": None,
									    "feature_extractor": None,
									}
									return components

						def __lowerCamelCase					(				self , __UpperCamelCase , __UpperCamelCase=0    )							->	Optional[Any]:




									'''simple docstring'''


									__UpperCamelCase    :    Union[str, Any]								=      torch.manual_seed(__UpperCamelCase    )
									__UpperCamelCase    :    Union[str, Any]								=      {
									    "prompt": "A field of roses",
									    "generator": generator,
									    # Setting height and width to None to prevent OOMs on CPU.
									    "height": None,
									    "width": None,
									    "num_inference_steps": 2,
									    "guidance_scale": 6.0,
									    "output_type": "numpy",
									}
									return inputs

						def __lowerCamelCase					(				self    )							->	List[str]:




									'''simple docstring'''


									__UpperCamelCase    :    Optional[Any]								=      "cpu"  # ensure determinism for the device-dependent torch.Generator
									__UpperCamelCase    :    Dict								=      self.get_dummy_components()
									__UpperCamelCase    :    Dict								=      StableDiffusionModelEditingPipeline(**__UpperCamelCase    )
									__UpperCamelCase    :    Optional[Any]								=      sd_pipe.to(__UpperCamelCase    )
									sd_pipe.set_progress_bar_config(disable=__UpperCamelCase    )

									__UpperCamelCase    :    List[Any]								=      self.get_dummy_inputs(__UpperCamelCase    )
									__UpperCamelCase    :    Union[str, Any]								=      sd_pipe(**__UpperCamelCase    ).images
									__UpperCamelCase    :    List[str]								=      image[0, -3:, -3:, -1]
									assert image.shape == (1, 64, 64, 3)

									__UpperCamelCase    :    Optional[Any]								=      np.array([0.4755, 0.5132, 0.4976, 0.3904, 0.3554, 0.4765, 0.5139, 0.5158, 0.4889]    )

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

						def __lowerCamelCase					(				self    )							->	Any:




									'''simple docstring'''


									__UpperCamelCase    :    List[str]								=      "cpu"  # ensure determinism for the device-dependent torch.Generator
									__UpperCamelCase    :    str								=      self.get_dummy_components()
									__UpperCamelCase    :    Union[str, Any]								=      StableDiffusionModelEditingPipeline(**__UpperCamelCase    )
									__UpperCamelCase    :    Optional[Any]								=      sd_pipe.to(__UpperCamelCase    )
									sd_pipe.set_progress_bar_config(disable=__UpperCamelCase    )

									__UpperCamelCase    :    Dict								=      self.get_dummy_inputs(__UpperCamelCase    )
									__UpperCamelCase    :    str								=      "french fries"
									__UpperCamelCase    :    Union[str, Any]								=      sd_pipe(**__UpperCamelCase , negative_prompt=__UpperCamelCase    )
									__UpperCamelCase    :    Tuple								=      output.images
									__UpperCamelCase    :    Optional[Any]								=      image[0, -3:, -3:, -1]

									assert image.shape == (1, 64, 64, 3)

									__UpperCamelCase    :    Optional[int]								=      np.array([0.4992, 0.5101, 0.5004, 0.3949, 0.3604, 0.4735, 0.5216, 0.5204, 0.4913]    )

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

						def __lowerCamelCase					(				self    )							->	List[str]:




									'''simple docstring'''


									__UpperCamelCase    :    Union[str, Any]								=      "cpu"  # ensure determinism for the device-dependent torch.Generator
									__UpperCamelCase    :    Any								=      self.get_dummy_components()
									__UpperCamelCase    :    Optional[Any]								=      EulerAncestralDiscreteScheduler(
									    beta_start=0.00085 , beta_end=0.012 , beta_schedule="scaled_linear"    )
									__UpperCamelCase    :    Tuple								=      StableDiffusionModelEditingPipeline(**__UpperCamelCase    )
									__UpperCamelCase    :    Optional[Any]								=      sd_pipe.to(__UpperCamelCase    )
									sd_pipe.set_progress_bar_config(disable=__UpperCamelCase    )

									__UpperCamelCase    :    Dict								=      self.get_dummy_inputs(__UpperCamelCase    )
									__UpperCamelCase    :    Optional[Any]								=      sd_pipe(**__UpperCamelCase    ).images
									__UpperCamelCase    :    List[str]								=      image[0, -3:, -3:, -1]

									assert image.shape == (1, 64, 64, 3)

									__UpperCamelCase    :    List[Any]								=      np.array([0.4747, 0.5372, 0.4779, 0.4982, 0.5543, 0.4816, 0.5238, 0.4904, 0.5027]    )

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

						def __lowerCamelCase					(				self    )							->	int:




									'''simple docstring'''


									__UpperCamelCase    :    List[Any]								=      "cpu"  # ensure determinism for the device-dependent torch.Generator
									__UpperCamelCase    :    Optional[int]								=      self.get_dummy_components()
									__UpperCamelCase    :    str								=      PNDMScheduler()
									__UpperCamelCase    :    Union[str, Any]								=      StableDiffusionModelEditingPipeline(**__UpperCamelCase    )
									__UpperCamelCase    :    Optional[int]								=      sd_pipe.to(__UpperCamelCase    )
									sd_pipe.set_progress_bar_config(disable=__UpperCamelCase    )

									__UpperCamelCase    :    Tuple								=      self.get_dummy_inputs(__UpperCamelCase    )
									# the pipeline does not expect pndm so test if it raises error.
									with self.assertRaises(__UpperCamelCase    ):
												__UpperCamelCase    :    List[Any]								=      sd_pipe(**__UpperCamelCase    ).images

						def __lowerCamelCase					(				self    )							->	Dict:




									'''simple docstring'''


									super().test_inference_batch_single_identical(expected_max_diff=5E-3    )




						def __lowerCamelCase					(				self    )							->	List[str]:




									'''simple docstring'''


									super().test_attention_slicing_forward_pass(expected_max_diff=5E-3    )







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







						"""simple docstring"""




						def __lowerCamelCase					(				self    )							->	Dict:




									'''simple docstring'''


									super().tearDown()
									gc.collect()
									torch.cuda.empty_cache()

						def __lowerCamelCase					(				self , __UpperCamelCase=0    )							->	List[str]:




									'''simple docstring'''


									__UpperCamelCase    :    Any								=      torch.manual_seed(__UpperCamelCase    )
									__UpperCamelCase    :    Optional[int]								=      {
									    "prompt": "A field of roses",
									    "generator": generator,
									    "num_inference_steps": 3,
									    "guidance_scale": 7.5,
									    "output_type": "numpy",
									}
									return inputs

						def __lowerCamelCase					(				self    )							->	Dict:




									'''simple docstring'''


									__UpperCamelCase    :    Optional[Any]								=      "CompVis/stable-diffusion-v1-4"
									__UpperCamelCase    :    Any								=      StableDiffusionModelEditingPipeline.from_pretrained(__UpperCamelCase , safety_checker=__UpperCamelCase    )
									pipe.to(__UpperCamelCase    )
									pipe.set_progress_bar_config(disable=__UpperCamelCase    )
									pipe.enable_attention_slicing()

									__UpperCamelCase    :    List[Any]								=      self.get_inputs()
									__UpperCamelCase    :    Optional[int]								=      pipe(**__UpperCamelCase    ).images
									__UpperCamelCase    :    str								=      image[0, -3:, -3:, -1].flatten()

									assert image.shape == (1, 5_12, 5_12, 3)

									__UpperCamelCase    :    int								=      np.array(
									    [0.6749496, 0.6386453, 0.51443267, 0.66094905, 0.61921215, 0.5491332, 0.5744417, 0.58075106, 0.5174658]    )

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

									# make sure image changes after editing
									pipe.edit_model("A pack of roses" , "A pack of blue roses"    )

									__UpperCamelCase    :    Tuple								=      pipe(**__UpperCamelCase    ).images
									__UpperCamelCase    :    List[str]								=      image[0, -3:, -3:, -1].flatten()

									assert image.shape == (1, 5_12, 5_12, 3)

									assert np.abs(expected_slice - image_slice    ).max() > 1E-1




						def __lowerCamelCase					(				self    )							->	Any:




									'''simple docstring'''


									torch.cuda.empty_cache()
									torch.cuda.reset_max_memory_allocated()
									torch.cuda.reset_peak_memory_stats()

									__UpperCamelCase    :    int								=      "CompVis/stable-diffusion-v1-4"
									__UpperCamelCase    :    List[str]								=      DDIMScheduler.from_pretrained(__UpperCamelCase , subfolder="scheduler"    )
									__UpperCamelCase    :    Any								=      StableDiffusionModelEditingPipeline.from_pretrained(
									    __UpperCamelCase , scheduler=__UpperCamelCase , safety_checker=__UpperCamelCase    )
									__UpperCamelCase    :    Any								=      pipe.to(__UpperCamelCase    )
									pipe.set_progress_bar_config(disable=__UpperCamelCase    )
									pipe.enable_attention_slicing(1    )
									pipe.enable_sequential_cpu_offload()

									__UpperCamelCase    :    Tuple								=      self.get_inputs()
									__UpperCamelCase    :    Union[str, Any]								=      pipe(**__UpperCamelCase    )

									__UpperCamelCase    :    Dict								=      torch.cuda.max_memory_allocated()
									# make sure that less than 4.4 GB is allocated
									assert mem_bytes < 4.4 * 10**9


import os
import pickle
import tempfile
import unittest
from typing import Callable, Optional

import numpy as np

from transformers import (
    BatchEncoding,
    BertTokenizer,
    BertTokenizerFast,
    PreTrainedTokenizer,
    PreTrainedTokenizerFast,
    TensorType,
    TokenSpan,
    is_tokenizers_available,
)
from transformers.models.gpta.tokenization_gpta import GPTaTokenizer
from transformers.testing_utils import CaptureStderr, require_flax, require_tf, require_tokenizers, require_torch, slow


if is_tokenizers_available():
					from tokenizers import Tokenizer
					from tokenizers.models import WordPiece
class 		SCREAMING_SNAKE_CASE__					(		unittest.TestCase   ):







						"""simple docstring"""




						def __lowerCamelCase					(				self , __UpperCamelCase    )							->	Union[str, Any]:




									'''simple docstring'''


									__UpperCamelCase    :    List[str]								=      list(tokenizer_class.max_model_input_sizes.keys()    )
									for model_name in sa_models[:1]:
												__UpperCamelCase    :    int								=      tokenizer_class.from_pretrained(__UpperCamelCase    )
												self.assertIsNotNone(__UpperCamelCase    )
												self.assertIsInstance(__UpperCamelCase , __UpperCamelCase    )
												self.assertIsInstance(__UpperCamelCase , __UpperCamelCase    )

												for special_tok in tokenizer.all_special_tokens:
															self.assertIsInstance(__UpperCamelCase , __UpperCamelCase    )
															__UpperCamelCase    :    str								=      tokenizer.convert_tokens_to_ids(__UpperCamelCase    )
															self.assertIsInstance(__UpperCamelCase , __UpperCamelCase    )

						def __lowerCamelCase					(				self , __UpperCamelCase , __UpperCamelCase = None    )							->	Tuple:




									'''simple docstring'''


									__UpperCamelCase    :    Optional[Any]								=      pickle.dumps(__UpperCamelCase    )
									self.assertIsNotNone(__UpperCamelCase    )

									__UpperCamelCase    :    List[str]								=      pickle.loads(__UpperCamelCase    )

									# Ensure is_fast is correctly restored
									self.assertEqual(be_restored.is_fast , be_original.is_fast    )

									# Ensure encodings are potentially correctly restored
									if be_original.is_fast:
												self.assertIsNotNone(be_restored.encodings    )
									else:
												self.assertIsNone(be_restored.encodings    )

									# Ensure the keys are the same
									for original_v, restored_v in zip(be_original.values() , be_restored.values()    ):
												if equal_op:
															self.assertTrue(equal_op(__UpperCamelCase , __UpperCamelCase    )    )
												else:
															self.assertEqual(__UpperCamelCase , __UpperCamelCase    )

						@slow
						def __lowerCamelCase					(				self    )							->	List[Any]:




									'''simple docstring'''


									self.check_tokenizer_from_pretrained(__UpperCamelCase    )

						def __lowerCamelCase					(				self    )							->	Optional[int]:




									'''simple docstring'''


									self.assertEqual(TensorType("tf"    ) , TensorType.TENSORFLOW    )
									self.assertEqual(TensorType("pt"    ) , TensorType.PYTORCH    )
									self.assertEqual(TensorType("np"    ) , TensorType.NUMPY    )

						@require_tokenizers
						def __lowerCamelCase					(				self    )							->	List[str]:




									'''simple docstring'''


									import numpy as np

									__UpperCamelCase    :    str								=      BertTokenizer.from_pretrained("bert-base-cased"    )
									__UpperCamelCase    :    Optional[Any]								=      BertTokenizerFast.from_pretrained("bert-base-cased"    )

									# Python no tensor
									with self.subTest("BatchEncoding (Python, return_tensors=None)"    ):
												self.assert_dump_and_restore(tokenizer_p("Small example to encode"    )    )

									with self.subTest("BatchEncoding (Python, return_tensors=NUMPY)"    ):
												self.assert_dump_and_restore(
												    tokenizer_p("Small example to encode" , return_tensors=TensorType.NUMPY    ) , np.array_equal    )

									with self.subTest("BatchEncoding (Rust, return_tensors=None)"    ):
												self.assert_dump_and_restore(tokenizer_r("Small example to encode"    )    )

									with self.subTest("BatchEncoding (Rust, return_tensors=NUMPY)"    ):
												self.assert_dump_and_restore(
												    tokenizer_r("Small example to encode" , return_tensors=TensorType.NUMPY    ) , np.array_equal    )

						@require_tf
						@require_tokenizers
						def __lowerCamelCase					(				self    )							->	Union[str, Any]:




									'''simple docstring'''


									import tensorflow as tf

									def tf_array_equals(__UpperCamelCase , __UpperCamelCase    ):
												return tf.reduce_all(tf.equal(__UpperCamelCase , __UpperCamelCase    )    )

									__UpperCamelCase    :    int								=      BertTokenizer.from_pretrained("bert-base-cased"    )
									__UpperCamelCase    :    Dict								=      BertTokenizerFast.from_pretrained("bert-base-cased"    )

									with self.subTest("BatchEncoding (Python, return_tensors=TENSORFLOW)"    ):
												self.assert_dump_and_restore(
												    tokenizer_p("Small example to encode" , return_tensors=TensorType.TENSORFLOW    ) , __UpperCamelCase    )

									with self.subTest("BatchEncoding (Rust, return_tensors=TENSORFLOW)"    ):
												self.assert_dump_and_restore(
												    tokenizer_r("Small example to encode" , return_tensors=TensorType.TENSORFLOW    ) , __UpperCamelCase    )

						@require_torch
						@require_tokenizers
						def __lowerCamelCase					(				self    )							->	Any:




									'''simple docstring'''


									import torch

									__UpperCamelCase    :    List[Any]								=      BertTokenizer.from_pretrained("bert-base-cased"    )
									__UpperCamelCase    :    Optional[Any]								=      BertTokenizerFast.from_pretrained("bert-base-cased"    )

									with self.subTest("BatchEncoding (Python, return_tensors=PYTORCH)"    ):
												self.assert_dump_and_restore(
												    tokenizer_p("Small example to encode" , return_tensors=TensorType.PYTORCH    ) , torch.equal    )

									with self.subTest("BatchEncoding (Rust, return_tensors=PYTORCH)"    ):
												self.assert_dump_and_restore(
												    tokenizer_r("Small example to encode" , return_tensors=TensorType.PYTORCH    ) , torch.equal    )

						@require_tokenizers
						def __lowerCamelCase					(				self    )							->	Any:




									'''simple docstring'''


									__UpperCamelCase    :    Optional[int]								=      BertTokenizer.from_pretrained("bert-base-cased"    )
									__UpperCamelCase    :    Tuple								=      BertTokenizerFast.from_pretrained("bert-base-cased"    )

									with self.subTest("Python Tokenizer"    ):
												self.assertFalse(tokenizer_p("Small example to_encode"    ).is_fast    )

									with self.subTest("Rust Tokenizer"    ):
												self.assertTrue(tokenizer_r("Small example to_encode"    ).is_fast    )

						@require_tokenizers
						def __lowerCamelCase					(				self    )							->	Union[str, Any]:




									'''simple docstring'''


									__UpperCamelCase    :    Any								=      BertTokenizerFast.from_pretrained("bert-base-cased"    )
									__UpperCamelCase    :    Dict								=      tokenizer_r(["Test", "\xad", "test"] , is_split_into_words=__UpperCamelCase    )

									self.assertEqual(encoded.word_to_tokens(0    ) , TokenSpan(start=1 , end=2    )    )
									self.assertEqual(encoded.word_to_tokens(1    ) , __UpperCamelCase    )
									self.assertEqual(encoded.word_to_tokens(2    ) , TokenSpan(start=2 , end=3    )    )

						def __lowerCamelCase					(				self    )							->	Optional[int]:




									'''simple docstring'''


									__UpperCamelCase    :    str								=      BatchEncoding({"inputs": [[1, 2, 3], [4, 5, 6]], "labels": [0, 1]}    )
									__UpperCamelCase    :    List[str]								=      batch.convert_to_tensors(tensor_type="np"    )
									self.assertEqual(tensor_batch["inputs"].shape , (2, 3)    )
									self.assertEqual(tensor_batch["labels"].shape , (2,)    )
									# test converting the converted
									with CaptureStderr() as cs:
												__UpperCamelCase    :    Optional[Any]								=      batch.convert_to_tensors(tensor_type="np"    )
									self.assertFalse(len(cs.err    ) , msg=f'''should have no warning, but got {cs.err}'''    )

									__UpperCamelCase    :    Union[str, Any]								=      BatchEncoding({"inputs": [1, 2, 3], "labels": 0}    )
									__UpperCamelCase    :    int								=      batch.convert_to_tensors(tensor_type="np" , prepend_batch_axis=__UpperCamelCase    )
									self.assertEqual(tensor_batch["inputs"].shape , (1, 3)    )
									self.assertEqual(tensor_batch["labels"].shape , (1,)    )

						@require_torch
						def __lowerCamelCase					(				self    )							->	List[str]:




									'''simple docstring'''


									__UpperCamelCase    :    Dict								=      BatchEncoding({"inputs": [[1, 2, 3], [4, 5, 6]], "labels": [0, 1]}    )
									__UpperCamelCase    :    List[Any]								=      batch.convert_to_tensors(tensor_type="pt"    )
									self.assertEqual(tensor_batch["inputs"].shape , (2, 3)    )
									self.assertEqual(tensor_batch["labels"].shape , (2,)    )
									# test converting the converted
									with CaptureStderr() as cs:
												__UpperCamelCase    :    Tuple								=      batch.convert_to_tensors(tensor_type="pt"    )
									self.assertFalse(len(cs.err    ) , msg=f'''should have no warning, but got {cs.err}'''    )

									__UpperCamelCase    :    Union[str, Any]								=      BatchEncoding({"inputs": [1, 2, 3], "labels": 0}    )
									__UpperCamelCase    :    List[Any]								=      batch.convert_to_tensors(tensor_type="pt" , prepend_batch_axis=__UpperCamelCase    )
									self.assertEqual(tensor_batch["inputs"].shape , (1, 3)    )
									self.assertEqual(tensor_batch["labels"].shape , (1,)    )

						@require_tf
						def __lowerCamelCase					(				self    )							->	Optional[Any]:




									'''simple docstring'''


									__UpperCamelCase    :    List[Any]								=      BatchEncoding({"inputs": [[1, 2, 3], [4, 5, 6]], "labels": [0, 1]}    )
									__UpperCamelCase    :    Tuple								=      batch.convert_to_tensors(tensor_type="tf"    )
									self.assertEqual(tensor_batch["inputs"].shape , (2, 3)    )
									self.assertEqual(tensor_batch["labels"].shape , (2,)    )
									# test converting the converted
									with CaptureStderr() as cs:
												__UpperCamelCase    :    Optional[int]								=      batch.convert_to_tensors(tensor_type="tf"    )
									self.assertFalse(len(cs.err    ) , msg=f'''should have no warning, but got {cs.err}'''    )

									__UpperCamelCase    :    str								=      BatchEncoding({"inputs": [1, 2, 3], "labels": 0}    )
									__UpperCamelCase    :    Union[str, Any]								=      batch.convert_to_tensors(tensor_type="tf" , prepend_batch_axis=__UpperCamelCase    )
									self.assertEqual(tensor_batch["inputs"].shape , (1, 3)    )
									self.assertEqual(tensor_batch["labels"].shape , (1,)    )

						@require_flax
						def __lowerCamelCase					(				self    )							->	List[Any]:




									'''simple docstring'''


									__UpperCamelCase    :    str								=      BatchEncoding({"inputs": [[1, 2, 3], [4, 5, 6]], "labels": [0, 1]}    )
									__UpperCamelCase    :    int								=      batch.convert_to_tensors(tensor_type="jax"    )
									self.assertEqual(tensor_batch["inputs"].shape , (2, 3)    )
									self.assertEqual(tensor_batch["labels"].shape , (2,)    )
									# test converting the converted
									with CaptureStderr() as cs:
												__UpperCamelCase    :    Dict								=      batch.convert_to_tensors(tensor_type="jax"    )
									self.assertFalse(len(cs.err    ) , msg=f'''should have no warning, but got {cs.err}'''    )

									__UpperCamelCase    :    Tuple								=      BatchEncoding({"inputs": [1, 2, 3], "labels": 0}    )
									__UpperCamelCase    :    Union[str, Any]								=      batch.convert_to_tensors(tensor_type="jax" , prepend_batch_axis=__UpperCamelCase    )
									self.assertEqual(tensor_batch["inputs"].shape , (1, 3)    )
									self.assertEqual(tensor_batch["labels"].shape , (1,)    )

						def __lowerCamelCase					(				self    )							->	int:




									'''simple docstring'''


									__UpperCamelCase    :    str								=      [{"input_ids": np.array([0, 1, 2]    )}, {"input_ids": np.array([0, 1, 2, 3]    )}]
									__UpperCamelCase    :    Any								=      BertTokenizer.from_pretrained("bert-base-cased"    )

									__UpperCamelCase    :    Optional[Any]								=      tokenizer.pad(__UpperCamelCase , padding=__UpperCamelCase    )
									self.assertTrue(isinstance(batch["input_ids"] , np.ndarray    )    )
									self.assertEqual(batch["input_ids"].tolist() , [[0, 1, 2, tokenizer.pad_token_id], [0, 1, 2, 3]]    )
									__UpperCamelCase    :    Optional[Any]								=      tokenizer.pad(__UpperCamelCase , padding=__UpperCamelCase , return_tensors="np"    )
									self.assertTrue(isinstance(batch["input_ids"] , np.ndarray    )    )
									self.assertEqual(batch["input_ids"].tolist() , [[0, 1, 2, tokenizer.pad_token_id], [0, 1, 2, 3]]    )

						@require_torch
						def __lowerCamelCase					(				self    )							->	Optional[int]:




									'''simple docstring'''


									import torch

									__UpperCamelCase    :    List[str]								=      [{"input_ids": torch.tensor([0, 1, 2]    )}, {"input_ids": torch.tensor([0, 1, 2, 3]    )}]
									__UpperCamelCase    :    str								=      BertTokenizer.from_pretrained("bert-base-cased"    )

									__UpperCamelCase    :    str								=      tokenizer.pad(__UpperCamelCase , padding=__UpperCamelCase    )
									self.assertTrue(isinstance(batch["input_ids"] , torch.Tensor    )    )
									self.assertEqual(batch["input_ids"].tolist() , [[0, 1, 2, tokenizer.pad_token_id], [0, 1, 2, 3]]    )
									__UpperCamelCase    :    int								=      tokenizer.pad(__UpperCamelCase , padding=__UpperCamelCase , return_tensors="pt"    )
									self.assertTrue(isinstance(batch["input_ids"] , torch.Tensor    )    )
									self.assertEqual(batch["input_ids"].tolist() , [[0, 1, 2, tokenizer.pad_token_id], [0, 1, 2, 3]]    )

						@require_tf
						def __lowerCamelCase					(				self    )							->	List[Any]:




									'''simple docstring'''


									import tensorflow as tf

									__UpperCamelCase    :    List[Any]								=      [{"input_ids": tf.constant([0, 1, 2]    )}, {"input_ids": tf.constant([0, 1, 2, 3]    )}]
									__UpperCamelCase    :    int								=      BertTokenizer.from_pretrained("bert-base-cased"    )

									__UpperCamelCase    :    Optional[Any]								=      tokenizer.pad(__UpperCamelCase , padding=__UpperCamelCase    )
									self.assertTrue(isinstance(batch["input_ids"] , tf.Tensor    )    )
									self.assertEqual(batch["input_ids"].numpy().tolist() , [[0, 1, 2, tokenizer.pad_token_id], [0, 1, 2, 3]]    )
									__UpperCamelCase    :    List[str]								=      tokenizer.pad(__UpperCamelCase , padding=__UpperCamelCase , return_tensors="tf"    )
									self.assertTrue(isinstance(batch["input_ids"] , tf.Tensor    )    )
									self.assertEqual(batch["input_ids"].numpy().tolist() , [[0, 1, 2, tokenizer.pad_token_id], [0, 1, 2, 3]]    )

						@require_tokenizers
						def __lowerCamelCase					(				self    )							->	int:




									'''simple docstring'''


									__UpperCamelCase    :    List[Any]								=      Tokenizer(WordPiece(unk_token="[UNK]"    )    )
									PreTrainedTokenizerFast(tokenizer_object=__UpperCamelCase    )




						@require_tokenizers
						def __lowerCamelCase					(				self    )							->	Optional[int]:




									'''simple docstring'''


									__UpperCamelCase    :    Union[str, Any]								=      Tokenizer(WordPiece(unk_token="[UNK]"    )    )
									with tempfile.TemporaryDirectory() as tmpdirname:
												bert_tokenizer.save(os.path.join(__UpperCamelCase , "tokenizer.json"    )    )
												PreTrainedTokenizerFast(tokenizer_file=os.path.join(__UpperCamelCase , "tokenizer.json"    )    )