





import json
import os
import tempfile

import datasets
from utils import generate_example_dataset, get_duration


UpperCAmelCase_     							= 5_0000
UpperCAmelCase_     							= 5000

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




@get_duration
def 		lowerCAmelCase_    (  __UpperCAmelCase:			datasets.Dataset		,   __UpperCAmelCase:			int      )      ->	Union[str, Any]:
    for i in range(__UpperCAmelCase      ):
        UpperCamelCase__							:				str          =      dataset[i]




@get_duration
def 		lowerCAmelCase_    (  __UpperCAmelCase:			datasets.Dataset		,   __UpperCAmelCase:			List[Any]		,   __UpperCAmelCase:			Optional[int]      )      ->	List[Any]:
    for i in range(0		,   len(__UpperCAmelCase      )		,   __UpperCAmelCase      ):
        UpperCamelCase__							:				List[Any]          =      dataset[i : i + batch_size]




@get_duration
def 		lowerCAmelCase_    (  __UpperCAmelCase:			datasets.Dataset		,   __UpperCAmelCase:			int		,   __UpperCAmelCase:			Union[str, Any]      )      ->	Any:
    with dataset.formatted_as(type=__UpperCAmelCase      ):
        for i in range(__UpperCAmelCase      ):
            UpperCamelCase__							:				Any          =      dataset[i]




@get_duration
def 		lowerCAmelCase_    (  __UpperCAmelCase:			datasets.Dataset		,   __UpperCAmelCase:			str		,   __UpperCAmelCase:			Optional[Any]		,   __UpperCAmelCase:			Optional[int]      )      ->	List[Any]:
    with dataset.formatted_as(type=__UpperCAmelCase      ):
        for i in range(0		,   __UpperCAmelCase		,   __UpperCAmelCase      ):
            UpperCamelCase__							:				int          =      dataset[i : i + batch_size]




def 		lowerCAmelCase_    (  )      ->	int:
    UpperCamelCase__							:				Dict          =      {'''num examples''': SPEED_TEST_N_EXAMPLES}
    UpperCamelCase__							:				Optional[Any]          =      [
        (read, {'''length''': SMALL_TEST}),
        (read, {'''length''': SPEED_TEST_N_EXAMPLES}),
        (read_batch, {'''length''': SPEED_TEST_N_EXAMPLES, '''batch_size''': 10}),
        (read_batch, {'''length''': SPEED_TEST_N_EXAMPLES, '''batch_size''': 100}),
        (read_batch, {'''length''': SPEED_TEST_N_EXAMPLES, '''batch_size''': 1000}),
        (read_formatted, {'''type''': '''numpy''', '''length''': SMALL_TEST}),
        (read_formatted, {'''type''': '''pandas''', '''length''': SMALL_TEST}),
        (read_formatted, {'''type''': '''torch''', '''length''': SMALL_TEST}),
        (read_formatted, {'''type''': '''tensorflow''', '''length''': SMALL_TEST}),
        (read_formatted_batch, {'''type''': '''numpy''', '''length''': SMALL_TEST, '''batch_size''': 10}),
        (read_formatted_batch, {'''type''': '''numpy''', '''length''': SMALL_TEST, '''batch_size''': 1000}),
    ]

    UpperCamelCase__							:				str          =      [
        (read, {'''length''': SMALL_TEST}),
        (read, {'''length''': SPEED_TEST_N_EXAMPLES}),
        (read_batch, {'''length''': SPEED_TEST_N_EXAMPLES, '''batch_size''': 10}),
        (read_batch, {'''length''': SPEED_TEST_N_EXAMPLES, '''batch_size''': 100}),
        (read_batch, {'''length''': SPEED_TEST_N_EXAMPLES, '''batch_size''': 1000}),
        (read_formatted, {'''type''': '''numpy''', '''length''': SMALL_TEST}),
        (read_formatted_batch, {'''type''': '''numpy''', '''length''': SMALL_TEST, '''batch_size''': 10}),
        (read_formatted_batch, {'''type''': '''numpy''', '''length''': SMALL_TEST, '''batch_size''': 1000}),
    ]
    with tempfile.TemporaryDirectory() as tmp_dir:
        print('''generating dataset'''      )
        UpperCamelCase__							:				Tuple          =      datasets.Features(
            {'''list''': datasets.Sequence(datasets.Value('''float32'''      )      ), '''numbers''': datasets.Value('''float32'''      )}      )
        UpperCamelCase__							:				Union[str, Any]          =      generate_example_dataset(
            os.path.join(__UpperCAmelCase		,   '''dataset.arrow'''      )		,   __UpperCAmelCase		,   num_examples=__UpperCAmelCase		,   seq_shapes={'''list''': (100,)}		,   )
        print('''first set of iterations'''      )
        for func, kwargs in functions:
            print(func.__name__		,   str(__UpperCAmelCase      )      )
            UpperCamelCase__							:				Any          =      func(__UpperCAmelCase		,   **__UpperCAmelCase      )

        print('''shuffling dataset'''      )
        UpperCamelCase__							:				Union[str, Any]          =      dataset.shuffle()
        print('''Second set of iterations (after shuffling'''      )
        for func, kwargs in functions_shuffled:
            print('''shuffled '''		,   func.__name__		,   str(__UpperCAmelCase      )      )
            UpperCamelCase__							:				List[Any]          =      func(
                __UpperCAmelCase		,   **__UpperCAmelCase      )

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


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








