'''simple docstring'''


from __future__ import annotations

import inspect
import unittest

from transformers import MobileViTConfig
from transformers.file_utils import is_tf_available, is_vision_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
 import numpy as np
 import tensorflow as tf

 from transformers import TFMobileViTForImageClassification, TFMobileViTForSemanticSegmentation, TFMobileViTModel
 from transformers.models.mobilevit.modeling_tf_mobilevit import TF_MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
 from PIL import Image

 from transformers import MobileViTImageProcessor






class      __SCREAMING_SNAKE_CASE						(       lowerCamelCase_       ):







  '''simple docstring'''






  def _UpperCamelCase     ( self						):




       '''simple docstring'''

       UpperCAmelCase_							:   Optional[Any]   =      self.config_class(**self.inputs_dict						)
       self.parent.assertTrue(hasattr(_UpperCamelCase      ,		'hidden_sizes'						)						)
       self.parent.assertTrue(hasattr(_UpperCamelCase      ,		'neck_hidden_sizes'						)						)
       self.parent.assertTrue(hasattr(_UpperCamelCase      ,		'num_attention_heads'						)						)







class      __SCREAMING_SNAKE_CASE						:







  '''simple docstring'''






  def __init__( self      ,		snake_case_      ,		snake_case_=1_3      ,		snake_case_=3_2      ,		snake_case_=2      ,		snake_case_=3      ,		snake_case_=6_4_0      ,		snake_case_=4      ,		snake_case_="silu"      ,		snake_case_=3      ,		snake_case_=3_2      ,		snake_case_=0.1      ,		snake_case_=0.1      ,		snake_case_=0.1      ,		snake_case_=0.02      ,		snake_case_=True      ,		snake_case_=True      ,		snake_case_=1_0      ,		snake_case_=None      ,		):




       '''simple docstring'''

       UpperCAmelCase_							:   Any   =      parent
       UpperCAmelCase_							:   Optional[Any]   =      batch_size
       UpperCAmelCase_							:   str   =      image_size
       UpperCAmelCase_							:   List[str]   =      patch_size
       UpperCAmelCase_							:   Union[str, Any]   =      num_channels
       UpperCAmelCase_							:   str   =      last_hidden_size
       UpperCAmelCase_							:   List[Any]   =      num_attention_heads
       UpperCAmelCase_							:   Optional[int]   =      hidden_act
       UpperCAmelCase_							:   Any   =      conv_kernel_size
       UpperCAmelCase_							:   List[Any]   =      output_stride
       UpperCAmelCase_							:   Optional[Any]   =      hidden_dropout_prob
       UpperCAmelCase_							:   List[Any]   =      attention_probs_dropout_prob
       UpperCAmelCase_							:   Union[str, Any]   =      classifier_dropout_prob
       UpperCAmelCase_							:   Dict   =      use_labels
       UpperCAmelCase_							:   Optional[Any]   =      is_training
       UpperCAmelCase_							:   List[str]   =      num_labels
       UpperCAmelCase_							:   str   =      initializer_range
       UpperCAmelCase_							:   List[Any]   =      scope


  def _UpperCamelCase     ( self						):




       '''simple docstring'''

       UpperCAmelCase_							:   List[str]   =      floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]						)

       UpperCAmelCase_							:   str   =      None
       UpperCAmelCase_							:   Optional[int]   =      None
       if self.use_labels:
            UpperCAmelCase_							:   str   =      ids_tensor([self.batch_size]      ,		self.num_labels						)
            UpperCAmelCase_							:   str   =      ids_tensor([self.batch_size, self.image_size, self.image_size]      ,		self.num_labels						)

       UpperCAmelCase_							:   Union[str, Any]   =      self.get_config()

       return config, pixel_values, labels, pixel_labels


  def _UpperCamelCase     ( self						):




       '''simple docstring'''

       return MobileViTConfig(
           image_size=self.image_size      ,		patch_size=self.patch_size      ,		num_channels=self.num_channels      ,		num_attention_heads=self.num_attention_heads      ,		hidden_act=self.hidden_act      ,		conv_kernel_size=self.conv_kernel_size      ,		output_stride=self.output_stride      ,		hidden_dropout_prob=self.hidden_dropout_prob      ,		attention_probs_dropout_prob=self.attention_probs_dropout_prob      ,		classifier_dropout_prob=self.classifier_dropout_prob      ,		initializer_range=self.initializer_range      ,		)


  def _UpperCamelCase     ( self      ,		snake_case_      ,		snake_case_      ,		snake_case_      ,		snake_case_						):




       '''simple docstring'''

       UpperCAmelCase_							:   Union[str, Any]   =      TFMobileViTModel(config=_UpperCamelCase						)
       UpperCAmelCase_							:   Optional[Any]   =      model(_UpperCamelCase      ,		training=_UpperCamelCase						)
       UpperCAmelCase_							:   Any   =      self.image_size // self.output_stride
       self.parent.assertEqual(
           result.last_hidden_state.shape      ,		(self.batch_size, self.last_hidden_size, expected_height, expected_width)						)


  def _UpperCamelCase     ( self      ,		snake_case_      ,		snake_case_      ,		snake_case_      ,		snake_case_						):




       '''simple docstring'''

       UpperCAmelCase_							:   Optional[Any]   =      self.num_labels
       UpperCAmelCase_							:   List[str]   =      TFMobileViTForImageClassification(_UpperCamelCase						)
       UpperCAmelCase_							:   Optional[Any]   =      model(_UpperCamelCase      ,		labels=_UpperCamelCase      ,		training=_UpperCamelCase						)
       self.parent.assertEqual(result.logits.shape      ,		(self.batch_size, self.num_labels)						)


  def _UpperCamelCase     ( self      ,		snake_case_      ,		snake_case_      ,		snake_case_      ,		snake_case_						):




       '''simple docstring'''

       UpperCAmelCase_							:   List[Any]   =      self.num_labels
       UpperCAmelCase_							:   List[str]   =      TFMobileViTForSemanticSegmentation(_UpperCamelCase						)
       UpperCAmelCase_							:   Optional[Any]   =      self.image_size // self.output_stride

       UpperCAmelCase_							:   Any   =      model(_UpperCamelCase      ,		training=_UpperCamelCase						)
       self.parent.assertEqual(
           result.logits.shape      ,		(self.batch_size, self.num_labels, expected_height, expected_width)						)

       UpperCAmelCase_							:   Optional[int]   =      model(_UpperCamelCase      ,		labels=_UpperCamelCase      ,		training=_UpperCamelCase						)
       self.parent.assertEqual(
           result.logits.shape      ,		(self.batch_size, self.num_labels, expected_height, expected_width)						)






  def _UpperCamelCase     ( self						):




       '''simple docstring'''

       UpperCAmelCase_							:   Dict   =      self.prepare_config_and_inputs()
       UpperCAmelCase_   ,			UpperCAmelCase_   ,			UpperCAmelCase_   ,			UpperCAmelCase_							:   Union[str, Any]   =      config_and_inputs
       UpperCAmelCase_							:   Dict   =      {'pixel_values': pixel_values}
       return config, inputs_dict







