

import unittest

import torch

from diffusers import UNetaDModel
from diffusers.utils import floats_tensor, slow, torch_device

from .test_modeling_common import ModelTesterMixin, UNetTesterMixin
class 		SCREAMING_SNAKE_CASE__					(		snake_case__						,	snake_case__						,	unittest.TestCase   ):







						"""simple docstring"""




						lowercase  :				Dict											=							UNetaDModel
						lowercase  :				Optional[int]											=							'sample'

						@property
						def __lowerCamelCase					(				self    )							->	Any:




									'''simple docstring'''


									__UpperCamelCase    :    Union[str, Any]								=      4
									__UpperCamelCase    :    Tuple								=      14
									__UpperCamelCase    :    Union[str, Any]								=      16

									__UpperCamelCase    :    str								=      floats_tensor((batch_size, num_features, seq_len)    ).to(__snake_case    )
									__UpperCamelCase    :    List[Any]								=      torch.tensor([10] * batch_size    ).to(__snake_case    )

									return {"sample": noise, "timestep": time_step}

						@property
						def __lowerCamelCase					(				self    )							->	str:




									'''simple docstring'''


									return (4, 14, 16)

						@property
						def __lowerCamelCase					(				self    )							->	str:




									'''simple docstring'''


									return (4, 14, 16)

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




									'''simple docstring'''


									pass

						def __lowerCamelCase					(				self    )							->	int:




									'''simple docstring'''


									pass

						@unittest.skipIf(torch_device == "mps" , "mish op not supported in MPS"    )
						def __lowerCamelCase					(				self    )							->	Optional[int]:




									'''simple docstring'''


									super().test_determinism()

						@unittest.skipIf(torch_device == "mps" , "mish op not supported in MPS"    )
						def __lowerCamelCase					(				self    )							->	Dict:




									'''simple docstring'''


									super().test_outputs_equivalence()

						@unittest.skipIf(torch_device == "mps" , "mish op not supported in MPS"    )
						def __lowerCamelCase					(				self    )							->	List[str]:




									'''simple docstring'''


									super().test_from_save_pretrained()

						@unittest.skipIf(torch_device == "mps" , "mish op not supported in MPS"    )
						def __lowerCamelCase					(				self    )							->	int:




									'''simple docstring'''


									super().test_from_save_pretrained_variant()

						@unittest.skipIf(torch_device == "mps" , "mish op not supported in MPS"    )
						def __lowerCamelCase					(				self    )							->	Optional[int]:




									'''simple docstring'''


									super().test_model_from_pretrained()

						@unittest.skipIf(torch_device == "mps" , "mish op not supported in MPS"    )
						def __lowerCamelCase					(				self    )							->	Optional[Any]:




									'''simple docstring'''


									super().test_output()

						def __lowerCamelCase					(				self    )							->	int:




									'''simple docstring'''


									__UpperCamelCase    :    Optional[int]								=      {
									    "block_out_channels": (32, 64, 1_28, 2_56),
									    "in_channels": 14,
									    "out_channels": 14,
									    "time_embedding_type": "positional",
									    "use_timestep_embedding": True,
									    "flip_sin_to_cos": False,
									    "freq_shift": 1.0,
									    "out_block_type": "OutConv1DBlock",
									    "mid_block_type": "MidResTemporalBlock1D",
									    "down_block_types": ("DownResnetBlock1D", "DownResnetBlock1D", "DownResnetBlock1D", "DownResnetBlock1D"),
									    "up_block_types": ("UpResnetBlock1D", "UpResnetBlock1D", "UpResnetBlock1D"),
									    "act_fn": "mish",
									}
									__UpperCamelCase    :    str								=      self.dummy_input
									return init_dict, inputs_dict

						@unittest.skipIf(torch_device == "mps" , "mish op not supported in MPS"    )
						def __lowerCamelCase					(				self    )							->	int:




									'''simple docstring'''


									__UpperCamelCase							,				__UpperCamelCase    :    List[Any]								=      UNetaDModel.from_pretrained(
									    "bglick13/hopper-medium-v2-value-function-hor32" , output_loading_info=__snake_case , subfolder="unet"    )
									self.assertIsNotNone(__snake_case    )
									self.assertEqual(len(loading_info["missing_keys"]    ) , 0    )

									model.to(__snake_case    )
									__UpperCamelCase    :    Dict								=      model(**self.dummy_input    )

									assert image is not None, "Make sure output is not None"

						@unittest.skipIf(torch_device == "mps" , "mish op not supported in MPS"    )
						def __lowerCamelCase					(				self    )							->	Union[str, Any]:




									'''simple docstring'''


									__UpperCamelCase    :    Union[str, Any]								=      UNetaDModel.from_pretrained("bglick13/hopper-medium-v2-value-function-hor32" , subfolder="unet"    )
									torch.manual_seed(0    )
									if torch.cuda.is_available():
												torch.cuda.manual_seed_all(0    )

									__UpperCamelCase    :    List[Any]								=      model.config.in_channels
									__UpperCamelCase    :    Optional[Any]								=      16
									__UpperCamelCase    :    Tuple								=      torch.randn((1, seq_len, num_features)    ).permute(
									    0 , 2 , 1    )  # match original, we can update values and remove
									__UpperCamelCase    :    Tuple								=      torch.full((num_features,) , 0    )

									with torch.no_grad():
												__UpperCamelCase    :    List[Any]								=      model(__snake_case , __snake_case    ).sample.permute(0 , 2 , 1    )

									__UpperCamelCase    :    Any								=      output[0, -3:, -3:].flatten()
									# fmt: off
									__UpperCamelCase    :    Optional[int]								=      torch.tensor([-2.137172, 1.1426016, 0.3688687, -0.766922, 0.7303146, 0.11038864, -0.4760633, 0.13270172, 0.02591348]    )
									# fmt: on
									self.assertTrue(torch.allclose(__snake_case , __snake_case , rtol=1E-3    )    )

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




									'''simple docstring'''


									pass




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




									'''simple docstring'''


									__UpperCamelCase    :    Optional[Any]								=      "harmonai/maestro-150k"
									__UpperCamelCase    :    Optional[Any]								=      UNetaDModel.from_pretrained(__snake_case , subfolder="unet"    )
									model.to(__snake_case    )

									__UpperCamelCase    :    List[str]								=      6_55_36
									__UpperCamelCase    :    List[Any]								=      torch.sin(torch.arange(__snake_case    )[None, None, :].repeat(1 , 2 , 1    )    ).to(__snake_case    )
									__UpperCamelCase    :    List[Any]								=      torch.tensor([1]    ).to(__snake_case    )

									with torch.no_grad():
												__UpperCamelCase    :    Any								=      model(__snake_case , __snake_case    ).sample

									__UpperCamelCase    :    Tuple								=      output.abs().sum()
									__UpperCamelCase    :    Union[str, Any]								=      output.abs().max()

									assert (output_sum - 224.0896).abs() < 0.5
									assert (output_max - 0.0607).abs() < 4E-4







