
"""simple docstring"""





import itertools
from dataclasses import dataclass
from typing import List, Optional

import pyarrow as pa
import pyarrow.parquet as pq

import datasets
from datasets.table import table_cast


UpperCamelCase_					:						Optional[int]				= datasets.utils.logging.get_logger(__name__)



@dataclass
class __lowerCAmelCase				(					datasets.BuilderConfig      ):




			"""simple docstring"""







			snake_case	      =				1_00_00
			snake_case	      =				None
			snake_case	      =				None





class __lowerCAmelCase				(					datasets.ArrowBasedBuilder      ):




			"""simple docstring"""







			snake_case	      =				ParquetConfig




			def      lowerCamelCase__     (				self						:					List[Any]	)      -> Dict:







								"""simple docstring"""
								return datasets.DatasetInfo(features=self.config.features	)




			def      lowerCamelCase__     (				self						:					List[Any]       ,   _snake_case						:					Any	)      -> Optional[int]:







								"""simple docstring"""
								if not self.config.data_files:
													raise ValueError(F'At least one data file must be specified, but got data_files={self.config.data_files}'	)
								A_				 =						dl_manager.download_and_extract(self.config.data_files	)
								if isinstance(_snake_case       ,   (str, list, tuple)	):
													A_				 =						data_files
													if isinstance(_snake_case       ,   _snake_case	):
																		A_				 =						[files]
													# Use `dl_manager.iter_files` to skip hidden files in an extracted archive
													A_				 =						[dl_manager.iter_files(_snake_case	) for file in files]
													return [datasets.SplitGenerator(name=datasets.Split.TRAIN       ,   gen_kwargs={"files": files}	)]
								A_				 =						[]
								for split_name, files in data_files.items():
													if isinstance(_snake_case       ,   _snake_case	):
																		A_				 =						[files]
													# Use `dl_manager.iter_files` to skip hidden files in an extracted archive
													A_				 =						[dl_manager.iter_files(_snake_case	) for file in files]
													# Infer features is they are stoed in the arrow schema
													if self.info.features is None:
																		for file in itertools.chain.from_iterable(_snake_case	):
																							with open(_snake_case       ,   "rb"	) as f:
																												A_				 =						datasets.Features.from_arrow_schema(pq.read_schema(_snake_case	)	)
																							break
													splits.append(datasets.SplitGenerator(name=_snake_case       ,   gen_kwargs={"files": files}	)	)
								return splits




			def      lowerCamelCase__     (				self						:					Tuple       ,   _snake_case						:					pa.Table	)      -> pa.Table:







								"""simple docstring"""
								if self.info.features is not None:
													# more expensive cast to support nested features with keys in a different order
													# allows str <-> int/float or str to Audio for example
													A_				 =						table_cast(_snake_case       ,   self.info.features.arrow_schema	)
								return pa_table






			def      lowerCamelCase__     (				self						:					Optional[int]       ,   _snake_case						:					Dict	)      -> Optional[Any]:







								"""simple docstring"""
								A_				 =						self.info.features.arrow_schema if self.info.features is not None else None
								if self.info.features is not None and self.config.columns is not None:
													if sorted(field.name for field in schema	) != sorted(self.config.columns	):
																		raise ValueError(
																		    F'Tried to load parquet data with columns \'{self.config.columns}\' with mismatching features \'{self.info.features}\''	)
								for file_idx, file in enumerate(itertools.chain.from_iterable(_snake_case	)	):
													with open(_snake_case       ,   "rb"	) as f:
																		A_				 =						pq.ParquetFile(_snake_case	)
																		try:
																							for batch_idx, record_batch in enumerate(
																							    parquet_file.iter_batches(batch_size=self.config.batch_size       ,   columns=self.config.columns	)	):
																												A_				 =						pa.Table.from_batches([record_batch]	)
																												# Uncomment for debugging (will print the Arrow table size and elements)
																												# logger.warning(f"pa_table: {pa_table} num rows: {pa_table.num_rows}")
																												# logger.warning('\n'.join(str(pa_table.slice(i, 1).to_pydict()) for i in range(pa_table.num_rows)))
																												yield F'{file_idx}_{batch_idx}', self._cast_table(_snake_case	)
																		except ValueError as e:
																							logger.error(F'Failed to read file \'{file}\' with error {type(_snake_case	)}: {e}'	)
																							raise






"""simple docstring"""





from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


UpperCamelCase_					:						Optional[int]				= logging.get_logger(__name__)

UpperCamelCase_					:						Dict				= {
    '''microsoft/focalnet-tiny''': '''https://huggingface.co/microsoft/focalnet-tiny/resolve/main/config.json''',
}



class __lowerCAmelCase				(					_lowercase     ,				_lowercase      ):




			"""simple docstring"""







			snake_case	      =				"focalnet"




			def __init__(				self						:					Any       ,   _snake_case						:					Optional[int]=224       ,   _snake_case						:					List[str]=4       ,   _snake_case						:					Any=3       ,   _snake_case						:					List[Any]=96       ,   _snake_case						:					Union[str, Any]=False       ,   _snake_case						:					Optional[Any]=[192, 384, 768, 768]       ,   _snake_case						:					List[str]=[2, 2, 6, 2]       ,   _snake_case						:					Any=[2, 2, 2, 2]       ,   _snake_case						:					List[Any]=[3, 3, 3, 3]       ,   _snake_case						:					Optional[Any]="gelu"       ,   _snake_case						:					Dict=4.0       ,   _snake_case						:					List[Any]=0.0       ,   _snake_case						:					List[str]=0.1       ,   _snake_case						:					Optional[Any]=False       ,   _snake_case						:					Any=1e-4       ,   _snake_case						:					str=False       ,   _snake_case						:					Optional[int]=False       ,   _snake_case						:					Tuple=False       ,   _snake_case						:					Any=0.0_2       ,   _snake_case						:					List[Any]=1e-5       ,   _snake_case						:					Union[str, Any]=32       ,   _snake_case						:					Tuple=None       ,   _snake_case						:					Any=None       ,   **_snake_case						:					Tuple       ,   )      -> str:







								"""simple docstring"""
								super().__init__(**_snake_case	)

								A_				 =						image_size
								A_				 =						patch_size
								A_				 =						num_channels
								A_				 =						embed_dim
								A_				 =						use_conv_embed
								A_				 =						hidden_sizes
								A_				 =						depths
								A_				 =						focal_levels
								A_				 =						focal_windows
								A_				 =						hidden_act
								A_				 =						mlp_ratio
								A_				 =						hidden_dropout_prob
								A_				 =						drop_path_rate
								A_				 =						use_layerscale
								A_				 =						layerscale_value
								A_				 =						use_post_layernorm
								A_				 =						use_post_layernorm_in_modulation
								A_				 =						normalize_modulator
								A_				 =						initializer_range
								A_				 =						layer_norm_eps
								A_				 =						encoder_stride
								A_				 =						["stem"] + [F'stage{idx}' for idx in range(1       ,   len(self.depths	) + 1	)]
								A_ ,    A_				 =						get_aligned_output_features_output_indices(
								    out_features=_snake_case       ,   out_indices=_snake_case       ,   stage_names=self.stage_names	)




