



import copy

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


__UpperCAmelCase						  =     logging.get_logger(__name__)


class 	lowerCamelCase__ (		_a   ):
						_lowerCAmelCase								= '''hybrid-clip'''
						_lowerCAmelCase								= True


						def __init__( self						:  List[str]      ,       _a						:  Any=5_1_2      ,       **_a						:  int			):
													super().__init__(**_a			)

													if "text_config" not in kwargs:
																				raise ValueError("`text_config` can not be `None`."			)

													if "vision_config" not in kwargs:
																				raise ValueError("`vision_config` can not be `None`."			)

													a__:       Dict											=kwargs.pop("text_config"			)
													a__:       int											=kwargs.pop("vision_config"			)

													a__:       Union[str, Any]											=text_config.pop("model_type"			)
													a__:       Tuple											=vision_config.pop("model_type"			)

													from transformers import AutoConfig

													a__:       str											=AutoConfig.for_model(_a      ,       **_a			)

													if vision_model_type == "clip":
																				a__:       Dict											=AutoConfig.for_model(_a      ,       **_a			).vision_config
													elif vision_model_type == "clip_vision_model":
																				from transformers import CLIPVisionConfig

																				a__:       Union[str, Any]											=CLIPVisionConfig(**_a			)
													else:
																				a__:       Optional[int]											=AutoConfig.for_model(_a      ,       **_a			)

													a__:       int											=projection_dim
													a__:       int											=1.0


						@classmethod
						def   _lowerCamelCase			( cls						:  List[str]      ,       _a						:  PretrainedConfig      ,       _a						:  PretrainedConfig      ,       **_a						:  Optional[Any]			):
													return cls(text_config=text_config.to_dict()      ,       vision_config=vision_config.to_dict()      ,       **_a			)







						def   _lowerCamelCase			( self						:  Dict			):
													a__:       Dict											=copy.deepcopy(self.__dict__			)
													a__:       Any											=self.text_config.to_dict()
													a__:       Any											=self.vision_config.to_dict()
													a__:       int											=self.__class__.model_type
													return output










import json
import os
from dataclasses import dataclass

import numpy as np
import pyarrow as pa

import datasets
from utils import get_duration


__UpperCAmelCase						  =     10_00_00_00_00_00
__UpperCAmelCase						  =     1_00_00

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





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


@dataclass
class 	lowerCamelCase__ :
						_lowerCAmelCase								= 42
						_lowerCAmelCase								= 42
						_lowerCAmelCase								= 42
						_lowerCAmelCase								= 42


						def   _lowerCamelCase			( self						:  Union[str, Any]			):
													a__:       Tuple											=np.random.default_rng(self.seed			)
													a__:       Tuple											=rng.integers(low=self.low      ,       high=self.high      ,       size=self.size			).tolist()


						def __iter__( self						:  Any			):
													return iter(self._sampled_values			)







						def __len__( self						:  Any			):
													return self.size





@get_duration
def 						__lowerCamelCase       (      __magic_name__	:  datasets.Dataset						):
							a__:       Union[str, Any]											=dataset[0]





@get_duration
def 						__lowerCamelCase       (      __magic_name__	:  datasets.Dataset						):
							a__:       Optional[Any]											=dataset[-1]





@get_duration
def 						__lowerCamelCase       (      __magic_name__	:  datasets.Dataset						):
							a__:       List[str]											=dataset[range(len(__magic_name__						) // 2     , len(__magic_name__						) // 2 + 1_024						)]





@get_duration
def 						__lowerCamelCase       (      __magic_name__	:  datasets.Dataset						):
							a__:       Optional[int]											=dataset[RandIter(0     , len(__magic_name__						)     , 1_024     , seed=42						)]





def 						__lowerCamelCase       (      ):
							a__:       Dict											={"num examples": SPEED_TEST_N_EXAMPLES}
							a__:       Union[str, Any]											=(get_first_row, get_last_row, get_batch_of_aaaa_rows, get_batch_of_aaaa_random_rows)
							print("generating dataset"						)
							a__:       Dict											=generate_100B_dataset(num_examples=__magic_name__     , chunk_size=__magic_name__						)
							print("Functions"						)
							for func in functions:
														print(func.__name__						)
														a__:       Dict											=func(__magic_name__						)

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


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





