code: 
  
  
  '''simple docstring'''
  
  import inspect
  import unittest
  
  from transformers import ResNetConfig
  from transformers.testing_utils import require_torch, require_vision, slow, torch_device
  from transformers.utils import cached_property, is_torch_available, is_vision_available
  
  from ...test_backbone_common import BackboneTesterMixin
  from ...test_configuration_common import ConfigTester
  from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
  from ...test_pipeline_mixin import PipelineTesterMixin
  
  
  if is_torch_available():
  							import torch
  							from torch import nn
  
  							from transformers import ResNetBackbone, ResNetForImageClassification, ResNetModel
  							from transformers.models.resnet.modeling_resnet import RESNET_PRETRAINED_MODEL_ARCHIVE_LIST
  
  
  if is_vision_available():
  							from PIL import Image
  
  							from transformers import AutoImageProcessor
  class _lowerCamelCase :
  
  
  
  		'''simple docstring'''
  
  
  
  
  
  
  
  		def __init__(      self	:		Dict						,  _A	:		List[Any]						,  _A	:		List[Any]=3						,  _A	:		Tuple=32						,  _A	:		str=3						,  _A	:		Any=10						,  _A	:		List[str]=[10, 20, 30, 40]						,  _A	:		Optional[Any]=[1, 1, 2, 1]						,  _A	:		Dict=True						,  _A	:		int=True						,  _A	:		Dict="relu"						,  _A	:		Any=3						,  _A	:		Union[str, Any]=None						,  _A	:		int=["stage2", "stage3", "stage4"]						,  _A	:		Union[str, Any]=[2, 3, 4]						,  )						->				Union[str, Any]:
  				__magic_name__ :					Union[str, Any]  			=  parent
  				__magic_name__ :					str  			=  batch_size
  				__magic_name__ :					str  			=  image_size
  				__magic_name__ :					Optional[Any]  			=  num_channels
  				__magic_name__ :					List[str]  			=  embeddings_size
  				__magic_name__ :					str  			=  hidden_sizes
  				__magic_name__ :					Tuple  			=  depths
  				__magic_name__ :					Any  			=  is_training
  				__magic_name__ :					Union[str, Any]  			=  use_labels
  				__magic_name__ :					List[str]  			=  hidden_act
  				__magic_name__ :					Union[str, Any]  			=  num_labels
  				__magic_name__ :					Any  			=  scope
  				__magic_name__ :					List[Any]  			=  len(_A    )
  				__magic_name__ :					Tuple  			=  out_features
  				__magic_name__ :					Tuple  			=  out_indices
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		Optional[int]    )						->				str:
  				__magic_name__ :					List[str]  			=  floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]    )
  
  				__magic_name__ :					Dict  			=  None
  				if self.use_labels:
  						__magic_name__ :					Optional[int]  			=  ids_tensor([self.batch_size]						,  self.num_labels    )
  
  				__magic_name__ :					Any  			=  self.get_config()
  
  				return config, pixel_values, labels
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		Optional[Any]    )						->				Optional[int]:
  				return ResNetConfig(
  				    num_channels=self.num_channels						,  embeddings_size=self.embeddings_size						,  hidden_sizes=self.hidden_sizes						,  depths=self.depths						,  hidden_act=self.hidden_act						,  num_labels=self.num_labels						,  out_features=self.out_features						,  out_indices=self.out_indices						,  )
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		Dict						,  _A	:		str						,  _A	:		Optional[int]						,  _A	:		List[Any]    )						->				str:
  				__magic_name__ :					Any  			=  ResNetModel(config=_A    )
  				model.to(_A    )
  				model.eval()
  				__magic_name__ :					List[Any]  			=  model(_A    )
  				# expected last hidden states: B, C, H // 32, W // 32
  				self.parent.assertEqual(
  				    result.last_hidden_state.shape						,  (self.batch_size, self.hidden_sizes[-1], self.image_size // 32, self.image_size // 32)						,  )
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		Optional[int]						,  _A	:		int						,  _A	:		int						,  _A	:		int    )						->				Optional[Any]:
  				__magic_name__ :					Any  			=  self.num_labels
  				__magic_name__ :					List[Any]  			=  ResNetForImageClassification(_A    )
  				model.to(_A    )
  				model.eval()
  				__magic_name__ :					Optional[Any]  			=  model(_A						,  labels=_A    )
  				self.parent.assertEqual(result.logits.shape						,  (self.batch_size, self.num_labels)    )
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		Any						,  _A	:		List[str]						,  _A	:		int						,  _A	:		List[Any]    )						->				int:
  				__magic_name__ :					str  			=  ResNetBackbone(config=_A    )
  				model.to(_A    )
  				model.eval()
  				__magic_name__ :					List[str]  			=  model(_A    )
  
  				# verify feature maps
  				self.parent.assertEqual(len(result.feature_maps    )						,  len(config.out_features    )    )
  				self.parent.assertListEqual(list(result.feature_maps[0].shape    )						,  [self.batch_size, self.hidden_sizes[1], 4, 4]    )
  
  				# verify channels
  				self.parent.assertEqual(len(model.channels    )						,  len(config.out_features    )    )
  				self.parent.assertListEqual(model.channels						,  config.hidden_sizes[1:]    )
  
  				# verify backbone works with out_features=None
  				__magic_name__ :					Union[str, Any]  			=  None
  				__magic_name__ :					Optional[int]  			=  ResNetBackbone(config=_A    )
  				model.to(_A    )
  				model.eval()
  				__magic_name__ :					str  			=  model(_A    )
  
  				# verify feature maps
  				self.parent.assertEqual(len(result.feature_maps    )						,  1    )
  				self.parent.assertListEqual(list(result.feature_maps[0].shape    )						,  [self.batch_size, self.hidden_sizes[-1], 1, 1]    )
  
  				# verify channels
  				self.parent.assertEqual(len(model.channels    )						,  1    )
  				self.parent.assertListEqual(model.channels						,  [config.hidden_sizes[-1]]    )
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		Any    )						->				Any:
  				__magic_name__ :					Dict  			=  self.prepare_config_and_inputs()
  				__magic_name__ :					Tuple  			=  config_and_inputs
  				__magic_name__ :					Union[str, Any]  			=  {'pixel_values': pixel_values}
  				return config, inputs_dict
  
  
  
  
  
  
  
  @require_torch
  class _lowerCamelCase (		lowercase__	,  lowercase__	,  unittest.TestCase							):
  
  
  
  		'''simple docstring'''
  
  
  
  
  
  
  
  		A_			:    Tuple   					=       (
  		    (
  		        ResNetModel,
  		        ResNetForImageClassification,
  		        ResNetBackbone,
  		    )
  		    if is_torch_available()
  		    else ()
  		)
  		A_			:    Any   					=       (
  		    {"""feature-extraction""": ResNetModel, """image-classification""": ResNetForImageClassification}
  		    if is_torch_available()
  		    else {}
  		)
  
  		A_			:    int   					=       True
  		A_			:    Dict   					=       False
  		A_			:    Tuple   					=       False
  		A_			:    str   					=       False
  		A_			:    List[Any]   					=       False
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		Tuple    )						->				Union[str, Any]:
  				__magic_name__ :					Optional[Any]  			=  ResNetModelTester(self    )
  				__magic_name__ :					Any  			=  ConfigTester(self						,  config_class=_A						,  has_text_modality=_A    )
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		Optional[int]    )						->				str:
  				self.create_and_test_config_common_properties()
  				self.config_tester.create_and_test_config_to_json_string()
  				self.config_tester.create_and_test_config_to_json_file()
  				self.config_tester.create_and_test_config_from_and_save_pretrained()
  				self.config_tester.create_and_test_config_with_num_labels()
  				self.config_tester.check_config_can_be_init_without_params()
  				self.config_tester.check_config_arguments_init()
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		Optional[Any]    )						->				Tuple:
  				return
  
  
  
  
  
  
  
  		@unittest.skip(reason='ResNet does not use inputs_embeds'    )
  		def      __lowerCAmelCase	(      self	:		int    )						->				Tuple:
  				pass
  
  
  
  
  
  
  
  		@unittest.skip(reason='ResNet does not support input and output embeddings'    )
  		def      __lowerCAmelCase	(      self	:		Dict    )						->				Optional[Any]:
  				pass
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		Optional[Any]    )						->				Optional[int]:
  				__magic_name__ :					Optional[int]  			=  self.model_tester.prepare_config_and_inputs_for_common()
  
  				for model_class in self.all_model_classes:
  						__magic_name__ :					Optional[Any]  			=  model_class(_A    )
  						__magic_name__ :					List[str]  			=  inspect.signature(model.forward    )
  						# signature.parameters is an OrderedDict => so arg_names order is deterministic
  						__magic_name__ :					Dict  			=  [*signature.parameters.keys()]
  
  						__magic_name__ :					int  			=  ['pixel_values']
  						self.assertListEqual(arg_names[:1]						,  _A    )
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		str    )						->				int:
  				__magic_name__ :					Union[str, Any]  			=  self.model_tester.prepare_config_and_inputs()
  				self.model_tester.create_and_check_model(*_A    )
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		str    )						->				Dict:
  				__magic_name__ :					List[Any]  			=  self.model_tester.prepare_config_and_inputs()
  				self.model_tester.create_and_check_backbone(*_A    )
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		Dict    )						->				int:
  				__magic_name__ :					List[Any]  			=  self.model_tester.prepare_config_and_inputs_for_common()
  
  				for model_class in self.all_model_classes:
  						__magic_name__ :					List[Any]  			=  model_class(config=_A    )
  						for name, module in model.named_modules():
  								if isinstance(_A						,  (nn.BatchNormad, nn.GroupNorm)    ):
  										self.assertTrue(
  										    torch.all(module.weight == 1    )						,  msg=F'Parameter {name} of model {model_class} seems not properly initialized'						,  )
  										self.assertTrue(
  										    torch.all(module.bias == 0    )						,  msg=F'Parameter {name} of model {model_class} seems not properly initialized'						,  )
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		Any    )						->				List[str]:
  				def check_hidden_states_output(_A	:		Optional[Any]						,  _A	:		Optional[Any]						,  _A	:		str    ):
  						__magic_name__ :					str  			=  model_class(_A    )
  						model.to(_A    )
  						model.eval()
  
  						with torch.no_grad():
  								__magic_name__ :					Any  			=  model(**self._prepare_for_class(_A						,  _A    )    )
  
  						__magic_name__ :					int  			=  outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states
  
  						__magic_name__ :					Optional[Any]  			=  self.model_tester.num_stages
  						self.assertEqual(len(_A    )						,  expected_num_stages + 1    )
  
  						# ResNet's feature maps are of shape (batch_size, num_channels, height, width)
  						self.assertListEqual(
  						    list(hidden_states[0].shape[-2:]    )						,  [self.model_tester.image_size // 4, self.model_tester.image_size // 4]						,  )
  
  				__magic_name__ :					Dict  			=  self.model_tester.prepare_config_and_inputs_for_common()
  				__magic_name__ :					int  			=  ['basic', 'bottleneck']
  				for model_class in self.all_model_classes:
  						for layer_type in layers_type:
  								__magic_name__ :					Any  			=  layer_type
  								__magic_name__ :					str  			=  True
  								check_hidden_states_output(_A						,  _A						,  _A    )
  
  								# check that output_hidden_states also work using config
  								del inputs_dict["output_hidden_states"]
  								__magic_name__ :					Dict  			=  True
  
  								check_hidden_states_output(_A						,  _A						,  _A    )
  
  
  
  
  
  
  
  		@unittest.skip(reason='ResNet does not use feedforward chunking'    )
  		def      __lowerCAmelCase	(      self	:		List[Any]    )						->				int:
  				pass
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		int    )						->				Tuple:
  				__magic_name__ :					List[str]  			=  self.model_tester.prepare_config_and_inputs()
  				self.model_tester.create_and_check_for_image_classification(*_A    )
  
  
  
  
  
  
  
  		@slow
  		def      __lowerCAmelCase	(      self	:		List[str]    )						->				Tuple:
  				for model_name in RESNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
  						__magic_name__ :					Optional[Any]  			=  ResNetModel.from_pretrained(_A    )
  						self.assertIsNotNone(_A    )
  
  
  
  
  
  
  
  def lowerCamelCase    (    ):
  
  
  
  
  
  		"""simple docstring"""
  
  
  
  
  
  
  
  		__magic_name__ :					List[str]  			=  Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'	)
  		return image
  @require_torch
  @require_vision
  class _lowerCamelCase (		unittest.TestCase							):
  
  
  
  		'''simple docstring'''
  
  
  
  
  
  
  
  		@cached_property
  		def      __lowerCAmelCase	(      self	:		Tuple    )						->				List[Any]:
  				return (
  				    AutoImageProcessor.from_pretrained(RESNET_PRETRAINED_MODEL_ARCHIVE_LIST[0]    )
  				    if is_vision_available()
  				    else None
  				)
  
  
  
  
  
  
  
  		@slow
  		def      __lowerCAmelCase	(      self	:		Any    )						->				Tuple:
  				__magic_name__ :					Any  			=  ResNetForImageClassification.from_pretrained(RESNET_PRETRAINED_MODEL_ARCHIVE_LIST[0]    ).to(_A    )
  
  				__magic_name__ :					int  			=  self.default_image_processor
  				__magic_name__ :					str  			=  prepare_img()
  				__magic_name__ :					Optional[Any]  			=  image_processor(images=_A						,  return_tensors='pt'    ).to(_A    )
  
  				# forward pass
  				with torch.no_grad():
  						__magic_name__ :					Tuple  			=  model(**_A    )
  
  				# verify the logits
  				__magic_name__ :					Optional[Any]  			=  torch.Size((1, 1000)    )
  				self.assertEqual(outputs.logits.shape						,  _A    )
  
  				__magic_name__ :					int  			=  torch.tensor([-11.1069, -9.7877, -8.3777]    ).to(_A    )
  
  				self.assertTrue(torch.allclose(outputs.logits[0, :3]						,  _A						,  atol=1E-4    )    )
  
  
  
  
  
  
  
  @require_torch
  class _lowerCamelCase (		lowercase__	,  unittest.TestCase							):
  
  
  
  		'''simple docstring'''
  
  
  
  
  
  
  
  		A_			:    Tuple   					=       (ResNetBackbone,) if is_torch_available() else ()
  		A_			:    int   					=       False
  		A_			:    Optional[Any]   					=       ResNetConfig
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		Union[str, Any]    )						->				str:
  				__magic_name__ :					Optional[Any]  			=  ResNetModelTester(self    )
