


import json
import os
import tempfile

import datasets
from utils import generate_example_dataset, get_duration


lowerCAmelCase	=							5_0000
lowerCAmelCase	=							5000

lowerCAmelCase,						lowerCAmelCase	=							os.path.split(__file__)
lowerCAmelCase	=							os.path.join(RESULTS_BASEPATH, 'results', RESULTS_FILENAME.replace('.py', '.json'))
@get_duration
def       _a			(				SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE					):


		"""simple docstring"""




		for i in range(SCREAMING_SNAKE_CASE					):
				lowercase__						=				dataset[i]
@get_duration
def       _a			(				SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE					):


		"""simple docstring"""




		for i in range(0						,    len(SCREAMING_SNAKE_CASE					)						,    SCREAMING_SNAKE_CASE					):
				lowercase__						=				dataset[i : i + batch_size]
@get_duration
def       _a			(				SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE					):


		"""simple docstring"""




		with dataset.formatted_as(type=SCREAMING_SNAKE_CASE					):
				for i in range(SCREAMING_SNAKE_CASE					):
						lowercase__						=				dataset[i]
@get_duration
def       _a			(				SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE					):


		"""simple docstring"""




		with dataset.formatted_as(type=SCREAMING_SNAKE_CASE					):
				for i in range(0						,    SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE					):
						lowercase__						=				dataset[i : i + batch_size]
def       _a			(				):


		"""simple docstring"""




		lowercase__						=				{'''num examples''': SPEED_TEST_N_EXAMPLES}
		lowercase__						=				[
		    (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''': 1_00}),
		    (read_batch, {'''length''': SPEED_TEST_N_EXAMPLES, '''batch_size''': 10_00}),
		    (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''': 10_00}),
		]

		lowercase__						=				[
		    (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''': 1_00}),
		    (read_batch, {'''length''': SPEED_TEST_N_EXAMPLES, '''batch_size''': 10_00}),
		    (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''': 10_00}),
		]
		with tempfile.TemporaryDirectory() as tmp_dir:
				print('''generating dataset'''					)
				lowercase__						=				datasets.Features(
				    {'''list''': datasets.Sequence(datasets.Value('''float32'''					)					), '''numbers''': datasets.Value('''float32'''					)}					)
				lowercase__						=				generate_example_dataset(
				    os.path.join(SCREAMING_SNAKE_CASE						,    '''dataset.arrow'''					)						,    SCREAMING_SNAKE_CASE						,    num_examples=SCREAMING_SNAKE_CASE						,    seq_shapes={'''list''': (1_00,)}						,    )
				print('''first set of iterations'''					)
				for func, kwargs in functions:
						print(func.__name__						,    str(SCREAMING_SNAKE_CASE					)					)
						lowercase__						=				func(SCREAMING_SNAKE_CASE						,    **SCREAMING_SNAKE_CASE					)

				print('''shuffling dataset'''					)
				lowercase__						=				dataset.shuffle()
				print('''Second set of iterations (after shuffling'''					)
				for func, kwargs in functions_shuffled:
						print('''shuffled '''						,    func.__name__						,    str(SCREAMING_SNAKE_CASE					)					)
						lowercase__						=				func(
						    SCREAMING_SNAKE_CASE						,    **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_iterating()






from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowerCAmelCase	=							logging.get_logger(__name__)

lowerCAmelCase	=							{
    'unc-nlp/lxmert-base-uncased': 'https://huggingface.co/unc-nlp/lxmert-base-uncased/resolve/main/config.json',
}


class 	_a							(      UpperCamelCase__      ):
							_lowercase     :      List[Any]  				=			'''lxmert'''
							_lowercase     :      Any  				=			{}

							def __init__(							self:     Any   ,						UpperCamelCase_:     List[Any]=30_522   ,						UpperCamelCase_:     int=768   ,						UpperCamelCase_:     Optional[Any]=12   ,						UpperCamelCase_:     Dict=9_500   ,						UpperCamelCase_:     List[Any]=1_600   ,						UpperCamelCase_:     List[Any]=400   ,						UpperCamelCase_:     List[str]=3_072   ,						UpperCamelCase_:     int="gelu"   ,						UpperCamelCase_:     Any=0.1   ,						UpperCamelCase_:     int=0.1   ,						UpperCamelCase_:     List[str]=512   ,						UpperCamelCase_:     Optional[int]=2   ,						UpperCamelCase_:     Union[str, Any]=0.02   ,						UpperCamelCase_:     Dict=1E-1_2   ,						UpperCamelCase_:     List[Any]=9   ,						UpperCamelCase_:     List[Any]=5   ,						UpperCamelCase_:     Optional[Any]=5   ,						UpperCamelCase_:     str=2_048   ,						UpperCamelCase_:     Dict=4   ,						UpperCamelCase_:     Any=6.67   ,						UpperCamelCase_:     Dict=True   ,						UpperCamelCase_:     List[str]=True   ,						UpperCamelCase_:     Dict=True   ,						UpperCamelCase_:     Any=True   ,						UpperCamelCase_:     Tuple=True   ,						UpperCamelCase_:     Optional[Any]=True   ,						UpperCamelCase_:     Any=True   ,						**UpperCamelCase_:     Union[str, Any]   ,						)      ->       Union[str, Any]:





									"""simple docstring"""







									lowercase__						=				vocab_size
									lowercase__						=				hidden_size
									lowercase__						=				num_attention_heads
									lowercase__						=				hidden_act
									lowercase__						=				intermediate_size
									lowercase__						=				hidden_dropout_prob
									lowercase__						=				attention_probs_dropout_prob
									lowercase__						=				max_position_embeddings
									lowercase__						=				type_vocab_size
									lowercase__						=				initializer_range
									lowercase__						=				layer_norm_eps
									lowercase__						=				num_qa_labels
									lowercase__						=				num_object_labels
									lowercase__						=				num_attr_labels
									lowercase__						=				l_layers
									lowercase__						=				x_layers
									lowercase__						=				r_layers
									lowercase__						=				visual_feat_dim
									lowercase__						=				visual_pos_dim
									lowercase__						=				visual_loss_normalizer
									lowercase__						=				task_matched
									lowercase__						=				task_mask_lm
									lowercase__						=				task_obj_predict
									lowercase__						=				task_qa
									lowercase__						=				visual_obj_loss
									lowercase__						=				visual_attr_loss
									lowercase__						=				visual_feat_loss
									lowercase__						=				{'''vision''': r_layers, '''cross_encoder''': x_layers, '''language''': l_layers}
									super().__init__(**UpperCamelCase_							)