class 		SCREAMING_SNAKE_CASE__					(		snake_case__						,	snake_case__						,	unittest.TestCase   ):







						"""simple docstring"""




						lowercase  :				int											=							UNetaDModel
						lowercase  :				str											=							'sample'

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




									'''simple docstring'''


									__UpperCamelCase    :    Optional[int]								=      4
									__UpperCamelCase    :    Optional[Any]								=      14
									__UpperCamelCase    :    Dict								=      16

									__UpperCamelCase    :    Any								=      floats_tensor((batch_size, num_features, seq_len)    ).to(__snake_case    )
									__UpperCamelCase    :    Tuple								=      torch.tensor([10] * batch_size    ).to(__snake_case    )

									return {"sample": noise, "timestep": time_step}

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




									'''simple docstring'''


									return (4, 14, 16)

						@property
						def __lowerCamelCase					(				self    )							->	Dict:




									'''simple docstring'''


									return (4, 14, 1)

						@unittest.skipIf(torch_device == "mps" , "mish op not supported in MPS"    )
						def __lowerCamelCase					(				self    )							->	Tuple:




									'''simple docstring'''


									super().test_determinism()

						@unittest.skipIf(torch_device == "mps" , "mish op not supported in MPS"    )
						def __lowerCamelCase					(				self    )							->	List[Any]:




									'''simple docstring'''


									super().test_outputs_equivalence()

						@unittest.skipIf(torch_device == "mps" , "mish op not supported in MPS"    )
						def __lowerCamelCase					(				self    )							->	List[str]:




									'''simple docstring'''


									super().test_from_save_pretrained()

						@unittest.skipIf(torch_device == "mps" , "mish op not supported in MPS"    )
						def __lowerCamelCase					(				self    )							->	Union[str, Any]:




									'''simple docstring'''


									super().test_from_save_pretrained_variant()

						@unittest.skipIf(torch_device == "mps" , "mish op not supported in MPS"    )
						def __lowerCamelCase					(				self    )							->	Optional[int]:




									'''simple docstring'''


									super().test_model_from_pretrained()

						@unittest.skipIf(torch_device == "mps" , "mish op not supported in MPS"    )
						def __lowerCamelCase					(				self    )							->	Dict:




									'''simple docstring'''


									__UpperCamelCase							,				__UpperCamelCase    :    Optional[Any]								=      self.prepare_init_args_and_inputs_for_common()
									__UpperCamelCase    :    int								=      self.model_class(**__snake_case    )
									model.to(__snake_case    )
									model.eval()

									with torch.no_grad():
												__UpperCamelCase    :    Tuple								=      model(**__snake_case    )

												if isinstance(__snake_case , __snake_case    ):
															__UpperCamelCase    :    str								=      output.sample

									self.assertIsNotNone(__snake_case    )
									__UpperCamelCase    :    Any								=      torch.Size((inputs_dict["sample"].shape[0], 1)    )
									self.assertEqual(output.shape , __snake_case , "Input and output shapes do not match"    )

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




									'''simple docstring'''


									pass

						def __lowerCamelCase					(				self    )							->	int:




									'''simple docstring'''


									pass

						def __lowerCamelCase					(				self    )							->	str:




									'''simple docstring'''


									__UpperCamelCase    :    Any								=      {
									    "in_channels": 14,
									    "out_channels": 14,
									    "down_block_types": ["DownResnetBlock1D", "DownResnetBlock1D", "DownResnetBlock1D", "DownResnetBlock1D"],
									    "up_block_types": [],
									    "out_block_type": "ValueFunction",
									    "mid_block_type": "ValueFunctionMidBlock1D",
									    "block_out_channels": [32, 64, 1_28, 2_56],
									    "layers_per_block": 1,
									    "downsample_each_block": True,
									    "use_timestep_embedding": True,
									    "freq_shift": 1.0,
									    "flip_sin_to_cos": False,
									    "time_embedding_type": "positional",
									    "act_fn": "mish",
									}
									__UpperCamelCase    :    Optional[int]								=      self.dummy_input
									return init_dict, inputs_dict

						@unittest.skipIf(torch_device == "mps" , "mish op not supported in MPS"    )
						def __lowerCamelCase					(				self    )							->	str:




									'''simple docstring'''


									__UpperCamelCase							,				__UpperCamelCase    :    str								=      UNetaDModel.from_pretrained(
									    "bglick13/hopper-medium-v2-value-function-hor32" , output_loading_info=__snake_case , subfolder="value_function"    )
									self.assertIsNotNone(__snake_case    )
									self.assertEqual(len(vf_loading_info["missing_keys"]    ) , 0    )

									value_function.to(__snake_case    )
									__UpperCamelCase    :    Optional[Any]								=      value_function(**self.dummy_input    )

									assert image is not None, "Make sure output is not None"

						@unittest.skipIf(torch_device == "mps" , "mish op not supported in MPS"    )
						def __lowerCamelCase					(				self    )							->	Any:




									'''simple docstring'''


									__UpperCamelCase							,				__UpperCamelCase    :    str								=      UNetaDModel.from_pretrained(
									    "bglick13/hopper-medium-v2-value-function-hor32" , output_loading_info=__snake_case , subfolder="value_function"    )
									torch.manual_seed(0    )
									if torch.cuda.is_available():
												torch.cuda.manual_seed_all(0    )

									__UpperCamelCase    :    Any								=      value_function.config.in_channels
									__UpperCamelCase    :    Any								=      14
									__UpperCamelCase    :    List[str]								=      torch.randn((1, seq_len, num_features)    ).permute(
									    0 , 2 , 1    )  # match original, we can update values and remove
									__UpperCamelCase    :    Any								=      torch.full((num_features,) , 0    )

									with torch.no_grad():
												__UpperCamelCase    :    str								=      value_function(__snake_case , __snake_case    ).sample

									# fmt: off
									__UpperCamelCase    :    List[str]								=      torch.tensor([165.25] * seq_len    )
									# fmt: on
									self.assertTrue(torch.allclose(__snake_case , __snake_case , rtol=1E-3    )    )




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




									'''simple docstring'''


									pass


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"    )    )