style_context: 
  
  
  '''simple docstring'''
  
  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 _lowerCamelCase (		unittest.TestCase							):
  
  
  
  		'''simple docstring'''
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		Any						,  _A	:		Optional[Any]    )						->				Optional[int]:
  			__magic_name__ :					Optional[int]  			=  list(tokenizer_class.max_model_input_sizes.keys()    )
  			for model_name in sa_models[:1]:
  				__magic_name__ :					List[str]  			=  tokenizer_class.from_pretrained(_A    )
  				self.assertIsNotNone(_A    )
  				self.assertIsInstance(_A						,  _A    )
  				self.assertIsInstance(_A						,  _A    )
  
  				for special_tok in tokenizer.all_special_tokens:
  					self.assertIsInstance(_A						,  _A    )
  					__magic_name__ :					Optional[Any]  			=  tokenizer.convert_tokens_to_ids(_A    )
  					self.assertIsInstance(_A						,  _A    )
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		Optional[Any]						,  _A	:		BatchEncoding						,  _A	:		Optional[Callable] = None    )						->				Tuple:
  			__magic_name__ :					Union[str, Any]  			=  pickle.dumps(_A    )
  			self.assertIsNotNone(_A    )
  
  			__magic_name__ :					Optional[Any]  			=  pickle.loads(_A    )
  
  			# 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(_A						,  _A    )    )
  				else:
  					self.assertEqual(_A						,  _A    )
  
  
  
  
  
  
  
  		@slow
  		def      __lowerCAmelCase	(      self	:		Dict    )						->				Optional[Any]:
  			self.check_tokenizer_from_pretrained(_A    )
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		str    )						->				List[Any]:
  			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]    )						->				Optional[int]:
  			import numpy as np
  
  			__magic_name__ :					Dict  			=  BertTokenizer.from_pretrained('bert-base-cased'    )
  			__magic_name__ :					str  			=  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	:		List[Any]    )						->				List[str]:
  			import tensorflow as tf
  
  			def tf_array_equals(_A	:		str						,  _A	:		Union[str, Any]    ):
  				return tf.reduce_all(tf.equal(_A						,  _A    )    )
  
  			__magic_name__ :					str  			=  BertTokenizer.from_pretrained('bert-base-cased'    )
  			__magic_name__ :					Optional[Any]  			=  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    )						,  _A    )
  
  			with self.subTest('BatchEncoding (Rust, return_tensors=TENSORFLOW)'    ):
  				self.assert_dump_and_restore(
  				    tokenizer_r('Small example to encode'						,  return_tensors=TensorType.TENSORFLOW    )						,  _A    )
  
  
  
  
  
  
  
  		@require_torch
  		@require_tokenizers
  		def      __lowerCAmelCase	(      self	:		Any    )						->				List[str]:
  			import torch
  
  			__magic_name__ :					Union[str, Any]  			=  BertTokenizer.from_pretrained('bert-base-cased'    )
  			__magic_name__ :					Optional[int]  			=  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	:		List[str]    )						->				Dict:
  			__magic_name__ :					Optional[int]  			=  BertTokenizer.from_pretrained('bert-base-cased'    )
  			__magic_name__ :					Dict  			=  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]    )						->				Optional[int]:
  			__magic_name__ :					Optional[int]  			=  BertTokenizerFast.from_pretrained('bert-base-cased'    )
  			__magic_name__ :					Tuple  			=  tokenizer_r(['Test', '\xad', 'test']						,  is_split_into_words=_A    )
  
  			self.assertEqual(encoded.word_to_tokens(0    )						,  TokenSpan(start=1						,  end=2    )    )
  			self.assertEqual(encoded.word_to_tokens(1    )						,  _A    )
  			self.assertEqual(encoded.word_to_tokens(2    )						,  TokenSpan(start=2						,  end=3    )    )
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		Optional[int]    )						->				Optional[Any]:
  			__magic_name__ :					Any  			=  BatchEncoding({'inputs': [[1, 2, 3], [4, 5, 6]], 'labels': [0, 1]}    )
  			__magic_name__ :					Dict  			=  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:
  				__magic_name__ :					Any  			=  batch.convert_to_tensors(tensor_type='np'    )
  			self.assertFalse(len(cs.err    )						,  msg=F'should have no warning, but got {cs.err}'    )
  
  			__magic_name__ :					Optional[Any]  			=  BatchEncoding({'inputs': [1, 2, 3], 'labels': 0}    )
  			__magic_name__ :					List[Any]  			=  batch.convert_to_tensors(tensor_type='np'						,  prepend_batch_axis=_A    )
  			self.assertEqual(tensor_batch['inputs'].shape						,  (1, 3)    )
  			self.assertEqual(tensor_batch['labels'].shape						,  (1,)    )
  
  
  
  
  
  
  
  		@require_torch
  		def      __lowerCAmelCase	(      self	:		Union[str, Any]    )						->				Any:
  			__magic_name__ :					Optional[int]  			=  BatchEncoding({'inputs': [[1, 2, 3], [4, 5, 6]], 'labels': [0, 1]}    )
  			__magic_name__ :					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:
  				__magic_name__ :					Union[str, Any]  			=  batch.convert_to_tensors(tensor_type='pt'    )
  			self.assertFalse(len(cs.err    )						,  msg=F'should have no warning, but got {cs.err}'    )
  
  			__magic_name__ :					Any  			=  BatchEncoding({'inputs': [1, 2, 3], 'labels': 0}    )
  			__magic_name__ :					str  			=  batch.convert_to_tensors(tensor_type='pt'						,  prepend_batch_axis=_A    )
  			self.assertEqual(tensor_batch['inputs'].shape						,  (1, 3)    )
  			self.assertEqual(tensor_batch['labels'].shape						,  (1,)    )
  
  
  
  
  
  
  
  		@require_tf
  		def      __lowerCAmelCase	(      self	:		Optional[Any]    )						->				List[str]:
  			__magic_name__ :					str  			=  BatchEncoding({'inputs': [[1, 2, 3], [4, 5, 6]], 'labels': [0, 1]}    )
  			__magic_name__ :					List[str]  			=  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:
  				__magic_name__ :					Optional[int]  			=  batch.convert_to_tensors(tensor_type='tf'    )
  			self.assertFalse(len(cs.err    )						,  msg=F'should have no warning, but got {cs.err}'    )
  
  			__magic_name__ :					Union[str, Any]  			=  BatchEncoding({'inputs': [1, 2, 3], 'labels': 0}    )
  			__magic_name__ :					Union[str, Any]  			=  batch.convert_to_tensors(tensor_type='tf'						,  prepend_batch_axis=_A    )
  			self.assertEqual(tensor_batch['inputs'].shape						,  (1, 3)    )
  			self.assertEqual(tensor_batch['labels'].shape						,  (1,)    )
  
  
  
  
  
  
  
  		@require_flax
  		def      __lowerCAmelCase	(      self	:		str    )						->				Optional[Any]:
  			__magic_name__ :					List[Any]  			=  BatchEncoding({'inputs': [[1, 2, 3], [4, 5, 6]], 'labels': [0, 1]}    )
  			__magic_name__ :					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:
  				__magic_name__ :					Optional[Any]  			=  batch.convert_to_tensors(tensor_type='jax'    )
  			self.assertFalse(len(cs.err    )						,  msg=F'should have no warning, but got {cs.err}'    )
  
  			__magic_name__ :					str  			=  BatchEncoding({'inputs': [1, 2, 3], 'labels': 0}    )
  			__magic_name__ :					Dict  			=  batch.convert_to_tensors(tensor_type='jax'						,  prepend_batch_axis=_A    )
  			self.assertEqual(tensor_batch['inputs'].shape						,  (1, 3)    )
  			self.assertEqual(tensor_batch['labels'].shape						,  (1,)    )
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		str    )						->				int:
  			__magic_name__ :					int  			=  [{'input_ids': np.array([0, 1, 2]    )}, {'input_ids': np.array([0, 1, 2, 3]    )}]
  			__magic_name__ :					Dict  			=  BertTokenizer.from_pretrained('bert-base-cased'    )
  
  			__magic_name__ :					Optional[int]  			=  tokenizer.pad(_A						,  padding=_A    )
  			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]]    )
  			__magic_name__ :					Dict  			=  tokenizer.pad(_A						,  padding=_A						,  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	:		List[Any]    )						->				str:
  			import torch
  
  			__magic_name__ :					List[str]  			=  [{'input_ids': torch.tensor([0, 1, 2]    )}, {'input_ids': torch.tensor([0, 1, 2, 3]    )}]
  			__magic_name__ :					List[str]  			=  BertTokenizer.from_pretrained('bert-base-cased'    )
  
  			__magic_name__ :					List[Any]  			=  tokenizer.pad(_A						,  padding=_A    )
  			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]]    )
  			__magic_name__ :					Union[str, Any]  			=  tokenizer.pad(_A						,  padding=_A						,  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	:		Any    )						->				Optional[int]:
  			import tensorflow as tf
  
  			__magic_name__ :					Tuple  			=  [{'input_ids': tf.constant([0, 1, 2]    )}, {'input_ids': tf.constant([0, 1, 2, 3]    )}]
  			__magic_name__ :					Any  			=  BertTokenizer.from_pretrained('bert-base-cased'    )
  
  			__magic_name__ :					Any  			=  tokenizer.pad(_A						,  padding=_A    )
  			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]]    )
  			__magic_name__ :					Union[str, Any]  			=  tokenizer.pad(_A						,  padding=_A						,  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	:		Any    )						->				str:
  			__magic_name__ :					str  			=  Tokenizer(WordPiece(unk_token='[UNK]'    )    )
  			PreTrainedTokenizerFast(tokenizer_object=_A    )
  
  
  
  
  
  
  
  		@require_tokenizers
  		def      __lowerCAmelCase	(      self	:		Dict    )						->				Any:
  			__magic_name__ :					List[Any]  			=  Tokenizer(WordPiece(unk_token='[UNK]'    )    )
  			with tempfile.TemporaryDirectory() as tmpdirname:
  				bert_tokenizer.save(os.path.join(_A						,  'tokenizer.json'    )    )
  				PreTrainedTokenizerFast(tokenizer_file=os.path.join(_A						,  'tokenizer.json'    )    )