

import unittest

from transformers import ElectraConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, slow, torch_device

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


if is_torch_available():
  import torch

  from transformers import (
      MODEL_FOR_PRETRAINING_MAPPING,
      ElectraForCausalLM,
      ElectraForMaskedLM,
      ElectraForMultipleChoice,
      ElectraForPreTraining,
      ElectraForQuestionAnswering,
      ElectraForSequenceClassification,
      ElectraForTokenClassification,
      ElectraModel,
  )
  from transformers.models.electra.modeling_electra import ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST






class 							A_			:


     def __init__(							self      :		List[str]      ,  UpperCAmelCase      :		Optional[Any]      ,  UpperCAmelCase      :		int=1_3      ,  UpperCAmelCase      :		str=7      ,  UpperCAmelCase      :		List[Any]=True      ,  UpperCAmelCase      :		Tuple=True      ,  UpperCAmelCase      :		int=True      ,  UpperCAmelCase      :		List[Any]=True      ,  UpperCAmelCase      :		Any=9_9      ,  UpperCAmelCase      :		List[Any]=3_2      ,  UpperCAmelCase      :		str=5      ,  UpperCAmelCase      :		int=4      ,  UpperCAmelCase      :		Optional[int]=3_7      ,  UpperCAmelCase      :		int="gelu"      ,  UpperCAmelCase      :		str=0.1      ,  UpperCAmelCase      :		Optional[int]=0.1      ,  UpperCAmelCase      :		Optional[int]=5_1_2      ,  UpperCAmelCase      :		List[str]=1_6      ,  UpperCAmelCase      :		Union[str, Any]=2      ,  UpperCAmelCase      :		Optional[Any]=0.02      ,  UpperCAmelCase      :		List[Any]=3      ,  UpperCAmelCase      :		str=4      ,  UpperCAmelCase      :		Tuple=None      ,  )							->     Dict:
      __lowerCAmelCase:       Optional[Any]            =				parent
      __lowerCAmelCase:       Tuple            =				batch_size
      __lowerCAmelCase:       str            =				seq_length
      __lowerCAmelCase:       Any            =				is_training
      __lowerCAmelCase:       List[str]            =				use_input_mask
      __lowerCAmelCase:       Union[str, Any]            =				use_token_type_ids
      __lowerCAmelCase:       Dict            =				use_labels
      __lowerCAmelCase:       Any            =				vocab_size
      __lowerCAmelCase:       Optional[int]            =				hidden_size
      __lowerCAmelCase:       str            =				num_hidden_layers
      __lowerCAmelCase:       Tuple            =				num_attention_heads
      __lowerCAmelCase:       Union[str, Any]            =				intermediate_size
      __lowerCAmelCase:       str            =				hidden_act
      __lowerCAmelCase:       List[Any]            =				hidden_dropout_prob
      __lowerCAmelCase:       str            =				attention_probs_dropout_prob
      __lowerCAmelCase:       Optional[Any]            =				max_position_embeddings
      __lowerCAmelCase:       Tuple            =				type_vocab_size
      __lowerCAmelCase:       Any            =				type_sequence_label_size
      __lowerCAmelCase:       str            =				initializer_range
      __lowerCAmelCase:       Optional[int]            =				num_labels
      __lowerCAmelCase:       int            =				num_choices
      __lowerCAmelCase:       Optional[Any]            =				scope


     def   UpperCAmelCase  (							self      :		int )							->     List[Any]:
      __lowerCAmelCase:       Tuple            =				ids_tensor([self.batch_size, self.seq_length]      ,  self.vocab_size )

      __lowerCAmelCase:       str            =				None
      if self.use_input_mask:
       __lowerCAmelCase:       Optional[int]            =				random_attention_mask([self.batch_size, self.seq_length] )

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

      __lowerCAmelCase:       Tuple            =				None
      __lowerCAmelCase:       List[str]            =				None
      __lowerCAmelCase:       Tuple            =				None
      if self.use_labels:
       __lowerCAmelCase:       int            =				ids_tensor([self.batch_size]      ,  self.type_sequence_label_size )
       __lowerCAmelCase:       Optional[Any]            =				ids_tensor([self.batch_size, self.seq_length]      ,  self.num_labels )
       __lowerCAmelCase:       Any            =				ids_tensor([self.batch_size]      ,  self.num_choices )
       __lowerCAmelCase:       Optional[int]            =				ids_tensor([self.batch_size, self.seq_length]      ,  1 )

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

      return (
          config,
          input_ids,
          token_type_ids,
          input_mask,
          sequence_labels,
          token_labels,
          choice_labels,
          fake_token_labels,
      )


     def   UpperCAmelCase  (							self      :		Union[str, Any] )							->     Optional[Any]:
      return ElectraConfig(
          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      ,  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      :		Optional[int] )							->     Any:
      (
          __lowerCAmelCase							
      ):       List[str]            =				self.prepare_config_and_inputs()

      __lowerCAmelCase:       List[str]            =				True
      __lowerCAmelCase:       int            =				floats_tensor([self.batch_size, self.seq_length, self.hidden_size] )
      __lowerCAmelCase:       Any            =				ids_tensor([self.batch_size, self.seq_length]      ,  vocab_size=2 )

      return (
          config,
          input_ids,
          token_type_ids,
          input_mask,
          sequence_labels,
          token_labels,
          choice_labels,
          encoder_hidden_states,
          encoder_attention_mask,
      )


     def   UpperCAmelCase  (							self      :		str      ,  UpperCAmelCase      :		Any      ,  UpperCAmelCase      :		Any      ,  UpperCAmelCase      :		Any      ,  UpperCAmelCase      :		List[str]      ,  UpperCAmelCase      :		Dict      ,  UpperCAmelCase      :		List[Any]      ,  UpperCAmelCase      :		Tuple      ,  UpperCAmelCase      :		Dict      ,  )							->     Optional[int]:
      __lowerCAmelCase:       Optional[int]            =				ElectraModel(config=UpperCAmelCase )
      model.to(UpperCAmelCase )
      model.eval()
      __lowerCAmelCase:       List[str]            =				model(UpperCAmelCase      ,  attention_mask=UpperCAmelCase      ,  token_type_ids=UpperCAmelCase )
      __lowerCAmelCase:       Optional[int]            =				model(UpperCAmelCase      ,  token_type_ids=UpperCAmelCase )
      __lowerCAmelCase:       Tuple            =				model(UpperCAmelCase )
      self.parent.assertEqual(result.last_hidden_state.shape      ,  (self.batch_size, self.seq_length, self.hidden_size) )


     def   UpperCAmelCase  (							self      :		List[str]      ,  UpperCAmelCase      :		List[str]      ,  UpperCAmelCase      :		Optional[int]      ,  UpperCAmelCase      :		str      ,  UpperCAmelCase      :		Union[str, Any]      ,  UpperCAmelCase      :		int      ,  UpperCAmelCase      :		Dict      ,  UpperCAmelCase      :		Tuple      ,  UpperCAmelCase      :		Optional[int]      ,  UpperCAmelCase      :		Optional[Any]      ,  )							->     List[Any]:
      __lowerCAmelCase:       Optional[int]            =				True
      __lowerCAmelCase:       int            =				ElectraModel(UpperCAmelCase )
      model.to(UpperCAmelCase )
      model.eval()
      __lowerCAmelCase:       Dict            =				model(
          UpperCAmelCase      ,  attention_mask=UpperCAmelCase      ,  token_type_ids=UpperCAmelCase      ,  encoder_hidden_states=UpperCAmelCase      ,  encoder_attention_mask=UpperCAmelCase      ,  )
      __lowerCAmelCase:       Optional[int]            =				model(
          UpperCAmelCase      ,  attention_mask=UpperCAmelCase      ,  token_type_ids=UpperCAmelCase      ,  encoder_hidden_states=UpperCAmelCase      ,  )
      __lowerCAmelCase:       Any            =				model(UpperCAmelCase      ,  attention_mask=UpperCAmelCase      ,  token_type_ids=UpperCAmelCase )
      self.parent.assertEqual(result.last_hidden_state.shape      ,  (self.batch_size, self.seq_length, self.hidden_size) )


     def   UpperCAmelCase  (							self      :		Optional[int]      ,  UpperCAmelCase      :		List[Any]      ,  UpperCAmelCase      :		str      ,  UpperCAmelCase      :		Any      ,  UpperCAmelCase      :		Dict      ,  UpperCAmelCase      :		Union[str, Any]      ,  UpperCAmelCase      :		Any      ,  UpperCAmelCase      :		str      ,  UpperCAmelCase      :		int      ,  )							->     Optional[int]:
      __lowerCAmelCase:       List[Any]            =				ElectraForMaskedLM(config=UpperCAmelCase )
      model.to(UpperCAmelCase )
      model.eval()
      __lowerCAmelCase:       Any            =				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      :		List[Any]      ,  UpperCAmelCase      :		List[Any]      ,  UpperCAmelCase      :		int      ,  UpperCAmelCase      :		List[Any]      ,  UpperCAmelCase      :		int      ,  UpperCAmelCase      :		List[Any]      ,  UpperCAmelCase      :		Optional[Any]      ,  UpperCAmelCase      :		Union[str, Any]      ,  UpperCAmelCase      :		int      ,  UpperCAmelCase      :		List[Any]      ,  )							->     Tuple:
      __lowerCAmelCase:       Dict            =				ElectraForCausalLM(config=UpperCAmelCase )
      model.to(UpperCAmelCase )
      model.eval()
      __lowerCAmelCase:       int            =				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      :		Union[str, Any]      ,  UpperCAmelCase      :		int      ,  UpperCAmelCase      :		Optional[int]      ,  UpperCAmelCase      :		int      ,  UpperCAmelCase      :		List[Any]      ,  UpperCAmelCase      :		Union[str, Any]      ,  UpperCAmelCase      :		int      ,  UpperCAmelCase      :		Any      ,  UpperCAmelCase      :		Dict      ,  )							->     Any:
      __lowerCAmelCase:       List[str]            =				self.num_labels
      __lowerCAmelCase:       List[str]            =				ElectraForTokenClassification(config=UpperCAmelCase )
      model.to(UpperCAmelCase )
      model.eval()
      __lowerCAmelCase:       Union[str, Any]            =				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      :		int      ,  UpperCAmelCase      :		List[Any]      ,  UpperCAmelCase      :		int      ,  UpperCAmelCase      :		Tuple      ,  UpperCAmelCase      :		int      ,  UpperCAmelCase      :		Union[str, Any]      ,  UpperCAmelCase      :		Tuple      ,  UpperCAmelCase      :		Tuple      ,  UpperCAmelCase      :		str      ,  )							->     Optional[int]:
      __lowerCAmelCase:       Tuple            =				self.num_labels
      __lowerCAmelCase:       Any            =				ElectraForPreTraining(config=UpperCAmelCase )
      model.to(UpperCAmelCase )
      model.eval()
      __lowerCAmelCase:       Optional[int]            =				model(UpperCAmelCase      ,  attention_mask=UpperCAmelCase      ,  token_type_ids=UpperCAmelCase      ,  labels=UpperCAmelCase )
      self.parent.assertEqual(result.logits.shape      ,  (self.batch_size, self.seq_length) )


     def   UpperCAmelCase  (							self      :		Union[str, Any]      ,  UpperCAmelCase      :		Dict      ,  UpperCAmelCase      :		int      ,  UpperCAmelCase      :		List[str]      ,  UpperCAmelCase      :		Any      ,  UpperCAmelCase      :		Dict      ,  UpperCAmelCase      :		Optional[int]      ,  UpperCAmelCase      :		int      ,  UpperCAmelCase      :		List[Any]      ,  )							->     Optional[Any]:
      __lowerCAmelCase:       Union[str, Any]            =				self.num_labels
      __lowerCAmelCase:       Union[str, Any]            =				ElectraForSequenceClassification(UpperCAmelCase )
      model.to(UpperCAmelCase )
      model.eval()
      __lowerCAmelCase:       List[Any]            =				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      :		Dict      ,  UpperCAmelCase      :		List[str]      ,  UpperCAmelCase      :		Optional[Any]      ,  UpperCAmelCase      :		int      ,  UpperCAmelCase      :		str      ,  UpperCAmelCase      :		str      ,  UpperCAmelCase      :		Union[str, Any]      ,  UpperCAmelCase      :		Union[str, Any]      ,  UpperCAmelCase      :		Tuple      ,  )							->     int:
      __lowerCAmelCase:       Tuple            =				ElectraForQuestionAnswering(config=UpperCAmelCase )
      model.to(UpperCAmelCase )
      model.eval()
      __lowerCAmelCase:       List[Any]            =				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      :		int      ,  UpperCAmelCase      :		Tuple      ,  UpperCAmelCase      :		Any      ,  UpperCAmelCase      :		Optional[Any]      ,  UpperCAmelCase      :		List[Any]      ,  UpperCAmelCase      :		int      ,  UpperCAmelCase      :		Optional[Any]      ,  UpperCAmelCase      :		Union[str, Any]      ,  UpperCAmelCase      :		int      ,  )							->     List[Any]:
      __lowerCAmelCase:       List[Any]            =				self.num_choices
      __lowerCAmelCase:       int            =				ElectraForMultipleChoice(config=UpperCAmelCase )
      model.to(UpperCAmelCase )
      model.eval()
      __lowerCAmelCase:       Optional[Any]            =				input_ids.unsqueeze(1 ).expand(-1      ,  self.num_choices      ,  -1 ).contiguous()
      __lowerCAmelCase:       List[Any]            =				token_type_ids.unsqueeze(1 ).expand(-1      ,  self.num_choices      ,  -1 ).contiguous()
      __lowerCAmelCase:       List[str]            =				input_mask.unsqueeze(1 ).expand(-1      ,  self.num_choices      ,  -1 ).contiguous()
      __lowerCAmelCase:       Optional[Any]            =				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      :		Union[str, Any] )							->     List[str]:
      __lowerCAmelCase:       List[str]            =				self.prepare_config_and_inputs()
      (
          __lowerCAmelCase							
      ):       Any            =				config_and_inputs
      __lowerCAmelCase:       int            =				{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
      return config, inputs_dict







@require_torch
class 							A_			(		snake_case__							,     snake_case__							,     unittest.TestCase ):
     _lowercase      :					Dict       =     (
         (
             ElectraModel,
             ElectraForPreTraining,
             ElectraForMaskedLM,
             ElectraForCausalLM,
             ElectraForMultipleChoice,
             ElectraForTokenClassification,
             ElectraForSequenceClassification,
             ElectraForQuestionAnswering,
         )
         if is_torch_available()
         else ()
     )
     _lowercase      :					Any       =     (
         {
             'feature-extraction': ElectraModel,
             'fill-mask': ElectraForMaskedLM,
             'question-answering': ElectraForQuestionAnswering,
             'text-classification': ElectraForSequenceClassification,
             'text-generation': ElectraForCausalLM,
             'token-classification': ElectraForTokenClassification,
             'zero-shot': ElectraForSequenceClassification,
         }
         if is_torch_available()
         else {}
     )
     _lowercase      :					Union[str, Any]       =     True


     def   UpperCAmelCase  (							self      :		Any      ,  UpperCAmelCase      :		List[str]      ,  UpperCAmelCase      :		int      ,  UpperCAmelCase      :		Optional[Any]=False )							->     Dict:
      __lowerCAmelCase:       Union[str, Any]            =				super()._prepare_for_class(UpperCAmelCase      ,  UpperCAmelCase      ,  return_labels=UpperCAmelCase )

      if return_labels:
       if model_class in get_values(UpperCAmelCase ):
        __lowerCAmelCase:       List[Any]            =				torch.zeros(
            (self.model_tester.batch_size, self.model_tester.seq_length)      ,  dtype=torch.long      ,  device=UpperCAmelCase )
      return inputs_dict


     def   UpperCAmelCase  (							self      :		Any )							->     Optional[Any]:
      __lowerCAmelCase:       str            =				ElectraModelTester(self )
      __lowerCAmelCase:       Optional[Any]            =				ConfigTester(self      ,  config_class=UpperCAmelCase      ,  hidden_size=3_7 )


     def   UpperCAmelCase  (							self      :		Optional[Any] )							->     str:
      self.config_tester.run_common_tests()


     def   UpperCAmelCase  (							self      :		Optional[int] )							->     List[Any]:
      __lowerCAmelCase:       Optional[Any]            =				self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_electra_model(*UpperCAmelCase )


     def   UpperCAmelCase  (							self      :		Tuple )							->     Union[str, Any]:
      __lowerCAmelCase:       str            =				self.model_tester.prepare_config_and_inputs_for_decoder()
      self.model_tester.create_and_check_electra_model_as_decoder(*UpperCAmelCase )


     def   UpperCAmelCase  (							self      :		Optional[Any] )							->     int:
      __lowerCAmelCase:       Tuple            =				self.model_tester.prepare_config_and_inputs()
      for type in ["absolute", "relative_key", "relative_key_query"]:
       __lowerCAmelCase:       List[Any]            =				type
       self.model_tester.create_and_check_electra_model(*UpperCAmelCase )


     def   UpperCAmelCase  (							self      :		List[Any] )							->     Tuple:
      __lowerCAmelCase:       int            =				self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_electra_for_masked_lm(*UpperCAmelCase )


     def   UpperCAmelCase  (							self      :		List[Any] )							->     Tuple:
      __lowerCAmelCase:       Dict            =				self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_electra_for_token_classification(*UpperCAmelCase )


     def   UpperCAmelCase  (							self      :		Any )							->     Any:
      __lowerCAmelCase:       Tuple            =				self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_electra_for_pretraining(*UpperCAmelCase )


     def   UpperCAmelCase  (							self      :		int )							->     List[Any]:
      __lowerCAmelCase:       Dict            =				self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_electra_for_sequence_classification(*UpperCAmelCase )


     def   UpperCAmelCase  (							self      :		Dict )							->     str:
      __lowerCAmelCase:       str            =				self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_electra_for_question_answering(*UpperCAmelCase )


     def   UpperCAmelCase  (							self      :		Tuple )							->     Dict:
      __lowerCAmelCase:       List[Any]            =				self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_electra_for_multiple_choice(*UpperCAmelCase )


     @slow
     def   UpperCAmelCase  (							self      :		Union[str, Any] )							->     str:
      for model_name in ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
       __lowerCAmelCase:       Union[str, Any]            =				ElectraModel.from_pretrained(UpperCAmelCase )
       self.assertIsNotNone(UpperCAmelCase )


     def   UpperCAmelCase  (							self      :		Dict )							->     str:
      __lowerCAmelCase:       Dict            =				self.model_tester.prepare_config_and_inputs_for_decoder()
      self.model_tester.create_and_check_electra_for_causal_lm(*UpperCAmelCase )







@require_torch
class 							A_			(		unittest.TestCase ):


     @slow
     def   UpperCAmelCase  (							self      :		Optional[Any] )							->     Any:
      __lowerCAmelCase:       Union[str, Any]            =				ElectraModel.from_pretrained('google/electra-small-discriminator' )
      __lowerCAmelCase:       Optional[Any]            =				torch.tensor([[0, 3_4_5, 2_3_2, 3_2_8, 7_4_0, 1_4_0, 1_6_9_5, 6_9, 6_0_7_8, 1_5_8_8, 2]] )
      __lowerCAmelCase:       List[Any]            =				torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]] )
      __lowerCAmelCase:       str            =				model(UpperCAmelCase      ,  attention_mask=UpperCAmelCase )[0]
      __lowerCAmelCase:       Dict            =				torch.Size((1, 1_1, 2_5_6) )
      self.assertEqual(output.shape      ,  UpperCAmelCase )
      __lowerCAmelCase:       Optional[int]            =				torch.tensor(
          [[[0.4471, 0.6821, -0.3265], [0.4627, 0.5255, -0.3668], [0.4532, 0.3313, -0.4344]]] )

      self.assertTrue(torch.allclose(output[:, 1:4, 1:4]      ,  UpperCAmelCase      ,  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


_a			=       1_0_0_0_0_0_0_0_0_0_0_0
_a			=       1_0_0_0_0

_a	,     _a			=       os.path.split(__file__)
_a			=       os.path.join(RESULTS_BASEPATH, '''results''', RESULTS_FILENAME.replace('''.py''', '''.json'''))







def _a			(	SCREAMING_SNAKE_CASE		:      int   , SCREAMING_SNAKE_CASE		:      int		)   ->   datasets.Dataset:

 """simple docstring"""






 __lowerCAmelCase:       List[Any]            =				pa.Table.from_pydict({'col': [0] * chunk_size}		)
 __lowerCAmelCase:       Dict            =				pa.concat_tables([table] * (num_examples // chunk_size)		)
 return datasets.Dataset(SCREAMING_SNAKE_CASE   , fingerprint='table_100B'		)






@dataclass
class 							A_			:
     _lowercase      :					int
     _lowercase      :					int
     _lowercase      :					int
     _lowercase      :					int


     def   UpperCAmelCase  (							self      :		Optional[Any] )							->     Dict:
      __lowerCAmelCase:       Dict            =				np.random.default_rng(self.seed )
      __lowerCAmelCase:       List[Any]            =				rng.integers(low=self.low      ,  high=self.high      ,  size=self.size ).tolist()


     def __iter__(							self      :		Any )							->     Optional[int]:
      return iter(self._sampled_values )


     def __len__(							self      :		Union[str, Any] )							->     Dict:
      return self.size







@get_duration
def _a			(	SCREAMING_SNAKE_CASE		:      datasets.Dataset		)   ->   List[str]:

 """simple docstring"""






 __lowerCAmelCase:       List[Any]            =				dataset[0]







@get_duration
def _a			(	SCREAMING_SNAKE_CASE		:      datasets.Dataset		)   ->   Dict:

 """simple docstring"""






 __lowerCAmelCase:       Dict            =				dataset[-1]







@get_duration
def _a			(	SCREAMING_SNAKE_CASE		:      datasets.Dataset		)   ->   Any:

 """simple docstring"""






 __lowerCAmelCase:       Union[str, Any]            =				dataset[range(len(SCREAMING_SNAKE_CASE		) // 2   , len(SCREAMING_SNAKE_CASE		) // 2 + 10_24		)]







@get_duration
def _a			(	SCREAMING_SNAKE_CASE		:      datasets.Dataset		)   ->   Optional[Any]:

 """simple docstring"""






 __lowerCAmelCase:       int            =				dataset[RandIter(0   , len(SCREAMING_SNAKE_CASE		)   , 10_24   , seed=42		)]







def _a			(	)   ->   Tuple:

 """simple docstring"""






 __lowerCAmelCase:       str            =				{'num examples': SPEED_TEST_N_EXAMPLES}
 __lowerCAmelCase:       Tuple            =				(get_first_row, get_last_row, get_batch_of_aaaa_rows, get_batch_of_aaaa_random_rows)
 print('generating dataset'		)
 __lowerCAmelCase:       str            =				generate_100B_dataset(num_examples=SCREAMING_SNAKE_CASE   , chunk_size=SCREAMING_SNAKE_CASE		)
 print('Functions'		)
 for func in functions:
  print(func.__name__		)
  __lowerCAmelCase:       Dict            =				func(SCREAMING_SNAKE_CASE		)

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


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