@require_tf
class      __SCREAMING_SNAKE_CASE						(       lowerCamelCase_						,	lowerCamelCase_						,	unittest.TestCase       ):







  '''simple docstring'''






  lowerCamelCase_		:List[Any]						    =		(
      (TFMobileViTModel, TFMobileViTForImageClassification, TFMobileViTForSemanticSegmentation)
      if is_tf_available()
      else ()
  )
  lowerCamelCase_		:List[Any]						    =		(
      {"""feature-extraction""": TFMobileViTModel, """image-classification""": TFMobileViTForImageClassification}
      if is_tf_available()
      else {}
  )

  lowerCamelCase_		:List[Any]						    =		False
  lowerCamelCase_		:Tuple						    =		False
  lowerCamelCase_		:Dict						    =		False
  lowerCamelCase_		:List[str]						    =		False
  lowerCamelCase_		:List[Any]						    =		False


  def _UpperCamelCase     ( self						):




       '''simple docstring'''

       UpperCAmelCase_							:   Dict   =      TFMobileViTModelTester(self						)
       UpperCAmelCase_							:   Any   =      TFMobileViTConfigTester(self      ,		config_class=_UpperCamelCase      ,		has_text_modality=_UpperCamelCase						)


  def _UpperCamelCase     ( self						):




       '''simple docstring'''

       self.config_tester.run_common_tests()


  @unittest.skip(reason='MobileViT does not use inputs_embeds'						)
  def _UpperCamelCase     ( self						):




       '''simple docstring'''

       pass


  @unittest.skip(reason='MobileViT does not support input and output embeddings'						)
  def _UpperCamelCase     ( self						):




       '''simple docstring'''

       pass


  @unittest.skip(reason='MobileViT does not output attentions'						)
  def _UpperCamelCase     ( self						):




       '''simple docstring'''

       pass


  def _UpperCamelCase     ( self						):




       '''simple docstring'''

       UpperCAmelCase_   ,			UpperCAmelCase_							:   List[Any]   =      self.model_tester.prepare_config_and_inputs_for_common()

       for model_class in self.all_model_classes:
            UpperCAmelCase_							:   Optional[Any]   =      model_class(_UpperCamelCase						)
            UpperCAmelCase_							:   Optional[Any]   =      inspect.signature(model.call						)
            # signature.parameters is an OrderedDict => so arg_names order is deterministic
            UpperCAmelCase_							:   List[Any]   =      [*signature.parameters.keys()]

            UpperCAmelCase_							:   Any   =      ['pixel_values']
            self.assertListEqual(arg_names[:1]      ,		_UpperCamelCase						)


  def _UpperCamelCase     ( self						):




       '''simple docstring'''

       UpperCAmelCase_							:   Any   =      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*_UpperCamelCase						)


  def _UpperCamelCase     ( self						):




       '''simple docstring'''

       def check_hidden_states_output(snake_case_      ,		snake_case_      ,		snake_case_						):
            UpperCAmelCase_							:   List[str]   =      model_class(_UpperCamelCase						)

            UpperCAmelCase_							:   Tuple   =      model(**self._prepare_for_class(_UpperCamelCase      ,		_UpperCamelCase						)						)

            UpperCAmelCase_							:   Union[str, Any]   =      outputs.hidden_states

            UpperCAmelCase_							:   Any   =      5
            self.assertEqual(len(_UpperCamelCase						)      ,		_UpperCamelCase						)

            # MobileViT's feature maps are of shape (batch_size, num_channels, height, width)
            # with the width and height being successively divided by 2.
            UpperCAmelCase_							:   Optional[Any]   =      2
            for i in range(len(_UpperCamelCase						)						):
                 self.assertListEqual(
                     list(hidden_states[i].shape[-2:]						)      ,		[self.model_tester.image_size // divisor, self.model_tester.image_size // divisor]      ,		)
                 divisor *= 2

            self.assertEqual(self.model_tester.output_stride      ,		divisor // 2						)

       UpperCAmelCase_   ,			UpperCAmelCase_							:   Dict   =      self.model_tester.prepare_config_and_inputs_for_common()

       for model_class in self.all_model_classes:
            UpperCAmelCase_							:   Optional[Any]   =      True
            check_hidden_states_output(_UpperCamelCase      ,		_UpperCamelCase      ,		_UpperCamelCase						)

            # check that output_hidden_states also work using config
            del inputs_dict["output_hidden_states"]
            UpperCAmelCase_							:   int   =      True

            check_hidden_states_output(_UpperCamelCase      ,		_UpperCamelCase      ,		_UpperCamelCase						)


  def _UpperCamelCase     ( self						):




       '''simple docstring'''

       UpperCAmelCase_							:   List[str]   =      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_image_classification(*_UpperCamelCase						)


  def _UpperCamelCase     ( self						):




       '''simple docstring'''

       UpperCAmelCase_							:   Union[str, Any]   =      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_semantic_segmentation(*_UpperCamelCase						)


  @unittest.skipIf(
      not is_tf_available() or len(tf.config.list_physical_devices('GPU'						)						) == 0      ,		reason='TF does not support backprop for grouped convolutions on CPU.'      ,		)
  def _UpperCamelCase     ( self						):




       '''simple docstring'''

       super().test_dataset_conversion()


  def _UpperCamelCase     ( self      ,		snake_case_      ,		snake_case_      ,		snake_case_=2E-1      ,		snake_case_=2E-1						):




       '''simple docstring'''

       self.assertTrue(np.allclose(_UpperCamelCase      ,		_UpperCamelCase      ,		atol=_UpperCamelCase      ,		rtol=_UpperCamelCase						)						)


  @unittest.skipIf(
      not is_tf_available() or len(tf.config.list_physical_devices('GPU'						)						) == 0      ,		reason='TF does not support backprop for grouped convolutions on CPU.'      ,		)
  @slow
  def _UpperCamelCase     ( self						):




       '''simple docstring'''

       UpperCAmelCase_   ,			UpperCAmelCase_							:   str   =      self.model_tester.prepare_config_and_inputs_for_common()

       for model_class in self.all_model_classes:
            # Since `TFMobileViTModel` cannot operate with the default `fit()` method.
            if model_class.__name__ != "TFMobileViTModel":
                 UpperCAmelCase_							:   int   =      model_class(_UpperCamelCase						)
                 if getattr(_UpperCamelCase      ,		'hf_compute_loss'      ,		_UpperCamelCase						):
                      super().test_keras_fit()


  def _UpperCamelCase     ( self						):




       '''simple docstring'''

       UpperCAmelCase_   ,			UpperCAmelCase_							:   int   =      self.model_tester.prepare_config_and_inputs_for_common()
       for model_class in self.all_model_classes:
            # set an ignore index to correctly test the masked loss used in
            # `TFMobileViTForSemanticSegmentation`.
            if model_class.__name__ != "TFMobileViTForSemanticSegmentation":
                 UpperCAmelCase_							:   Tuple   =      5

            UpperCAmelCase_							:   Any   =      model_class(_UpperCamelCase						)
            if getattr(_UpperCamelCase      ,		'hf_compute_loss'      ,		_UpperCamelCase						):
                 # The number of elements in the loss should be the same as the number of elements in the label
                 UpperCAmelCase_							:   int   =      self._prepare_for_class(inputs_dict.copy()      ,		_UpperCamelCase      ,		return_labels=_UpperCamelCase						)
                 UpperCAmelCase_							:   List[str]   =      prepared_for_class[
                     sorted(prepared_for_class.keys() - inputs_dict.keys()      ,		reverse=_UpperCamelCase						)[0]
                 ]
                 UpperCAmelCase_							:   List[str]   =      added_label.shape.as_list()[:1]

                 # Test that model correctly compute the loss with kwargs
                 UpperCAmelCase_							:   Dict   =      self._prepare_for_class(inputs_dict.copy()      ,		_UpperCamelCase      ,		return_labels=_UpperCamelCase						)
                 UpperCAmelCase_							:   Tuple   =      {'input_ids', 'pixel_values', 'input_features'}
                 UpperCAmelCase_							:   List[str]   =      possible_input_names.intersection(set(_UpperCamelCase						)						).pop()
                 UpperCAmelCase_							:   Union[str, Any]   =      prepared_for_class.pop(_UpperCamelCase						)

                 UpperCAmelCase_							:   int   =      model(_UpperCamelCase      ,		**_UpperCamelCase						)[0]
                 self.assertTrue(loss.shape.as_list() == expected_loss_size or loss.shape.as_list() == [1]						)

                 # Test that model correctly compute the loss when we mask some positions
                 UpperCAmelCase_							:   Any   =      self._prepare_for_class(inputs_dict.copy()      ,		_UpperCamelCase      ,		return_labels=_UpperCamelCase						)
                 UpperCAmelCase_							:   Optional[Any]   =      {'input_ids', 'pixel_values', 'input_features'}
                 UpperCAmelCase_							:   Union[str, Any]   =      possible_input_names.intersection(set(_UpperCamelCase						)						).pop()
                 UpperCAmelCase_							:   Union[str, Any]   =      prepared_for_class.pop(_UpperCamelCase						)
                 if "labels" in prepared_for_class:
                      UpperCAmelCase_							:   str   =      prepared_for_class['labels'].numpy()
                      if len(labels.shape						) > 1 and labels.shape[1] != 1:
                           # labels[0] = -100
                           UpperCAmelCase_							:   int   =      tf.convert_to_tensor(_UpperCamelCase						)
                           UpperCAmelCase_							:   List[Any]   =      model(_UpperCamelCase      ,		**_UpperCamelCase						)[0]
                           self.assertTrue(loss.shape.as_list() == expected_loss_size or loss.shape.as_list() == [1]						)
                           self.assertTrue(not np.any(np.isnan(loss.numpy()						)						)						)

                # Test that model correctly compute the loss with a dict
                 UpperCAmelCase_							:   Optional[int]   =      self._prepare_for_class(inputs_dict.copy()      ,		_UpperCamelCase      ,		return_labels=_UpperCamelCase						)
                 UpperCAmelCase_							:   str   =      model(_UpperCamelCase						)[0]
                 self.assertTrue(loss.shape.as_list() == expected_loss_size or loss.shape.as_list() == [1]						)

                 # Test that model correctly compute the loss with a tuple
                 UpperCAmelCase_							:   List[str]   =      self._prepare_for_class(inputs_dict.copy()      ,		_UpperCamelCase      ,		return_labels=_UpperCamelCase						)

                 # Get keys that were added with the _prepare_for_class function
                 UpperCAmelCase_							:   List[Any]   =      prepared_for_class.keys() - inputs_dict.keys()
                 UpperCAmelCase_							:   Union[str, Any]   =      inspect.signature(model.call						).parameters
                 UpperCAmelCase_							:   Any   =      list(signature.keys()						)

                 # Create a dictionary holding the location of the tensors in the tuple
                 UpperCAmelCase_							:   Dict   =      {0: input_name}
                 for label_key in label_keys:
                      UpperCAmelCase_							:   Tuple   =      signature_names.index(_UpperCamelCase						)
                      UpperCAmelCase_							:   Union[str, Any]   =      label_key
                 UpperCAmelCase_							:   List[str]   =      sorted(tuple_index_mapping.items()						)
                 # Initialize a list with their default values, update the values and convert to a tuple
                 UpperCAmelCase_							:   List[str]   =      []

                 for name in signature_names:
                      if name != "kwargs":
                           list_input.append(signature[name].default						)

                 for index, value in sorted_tuple_index_mapping:
                      UpperCAmelCase_							:   Optional[int]   =      prepared_for_class[value]

                 UpperCAmelCase_							:   List[str]   =      tuple(_UpperCamelCase						)

                 # Send to model
                 UpperCAmelCase_							:   Dict   =      model(tuple_input[:-1]						)[0]

                 self.assertTrue(loss.shape.as_list() == expected_loss_size or loss.shape.as_list() == [1]						)






  @slow
  def _UpperCamelCase     ( self						):




       '''simple docstring'''

       for model_name in TF_MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
            UpperCAmelCase_							:   Union[str, Any]   =      TFMobileViTModel.from_pretrained(_UpperCamelCase						)
            self.assertIsNotNone(_UpperCamelCase						)







def 					_lowerCamelCase    (      ):



     """simple docstring"""





     UpperCAmelCase_							:   Any   =      Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'   )
     return image






@require_tf
class      __SCREAMING_SNAKE_CASE						(       unittest.TestCase       ):







  '''simple docstring'''






  @slow
  def _UpperCamelCase     ( self						):




       '''simple docstring'''

       UpperCAmelCase_							:   Union[str, Any]   =      TFMobileViTForImageClassification.from_pretrained('apple/mobilevit-xx-small'						)

       UpperCAmelCase_							:   List[str]   =      MobileViTImageProcessor.from_pretrained('apple/mobilevit-xx-small'						)
       UpperCAmelCase_							:   str   =      prepare_img()
       UpperCAmelCase_							:   str   =      image_processor(images=_UpperCamelCase      ,		return_tensors='tf'						)

       # forward pass
       UpperCAmelCase_							:   Optional[Any]   =      model(**_UpperCamelCase      ,		training=_UpperCamelCase						)

       # verify the logits
       UpperCAmelCase_							:   Any   =      tf.TensorShape((1, 1_0_0_0)						)
       self.assertEqual(outputs.logits.shape      ,		_UpperCamelCase						)

       UpperCAmelCase_							:   Any   =      tf.constant([-1.93_64, -1.23_27, -0.46_53]						)

       tf.debugging.assert_near(outputs.logits[0, :3]      ,		_UpperCamelCase      ,		atol=1E-4      ,		rtol=1E-04						)






  @slow
  def _UpperCamelCase     ( self						):




       '''simple docstring'''

       UpperCAmelCase_							:   List[Any]   =      TFMobileViTForSemanticSegmentation.from_pretrained('apple/deeplabv3-mobilevit-xx-small'						)

       UpperCAmelCase_							:   Optional[Any]   =      MobileViTImageProcessor.from_pretrained('apple/deeplabv3-mobilevit-xx-small'						)

       UpperCAmelCase_							:   Optional[int]   =      prepare_img()
       UpperCAmelCase_							:   int   =      image_processor(images=_UpperCamelCase      ,		return_tensors='tf'						)

       # forward pass
       UpperCAmelCase_							:   Dict   =      model(inputs.pixel_values      ,		training=_UpperCamelCase						)
       UpperCAmelCase_							:   Tuple   =      outputs.logits

       # verify the logits
       UpperCAmelCase_							:   Union[str, Any]   =      tf.TensorShape((1, 2_1, 3_2, 3_2)						)
       self.assertEqual(logits.shape      ,		_UpperCamelCase						)

       UpperCAmelCase_							:   Optional[Any]   =      tf.constant(
           [
               [[6.97_13, 6.97_86, 7.24_22], [7.28_93, 7.28_25, 7.44_46], [7.65_80, 7.87_97, 7.94_20]],
               [[-1_0.6_8_6_9, -1_0.3_2_5_0, -1_0.3_4_7_1], [-1_0.4_2_2_8, -9.98_68, -9.71_32], [-1_1.0_4_0_5, -1_1.0_2_2_1, -1_0.7_3_1_8]],
               [[-3.30_89, -2.85_39, -2.67_40], [-3.27_06, -2.56_21, -2.51_08], [-3.25_34, -2.66_15, -2.66_51]],
           ]						)

       tf.debugging.assert_near(logits[0, :3, :3, :3]      ,		_UpperCamelCase      ,		rtol=1E-4      ,		atol=1E-4						)







import json
import os
from dataclasses import dataclass

import numpy as np
import pyarrow as pa

import datasets
from utils import get_duration


_lowerCamelCase    :      int	 =						10_00_00_00_00_00
_lowerCamelCase    :      Union[str, Any]	 =						1_00_00

_lowerCamelCase ,  _lowerCamelCase    :      List[str]	 =						os.path.split(__file__)
_lowerCamelCase    :      Any	 =						os.path.join(RESULTS_BASEPATH, '''results''', RESULTS_FILENAME.replace('''.py''', '''.json'''))





def 		__lowerCamelCase							(UpperCAmelCase__   :							int					,       UpperCAmelCase__   :							int     ):
					SCREAMING_SNAKE_CASE				=				pa.Table.from_pydict({"col": [0] * chunk_size}     )
					SCREAMING_SNAKE_CASE				=				pa.concat_tables([table] * (num_examples // chunk_size)     )
					return datasets.Dataset(UpperCAmelCase__					,       fingerprint="table_100B"     )


@dataclass
class   lowercase			:
							lowercase__  :				int
							lowercase__  :				int
							lowercase__  :				int
							lowercase__  :				int




							def 		__snake_case(  self      :    Tuple					)    -> Dict:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE				=				np.random.default_rng(self.seed					)
												SCREAMING_SNAKE_CASE				=				rng.integers(low=self.low		,							high=self.high		,							size=self.size					).tolist()




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



												'''simple docstring'''

												return iter(self._sampled_values					)





							def __len__(  self      :    Any					)    -> int:



												'''simple docstring'''

												return self.size





@get_duration
def 		__lowerCamelCase							(UpperCAmelCase__   :							datasets.Dataset     ):
					SCREAMING_SNAKE_CASE				=				dataset[0]





@get_duration
def 		__lowerCamelCase							(UpperCAmelCase__   :							datasets.Dataset     ):
					SCREAMING_SNAKE_CASE				=				dataset[-1]





@get_duration
def 		__lowerCamelCase							(UpperCAmelCase__   :							datasets.Dataset     ):
					SCREAMING_SNAKE_CASE				=				dataset[range(len(UpperCAmelCase__     ) // 2					,       len(UpperCAmelCase__     ) // 2 + 1_0_2_4     )]





@get_duration
def 		__lowerCamelCase							(UpperCAmelCase__   :							datasets.Dataset     ):
					SCREAMING_SNAKE_CASE				=				dataset[RandIter(0					,       len(UpperCAmelCase__     )					,       1_0_2_4					,       seed=4_2     )]





def 		__lowerCamelCase							():
					SCREAMING_SNAKE_CASE				=				{"num examples": SPEED_TEST_N_EXAMPLES}
					SCREAMING_SNAKE_CASE				=				(get_first_row, get_last_row, get_batch_of_aaaa_rows, get_batch_of_aaaa_random_rows)
					print("generating dataset"     )
					SCREAMING_SNAKE_CASE				=				generate_100B_dataset(num_examples=UpperCAmelCase__					,       chunk_size=UpperCAmelCase__     )
					print("Functions"     )
					for func in functions:
										print(func.__name__     )
										SCREAMING_SNAKE_CASE				=				func(UpperCAmelCase__     )

					with open(UpperCAmelCase__					,       "wb"     ) as f:
										f.write(json.dumps(UpperCAmelCase__     ).encode("utf-8"     )     )


if __name__ == "__main__":  # useful to run the profiler
							benchmark_table_100B()




