


import json
import os
from dataclasses import dataclass

import numpy as np
import pyarrow as pa

import datasets
from utils import get_duration


UpperCAmelCase__            =							1000_0000_0000
UpperCAmelCase__            =							1_0000

UpperCAmelCase__     ,UpperCAmelCase__            =							os.path.split(__file__)
UpperCAmelCase__            =							os.path.join(RESULTS_BASEPATH, '''results''', RESULTS_FILENAME.replace('''.py''', '''.json'''))
def     UpperCAmelCase_ (							__snake_case					,						__snake_case						)					->      datasets.Dataset:







 """simple docstring"""


 _lowercase											=pa.Table.from_pydict({'''col''': [0] * chunk_size}						)
 _lowercase											=pa.concat_tables([table] * (num_examples // chunk_size)						)
 return datasets.Dataset(__snake_case					,						fingerprint='''table_100B'''						)







@dataclass
class 				lowerCamelCase__       :
     SCREAMING_SNAKE_CASE__				      =      42
     SCREAMING_SNAKE_CASE__				      =      42
     SCREAMING_SNAKE_CASE__				      =      42
     SCREAMING_SNAKE_CASE__				      =      42





     def 					__A (self	)					->       Tuple:
      _lowercase											=np.random.default_rng(self.seed	)
      _lowercase											=rng.integers(low=self.low		,					high=self.high		,					size=self.size	).tolist()





     def __iter__(self	)					->       int:
      return iter(self._sampled_values	)





     def __len__(self	)					->       int:
      return self.size



@get_duration
def     UpperCAmelCase_ (							__snake_case						)					->      Any:







 """simple docstring"""


 _lowercase											=dataset[0]
@get_duration
def     UpperCAmelCase_ (							__snake_case						)					->      Union[str, Any]:







 """simple docstring"""


 _lowercase											=dataset[-1]
@get_duration
def     UpperCAmelCase_ (							__snake_case						)					->      Any:







 """simple docstring"""


 _lowercase											=dataset[range(len(__snake_case						) // 2					,						len(__snake_case						) // 2 + 1024						)]
@get_duration
def     UpperCAmelCase_ (							__snake_case						)					->      int:







 """simple docstring"""


 _lowercase											=dataset[RandIter(0					,						len(__snake_case						)					,						1024					,						seed=42						)]
def     UpperCAmelCase_ (							)					->      str:







 """simple docstring"""


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

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


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





import argparse

from . import (
    BertConfig,
    BertGenerationConfig,
    BertGenerationDecoder,
    BertGenerationEncoder,
    load_tf_weights_in_bert_generation,
    logging,
)


logging.set_verbosity_info()
def     UpperCAmelCase_ (							__snake_case					,						__snake_case					,						__snake_case					,						__snake_case					,						__snake_case						)					->      Tuple:







 """simple docstring"""


 _lowercase											=BertConfig.from_pretrained(
     '''bert-large-cased'''					,						vocab_size=__snake_case					,						max_position_embeddings=512					,						is_decoder=__snake_case					,						add_cross_attention=__snake_case					,						)
 _lowercase											=bert_config.to_dict()
 del bert_config_dict["type_vocab_size"]
 _lowercase											=BertGenerationConfig(**__snake_case						)
 if is_encoder:
  _lowercase											=BertGenerationEncoder(__snake_case						)
 else:
  _lowercase											=BertGenerationDecoder(__snake_case						)
 print(F"Building PyTorch model from configuration: {config}"						)

 # Load weights from tf checkpoint
 load_tf_weights_in_bert_generation(
     __snake_case					,						__snake_case					,						model_class='''bert'''					,						is_encoder_named_decoder=__snake_case					,						is_encoder=__snake_case					,						)

 # Save pytorch-model
 print(F"Save PyTorch model and config to {pytorch_dump_path}"						)
 model.save_pretrained(__snake_case						)


if __name__ == "__main__":
  UpperCAmelCase__            =							argparse.ArgumentParser()
  # Required parameters
  parser.add_argument(
      '''--tf_hub_path''', default=None, type=str, required=True, help='''Path to the TensorFlow checkpoint path.'''
  )
  parser.add_argument(
      '''--pytorch_dump_path''', default=None, type=str, required=True, help='''Path to the output PyTorch model.'''
  )
  parser.add_argument(
      '''--is_encoder_named_decoder''',
      action='''store_true''',
      help='''If decoder has to be renamed to encoder in PyTorch model.''',
  )
  parser.add_argument('''--is_encoder''', action='''store_true''', help='''If model is an encoder.''')
  parser.add_argument('''--vocab_size''', default=5_0358, type=int, help='''Vocab size of model''')
  UpperCAmelCase__            =							parser.parse_args()
  convert_tf_checkpoint_to_pytorch(
      args.tf_hub_path,
      args.pytorch_dump_path,
      args.is_encoder_named_decoder,
      args.vocab_size,
      is_encoder=args.is_encoder,
  )