from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


UpperCAmelCase_     							= {
    'configuration_convbert': ['CONVBERT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'ConvBertConfig', 'ConvBertOnnxConfig'],
    'tokenization_convbert': ['ConvBertTokenizer'],
}

try:
  if not is_tokenizers_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  UpperCAmelCase_     							= ['ConvBertTokenizerFast']

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  UpperCAmelCase_     							= [
      'CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST',
      'ConvBertForMaskedLM',
      'ConvBertForMultipleChoice',
      'ConvBertForQuestionAnswering',
      'ConvBertForSequenceClassification',
      'ConvBertForTokenClassification',
      'ConvBertLayer',
      'ConvBertModel',
      'ConvBertPreTrainedModel',
      'load_tf_weights_in_convbert',
  ]


try:
  if not is_tf_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  UpperCAmelCase_     							= [
      'TF_CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST',
      'TFConvBertForMaskedLM',
      'TFConvBertForMultipleChoice',
      'TFConvBertForQuestionAnswering',
      'TFConvBertForSequenceClassification',
      'TFConvBertForTokenClassification',
      'TFConvBertLayer',
      'TFConvBertModel',
      'TFConvBertPreTrainedModel',
  ]


if TYPE_CHECKING:
  from .configuration_convbert import CONVBERT_PRETRAINED_CONFIG_ARCHIVE_MAP, ConvBertConfig, ConvBertOnnxConfig
  from .tokenization_convbert import ConvBertTokenizer

  try:
    if not is_tokenizers_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .tokenization_convbert_fast import ConvBertTokenizerFast

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_convbert import (
        CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
        ConvBertForMaskedLM,
        ConvBertForMultipleChoice,
        ConvBertForQuestionAnswering,
        ConvBertForSequenceClassification,
        ConvBertForTokenClassification,
        ConvBertLayer,
        ConvBertModel,
        ConvBertPreTrainedModel,
        load_tf_weights_in_convbert,
    )

  try:
    if not is_tf_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_tf_convbert import (
        TF_CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
        TFConvBertForMaskedLM,
        TFConvBertForMultipleChoice,
        TFConvBertForQuestionAnswering,
        TFConvBertForSequenceClassification,
        TFConvBertForTokenClassification,
        TFConvBertLayer,
        TFConvBertModel,
        TFConvBertPreTrainedModel,
    )


else:
  import sys

  UpperCAmelCase_     							= _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)

