


import unittest

from transformers import MobileBertConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
			import torch

			from transformers import (
			    MODEL_FOR_PRETRAINING_MAPPING,
			    MobileBertForMaskedLM,
			    MobileBertForMultipleChoice,
			    MobileBertForNextSentencePrediction,
			    MobileBertForPreTraining,
			    MobileBertForQuestionAnswering,
			    MobileBertForSequenceClassification,
			    MobileBertForTokenClassification,
			    MobileBertModel,
			)







class lowerCAmelCase_		:

	'''simple docstring'''

	def __init__(			self	,   _UpperCAmelCase	,   _UpperCAmelCase=13	,   _UpperCAmelCase=7	,   _UpperCAmelCase=True	,   _UpperCAmelCase=True	,   _UpperCAmelCase=True	,   _UpperCAmelCase=True	,   _UpperCAmelCase=99	,   _UpperCAmelCase=64	,   _UpperCAmelCase=32	,   _UpperCAmelCase=5	,   _UpperCAmelCase=4	,   _UpperCAmelCase=37	,   _UpperCAmelCase="gelu"	,   _UpperCAmelCase=0.1	,   _UpperCAmelCase=0.1	,   _UpperCAmelCase=5_12	,   _UpperCAmelCase=16	,   _UpperCAmelCase=2	,   _UpperCAmelCase=0.02	,   _UpperCAmelCase=3	,   _UpperCAmelCase=4	,   _UpperCAmelCase=None	,   ):
							snake_case_ =   parent
							snake_case_ =   batch_size
							snake_case_ =   seq_length
							snake_case_ =   is_training
							snake_case_ =   use_input_mask
							snake_case_ =   use_token_type_ids
							snake_case_ =   use_labels
							snake_case_ =   vocab_size
							snake_case_ =   hidden_size
							snake_case_ =   embedding_size
							snake_case_ =   num_hidden_layers
							snake_case_ =   num_attention_heads
							snake_case_ =   intermediate_size
							snake_case_ =   hidden_act
							snake_case_ =   hidden_dropout_prob
							snake_case_ =   attention_probs_dropout_prob
							snake_case_ =   max_position_embeddings
							snake_case_ =   type_vocab_size
							snake_case_ =   type_sequence_label_size
							snake_case_ =   initializer_range
							snake_case_ =   num_labels
							snake_case_ =   num_choices
							snake_case_ =   scope



	def 		UpperCamelCase__  (			self      ):
							snake_case_ =   ids_tensor([self.batch_size, self.seq_length]	,   self.vocab_size      )

							snake_case_ =   None
							if self.use_input_mask:
													snake_case_ =   random_attention_mask([self.batch_size, self.seq_length]      )

							snake_case_ =   None
							if self.use_token_type_ids:
													snake_case_ =   ids_tensor([self.batch_size, self.seq_length]	,   self.type_vocab_size      )

							snake_case_ =   None
							snake_case_ =   None
							snake_case_ =   None
							if self.use_labels:
													snake_case_ =   ids_tensor([self.batch_size]	,   self.type_sequence_label_size      )
													snake_case_ =   ids_tensor([self.batch_size, self.seq_length]	,   self.num_labels      )
													snake_case_ =   ids_tensor([self.batch_size]	,   self.num_choices      )

							snake_case_ =   self.get_config()

							return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels



	def 		UpperCamelCase__  (			self      ):
							return MobileBertConfig(
							    vocab_size=self.vocab_size	,   hidden_size=self.hidden_size	,   num_hidden_layers=self.num_hidden_layers	,   num_attention_heads=self.num_attention_heads	,   intermediate_size=self.intermediate_size	,   embedding_size=self.embedding_size	,   hidden_act=self.hidden_act	,   hidden_dropout_prob=self.hidden_dropout_prob	,   attention_probs_dropout_prob=self.attention_probs_dropout_prob	,   max_position_embeddings=self.max_position_embeddings	,   type_vocab_size=self.type_vocab_size	,   is_decoder=_UpperCAmelCase	,   initializer_range=self.initializer_range	,   )



	def 		UpperCamelCase__  (			self	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase      ):
							snake_case_ =   MobileBertModel(config=_UpperCAmelCase      )
							model.to(_UpperCAmelCase      )
							model.eval()
							snake_case_ =   model(_UpperCAmelCase	,   attention_mask=_UpperCAmelCase	,   token_type_ids=_UpperCAmelCase      )
							snake_case_ =   model(_UpperCAmelCase	,   token_type_ids=_UpperCAmelCase      )
							snake_case_ =   model(_UpperCAmelCase      )

							self.parent.assertEqual(result.last_hidden_state.shape	,   (self.batch_size, self.seq_length, self.hidden_size)      )
							self.parent.assertEqual(result.pooler_output.shape	,   (self.batch_size, self.hidden_size)      )



	def 		UpperCamelCase__  (			self	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase      ):
							snake_case_ =   MobileBertForMaskedLM(config=_UpperCAmelCase      )
							model.to(_UpperCAmelCase      )
							model.eval()
							snake_case_ =   model(_UpperCAmelCase	,   attention_mask=_UpperCAmelCase	,   token_type_ids=_UpperCAmelCase	,   labels=_UpperCAmelCase      )
							self.parent.assertEqual(result.logits.shape	,   (self.batch_size, self.seq_length, self.vocab_size)      )



	def 		UpperCamelCase__  (			self	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase      ):
							snake_case_ =   MobileBertForNextSentencePrediction(config=_UpperCAmelCase      )
							model.to(_UpperCAmelCase      )
							model.eval()
							snake_case_ =   model(
							    _UpperCAmelCase	,   attention_mask=_UpperCAmelCase	,   token_type_ids=_UpperCAmelCase	,   labels=_UpperCAmelCase	,   )
							self.parent.assertEqual(result.logits.shape	,   (self.batch_size, 2)      )



	def 		UpperCamelCase__  (			self	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase      ):
							snake_case_ =   MobileBertForPreTraining(config=_UpperCAmelCase      )
							model.to(_UpperCAmelCase      )
							model.eval()
							snake_case_ =   model(
							    _UpperCAmelCase	,   attention_mask=_UpperCAmelCase	,   token_type_ids=_UpperCAmelCase	,   labels=_UpperCAmelCase	,   next_sentence_label=_UpperCAmelCase	,   )
							self.parent.assertEqual(result.prediction_logits.shape	,   (self.batch_size, self.seq_length, self.vocab_size)      )
							self.parent.assertEqual(result.seq_relationship_logits.shape	,   (self.batch_size, 2)      )



	def 		UpperCamelCase__  (			self	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase      ):
							snake_case_ =   MobileBertForQuestionAnswering(config=_UpperCAmelCase      )
							model.to(_UpperCAmelCase      )
							model.eval()
							snake_case_ =   model(
							    _UpperCAmelCase	,   attention_mask=_UpperCAmelCase	,   token_type_ids=_UpperCAmelCase	,   start_positions=_UpperCAmelCase	,   end_positions=_UpperCAmelCase	,   )
							self.parent.assertEqual(result.start_logits.shape	,   (self.batch_size, self.seq_length)      )
							self.parent.assertEqual(result.end_logits.shape	,   (self.batch_size, self.seq_length)      )



	def 		UpperCamelCase__  (			self	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase      ):
							snake_case_ =   self.num_labels
							snake_case_ =   MobileBertForSequenceClassification(_UpperCAmelCase      )
							model.to(_UpperCAmelCase      )
							model.eval()
							snake_case_ =   model(_UpperCAmelCase	,   attention_mask=_UpperCAmelCase	,   token_type_ids=_UpperCAmelCase	,   labels=_UpperCAmelCase      )
							self.parent.assertEqual(result.logits.shape	,   (self.batch_size, self.num_labels)      )



	def 		UpperCamelCase__  (			self	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase      ):
							snake_case_ =   self.num_labels
							snake_case_ =   MobileBertForTokenClassification(config=_UpperCAmelCase      )
							model.to(_UpperCAmelCase      )
							model.eval()
							snake_case_ =   model(_UpperCAmelCase	,   attention_mask=_UpperCAmelCase	,   token_type_ids=_UpperCAmelCase	,   labels=_UpperCAmelCase      )
							self.parent.assertEqual(result.logits.shape	,   (self.batch_size, self.seq_length, self.num_labels)      )



	def 		UpperCamelCase__  (			self	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase      ):
							snake_case_ =   self.num_choices
							snake_case_ =   MobileBertForMultipleChoice(config=_UpperCAmelCase      )
							model.to(_UpperCAmelCase      )
							model.eval()
							snake_case_ =   input_ids.unsqueeze(1      ).expand(-1	,   self.num_choices	,   -1      ).contiguous()
							snake_case_ =   token_type_ids.unsqueeze(1      ).expand(-1	,   self.num_choices	,   -1      ).contiguous()
							snake_case_ =   input_mask.unsqueeze(1      ).expand(-1	,   self.num_choices	,   -1      ).contiguous()
							snake_case_ =   model(
							    _UpperCAmelCase	,   attention_mask=_UpperCAmelCase	,   token_type_ids=_UpperCAmelCase	,   labels=_UpperCAmelCase	,   )
							self.parent.assertEqual(result.logits.shape	,   (self.batch_size, self.num_choices)      )





	def 		UpperCamelCase__  (			self      ):
							snake_case_ =   self.prepare_config_and_inputs()
							(
							    (
							    snake_case_					
							) ,					(
							    snake_case_					
							) ,					(
							    snake_case_					
							) ,					(
							    snake_case_					
							) ,					(
							    snake_case_					
							) ,					(
							    snake_case_					
							) ,					(
							    snake_case_					
							) ,										
							) =   config_and_inputs
							snake_case_ =   {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
							return config, inputs_dict







@require_torch
class lowerCAmelCase_		(				lowerCamelCase__      ,		lowerCamelCase__      ,		unittest.TestCase ):

	'''simple docstring'''

	__snake_case				=						(
	    (
	        MobileBertModel,
	        MobileBertForMaskedLM,
	        MobileBertForMultipleChoice,
	        MobileBertForNextSentencePrediction,
	        MobileBertForPreTraining,
	        MobileBertForQuestionAnswering,
	        MobileBertForSequenceClassification,
	        MobileBertForTokenClassification,
	    )
	    if is_torch_available()
	    else ()
	)
	__snake_case				=						(
	    {
	        "feature-extraction": MobileBertModel,
	        "fill-mask": MobileBertForMaskedLM,
	        "question-answering": MobileBertForQuestionAnswering,
	        "text-classification": MobileBertForSequenceClassification,
	        "token-classification": MobileBertForTokenClassification,
	        "zero-shot": MobileBertForSequenceClassification,
	    }
	    if is_torch_available()
	    else {}
	)
	__snake_case				=						True



	def 		UpperCamelCase__  (			self	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase=False      ):
							snake_case_ =   super()._prepare_for_class(_UpperCAmelCase	,   _UpperCAmelCase	,   return_labels=_UpperCAmelCase      )

							if return_labels:
													if model_class in get_values(_UpperCAmelCase      ):
																			snake_case_ =   torch.zeros(
																			    (self.model_tester.batch_size, self.model_tester.seq_length)	,   dtype=torch.long	,   device=_UpperCAmelCase      )
																			snake_case_ =   torch.zeros(
																			    self.model_tester.batch_size	,   dtype=torch.long	,   device=_UpperCAmelCase      )
							return inputs_dict



	def 		UpperCamelCase__  (			self      ):
							snake_case_ =   MobileBertModelTester(self      )
							snake_case_ =   ConfigTester(self	,   config_class=_UpperCAmelCase	,   hidden_size=37      )



	def 		UpperCamelCase__  (			self      ):
							self.config_tester.run_common_tests()



	def 		UpperCamelCase__  (			self      ):
							snake_case_ =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mobilebert_model(*_UpperCAmelCase      )



	def 		UpperCamelCase__  (			self      ):
							snake_case_ =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mobilebert_for_masked_lm(*_UpperCAmelCase      )



	def 		UpperCamelCase__  (			self      ):
							snake_case_ =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mobilebert_for_multiple_choice(*_UpperCAmelCase      )



	def 		UpperCamelCase__  (			self      ):
							snake_case_ =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mobilebert_for_next_sequence_prediction(*_UpperCAmelCase      )



	def 		UpperCamelCase__  (			self      ):
							snake_case_ =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mobilebert_for_pretraining(*_UpperCAmelCase      )



	def 		UpperCamelCase__  (			self      ):
							snake_case_ =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mobilebert_for_question_answering(*_UpperCAmelCase      )



	def 		UpperCamelCase__  (			self      ):
							snake_case_ =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mobilebert_for_sequence_classification(*_UpperCAmelCase      )





	def 		UpperCamelCase__  (			self      ):
							snake_case_ =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mobilebert_for_token_classification(*_UpperCAmelCase      )






def  __lowerCAmelCase					(SCREAMING_SNAKE_CASE      )->						List[Any]:




						"""simple docstring"""

						return torch.tensor(
						    SCREAMING_SNAKE_CASE      ,      dtype=torch.long      ,      device=SCREAMING_SNAKE_CASE      ,      )


UpperCAmelCase    =					1e-3







@require_torch
@require_sentencepiece
@require_tokenizers
class lowerCAmelCase_		(				unittest.TestCase ):

	'''simple docstring'''

	@slow
	def 		UpperCamelCase__  (			self      ):
							snake_case_ =   MobileBertModel.from_pretrained('''google/mobilebert-uncased'''      ).to(_UpperCAmelCase      )
							snake_case_ =   _long_tensor([[1_01, 71_10, 10_05, 10_56, 20_23, 1_13_33, 1_74_13, 10_29, 1_02]]      )
							with torch.no_grad():
													snake_case_ =   model(_UpperCAmelCase      )[0]
							snake_case_ =   torch.Size((1, 9, 5_12)      )
							self.assertEqual(output.shape	,   _UpperCAmelCase      )
							snake_case_ =   torch.tensor(
							    [
							        [
							            [-2.4736526E07, 8.2691656E04, 1.6521838E05],
							            [-5.7541704E-01, 3.9056022E00, 4.4011507E00],
							            [2.6047359E00, 1.5677652E00, -1.7324188E-01],
							        ]
							    ]	,   device=_UpperCAmelCase	,   )

							# MobileBERT results range from 10e0 to 10e8. Even a 0.0000001% difference with a value of 10e8 results in a
							# ~1 difference, it's therefore not a good idea to measure using addition.
							# Here, we instead divide the expected result with the result in order to obtain ~1. We then check that the
							# result is held between bounds: 1 - TOLERANCE < expected_result / result < 1 + TOLERANCE
							snake_case_ =   torch.all((expected_slice / output[..., :3, :3]) >= 1 - TOLERANCE      )
							snake_case_ =   torch.all((expected_slice / output[..., :3, :3]) <= 1 + TOLERANCE      )

							self.assertTrue(lower_bound and upper_bound      )



# Lint as: python3
import sys
from collections.abc import Mapping
from typing import TYPE_CHECKING, Dict, Optional

import numpy as np
import pyarrow as pa

from .. import config
from ..utils.logging import get_logger
from ..utils.py_utils import map_nested
from .formatting import TensorFormatter


if TYPE_CHECKING:
   import jax
   import jaxlib

UpperCAmelCase    =					get_logger()

UpperCAmelCase    =					None







class lowerCAmelCase_		(				TensorFormatter[Mapping, "jax.Array", Mapping] ):

 '''simple docstring'''

 def __init__(			self	,   _UpperCAmelCase=None	,   _UpperCAmelCase=None	,   **_UpperCAmelCase      ):
       super().__init__(features=_UpperCAmelCase      )
       import jax
       from jaxlib.xla_client import Device

       if isinstance(_UpperCAmelCase	,   _UpperCAmelCase      ):
             raise ValueError(
                 F'''Expected {device} to be a `str` not {type(_UpperCAmelCase      )}, as `jaxlib.xla_extension.Device` '''
                 '''is not serializable neither with `pickle` nor with `dill`. Instead you can surround '''
                 '''the device with `str()` to get its string identifier that will be internally mapped '''
                 '''to the actual `jaxlib.xla_extension.Device`.'''      )
       snake_case_ =   device if isinstance(_UpperCAmelCase	,   _UpperCAmelCase      ) else str(jax.devices()[0]      )
       # using global variable since `jaxlib.xla_extension.Device` is not serializable neither
       # with `pickle` nor with `dill`, so we need to use a global variable instead
       global DEVICE_MAPPING
       if DEVICE_MAPPING is None:
             snake_case_ =   self._map_devices_to_str()
       if self.device not in list(DEVICE_MAPPING.keys()      ):
             logger.warning(
                 F'''Device with string identifier {self.device} not listed among the available '''
                 F'''devices: {list(DEVICE_MAPPING.keys()      )}, so falling back to the default '''
                 F'''device: {str(jax.devices()[0]      )}.'''      )
             snake_case_ =   str(jax.devices()[0]      )
       snake_case_ =   jnp_array_kwargs



 @staticmethod
 def 		UpperCamelCase__  (			):
       import jax

       return {str(_UpperCAmelCase      ): device for device in jax.devices()}



 def 		UpperCamelCase__  (			self	,   _UpperCAmelCase      ):
       import jax
       import jax.numpy as jnp

       if isinstance(_UpperCAmelCase	,   _UpperCAmelCase      ) and column:
             if all(
                 isinstance(_UpperCAmelCase	,   jax.Array      ) and x.shape == column[0].shape and x.dtype == column[0].dtype for x in column      ):
                   return jnp.stack(_UpperCAmelCase	,   axis=0      )
       return column



 def 		UpperCamelCase__  (			self	,   _UpperCAmelCase      ):
       import jax
       import jax.numpy as jnp

       if isinstance(_UpperCAmelCase	,   (str, bytes, type(_UpperCAmelCase      ))      ):
             return value
       elif isinstance(_UpperCAmelCase	,   (np.character, np.ndarray)      ) and np.issubdtype(value.dtype	,   np.character      ):
             return value.tolist()

       snake_case_ =   {}

       if isinstance(_UpperCAmelCase	,   (np.number, np.ndarray)      ) and np.issubdtype(value.dtype	,   np.integer      ):
             # the default int precision depends on the jax config
             # see https://jax.readthedocs.io/en/latest/notebooks/Common_Gotchas_in_JAX.html#double-64bit-precision
             if jax.config.jax_enable_xaa:
                   snake_case_ =   {'''dtype''': jnp.intaa}
             else:
                   snake_case_ =   {'''dtype''': jnp.intaa}
       elif isinstance(_UpperCAmelCase	,   (np.number, np.ndarray)      ) and np.issubdtype(value.dtype	,   np.floating      ):
             snake_case_ =   {'''dtype''': jnp.floataa}
       elif config.PIL_AVAILABLE and "PIL" in sys.modules:
             import PIL.Image

             if isinstance(_UpperCAmelCase	,   PIL.Image.Image      ):
                   snake_case_ =   np.asarray(_UpperCAmelCase      )

        # using global variable since `jaxlib.xla_extension.Device` is not serializable neither
        # with `pickle` nor with `dill`, so we need to use a global variable instead
       global DEVICE_MAPPING
       if DEVICE_MAPPING is None:
             snake_case_ =   self._map_devices_to_str()

       with jax.default_device(DEVICE_MAPPING[self.device]      ):
             # calling jnp.array on a np.ndarray does copy the data
             # see https://github.com/google/jax/issues/4486
             return jnp.array(_UpperCAmelCase	,   **{**default_dtype, **self.jnp_array_kwargs}      )



 def 		UpperCamelCase__  (			self	,   _UpperCAmelCase      ):
       import jax

       # support for torch, tf, jax etc.
       if config.TORCH_AVAILABLE and "torch" in sys.modules:
             import torch

             if isinstance(_UpperCAmelCase	,   torch.Tensor      ):
                   return self._tensorize(data_struct.detach().cpu().numpy()[()]      )
       if hasattr(_UpperCAmelCase	,   '''__array__'''      ) and not isinstance(_UpperCAmelCase	,   jax.Array      ):
             snake_case_ =   data_struct.__array__()
       # support for nested types like struct of list of struct
       if isinstance(_UpperCAmelCase	,   np.ndarray      ):
             if data_struct.dtype == object:  # jax arrays cannot be instantied from an array of objects
                   return self._consolidate([self.recursive_tensorize(_UpperCAmelCase      ) for substruct in data_struct]      )
       elif isinstance(_UpperCAmelCase	,   (list, tuple)      ):
             return self._consolidate([self.recursive_tensorize(_UpperCAmelCase      ) for substruct in data_struct]      )
       return self._tensorize(_UpperCAmelCase      )



 def 		UpperCamelCase__  (			self	,   _UpperCAmelCase      ):
       return map_nested(self._recursive_tensorize	,   _UpperCAmelCase	,   map_list=_UpperCAmelCase      )



 def 		UpperCamelCase__  (			self	,   _UpperCAmelCase      ):
       snake_case_ =   self.numpy_arrow_extractor().extract_row(_UpperCAmelCase      )
       snake_case_ =   self.python_features_decoder.decode_row(_UpperCAmelCase      )
       return self.recursive_tensorize(_UpperCAmelCase      )



 def 		UpperCamelCase__  (			self	,   _UpperCAmelCase      ):
       snake_case_ =   self.numpy_arrow_extractor().extract_column(_UpperCAmelCase      )
       snake_case_ =   self.python_features_decoder.decode_column(_UpperCAmelCase	,   pa_table.column_names[0]      )
       snake_case_ =   self.recursive_tensorize(_UpperCAmelCase      )
       snake_case_ =   self._consolidate(_UpperCAmelCase      )
       return column





 def 		UpperCamelCase__  (			self	,   _UpperCAmelCase      ):
       snake_case_ =   self.numpy_arrow_extractor().extract_batch(_UpperCAmelCase      )
       snake_case_ =   self.python_features_decoder.decode_batch(_UpperCAmelCase      )
       snake_case_ =   self.recursive_tensorize(_UpperCAmelCase      )
       for column_name in batch:
             snake_case_ =   self._consolidate(batch[column_name]      )
       return batch