



import copy

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


__UpperCAmelCase						  =     logging.get_logger(__name__)

__UpperCAmelCase						  =     {
    '''facebook/sam-vit-huge''': '''https://huggingface.co/facebook/sam-vit-huge/resolve/main/config.json''',
    '''facebook/sam-vit-large''': '''https://huggingface.co/facebook/sam-vit-large/resolve/main/config.json''',
    '''facebook/sam-vit-base''': '''https://huggingface.co/facebook/sam-vit-base/resolve/main/config.json''',
}


class 	lowerCamelCase__ (		_a   ):


						def __init__( self						:  List[Any]      ,       _a						:  int=2_5_6      ,       _a						:  int=1_0_2_4      ,       _a						:  Optional[int]=1_6      ,       _a						:  Dict=1_6      ,       _a						:  Any=4      ,       _a						:  List[Any]="gelu"      ,       _a						:  Union[str, Any]=1e-6      ,       **_a						:  str      ,       ):
							super().__init__(**_a			)
							a__:       Any											=hidden_size
							a__:       str											=image_size
							a__:       Union[str, Any]											=patch_size
							a__:       str											=image_size // patch_size
							a__:       Any											=mask_input_channels
							a__:       Optional[int]											=num_point_embeddings
							a__:       Optional[int]											=hidden_act
							a__:       str											=layer_norm_eps


class 	lowerCamelCase__ (		_a   ):


						def __init__( self						:  Optional[Any]      ,       _a						:  Any=2_5_6      ,       _a						:  int="relu"      ,       _a						:  List[str]=2_0_4_8      ,       _a						:  Union[str, Any]=2      ,       _a						:  Any=8      ,       _a						:  List[Any]=2      ,       _a						:  int=3      ,       _a						:  Optional[int]=3      ,       _a						:  str=2_5_6      ,       _a						:  str=1e-6      ,       **_a						:  Tuple      ,       ):
							super().__init__(**_a			)
							a__:       Dict											=hidden_size
							a__:       int											=hidden_act
							a__:       Optional[int]											=mlp_dim
							a__:       Dict											=num_hidden_layers
							a__:       Optional[int]											=num_attention_heads
							a__:       str											=attention_downsample_rate
							a__:       List[Any]											=num_multimask_outputs
							a__:       Optional[Any]											=iou_head_depth
							a__:       str											=iou_head_hidden_dim
							a__:       int											=layer_norm_eps


class 	lowerCamelCase__ (		_a   ):


						def __init__( self						:  Optional[int]      ,       _a						:  Tuple=7_6_8      ,       _a						:  Union[str, Any]=2_5_6      ,       _a						:  Optional[Any]=1_2      ,       _a						:  Optional[Any]=1_2      ,       _a						:  Any=3      ,       _a						:  List[str]=1_0_2_4      ,       _a						:  Tuple=1_6      ,       _a						:  Union[str, Any]="gelu"      ,       _a						:  Tuple=1e-06      ,       _a						:  List[Any]=0.0      ,       _a						:  Optional[int]=1e-10      ,       _a						:  Any=True      ,       _a						:  List[str]=4.0      ,       _a						:  str=True      ,       _a						:  Optional[Any]=True      ,       _a						:  List[str]=1_4      ,       _a						:  Any=[2, 5, 8, 1_1]      ,       _a						:  int=1_2_8      ,       _a						:  int=None      ,       **_a						:  Tuple      ,       ):
							super().__init__(**_a			)

							a__:       Tuple											=hidden_size
							a__:       Union[str, Any]											=output_channels
							a__:       Optional[Any]											=num_hidden_layers
							a__:       Optional[Any]											=num_attention_heads
							a__:       int											=num_channels
							a__:       str											=image_size
							a__:       Dict											=patch_size
							a__:       Optional[int]											=hidden_act
							a__:       Optional[int]											=layer_norm_eps
							a__:       int											=attention_dropout
							a__:       Union[str, Any]											=initializer_range
							a__:       int											=qkv_bias
							a__:       Union[str, Any]											=mlp_ratio
							a__:       Tuple											=use_abs_pos
							a__:       List[Any]											=use_rel_pos
							a__:       List[Any]											=window_size
							a__:       Dict											=global_attn_indexes
							a__:       int											=num_pos_feats
							a__:       int											=int(hidden_size * mlp_ratio			) if mlp_dim is None else mlp_dim


class 	lowerCamelCase__ (		_a   ):
						_lowerCAmelCase								= '''sam'''
						_lowerCAmelCase								= True


						def __init__( self						:  List[str]      ,       _a						:  Optional[int]=None      ,       _a						:  List[str]=None      ,       _a						:  Optional[int]=None      ,       _a						:  Union[str, Any]=0.0_2      ,       **_a						:  Optional[int]      ,       ):
							super().__init__(**_a			)
							a__:       int											=vision_config if vision_config is not None else {}
							a__:       List[str]											=prompt_encoder_config if prompt_encoder_config is not None else {}
							a__:       Optional[int]											=mask_decoder_config if mask_decoder_config is not None else {}

							if isinstance(_a      ,       _a			):
								a__:       List[str]											=vision_config.to_dict()
							if isinstance(_a      ,       _a			):
								a__:       List[str]											=prompt_encoder_config.to_dict()
							if isinstance(_a      ,       _a			):
								a__:       Dict											=mask_decoder_config.to_dict()

							a__:       Optional[int]											=SamVisionConfig(**_a			)
							a__:       List[str]											=SamPromptEncoderConfig(**_a			)
							a__:       int											=SamMaskDecoderConfig(**_a			)
							a__:       str											=initializer_range







						def   _lowerCamelCase			( self						:  List[str]			):
							a__:       Optional[Any]											=copy.deepcopy(self.__dict__			)
							a__:       Dict											=self.vision_config.to_dict()
							a__:       Tuple											=self.prompt_encoder_config.to_dict()
							a__:       Optional[Any]											=self.mask_decoder_config.to_dict()
							a__:       Tuple											=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()





