




from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


lowercase_     :    List[str]      =			logging.get_logger(__name__)

lowercase_     :    Optional[int]      =			{
    'apple/mobilevitv2-1.0': 'https://huggingface.co/apple/mobilevitv2-1.0/resolve/main/config.json',
}
class    __lowerCAmelCase			(	__lowerCamelCase			):
			snake_case_				:			Optional[int]								=					"mobilevitv2"







			def __init__(	self   :      Dict   ,   snake_case__   :      Tuple=3   ,   snake_case__   :      Optional[int]=256   ,   snake_case__   :      Optional[int]=2   ,   snake_case__   :      Optional[Any]=2.0   ,   snake_case__   :      Tuple="swish"   ,   snake_case__   :      Optional[Any]=3   ,   snake_case__   :      Tuple=32   ,   snake_case__   :      Dict=0.1   ,   snake_case__   :      Tuple=0.02   ,   snake_case__   :      Optional[Any]=1e-5   ,   snake_case__   :      Union[str, Any]=512   ,   snake_case__   :      Dict=[6, 12, 18]   ,   snake_case__   :      List[Any]=0.1   ,   snake_case__   :      Union[str, Any]=255   ,   snake_case__   :      Optional[int]=[2, 4, 3]   ,   snake_case__   :      int=[128, 192, 256]   ,   snake_case__   :      int=1.0   ,   snake_case__   :      Optional[int]=2   ,   snake_case__   :      str=0.0   ,   snake_case__   :      List[str]=0.0   ,   **snake_case__   :      List[str]   ,   ):




									"""simple docstring"""


									super().__init__(**_UpperCamelCase				)

									_UpperCAmelCase													=					num_channels
									_UpperCAmelCase													=					image_size
									_UpperCAmelCase													=					patch_size
									_UpperCAmelCase													=					expand_ratio
									_UpperCAmelCase													=					hidden_act
									_UpperCAmelCase													=					conv_kernel_size
									_UpperCAmelCase													=					output_stride
									_UpperCAmelCase													=					initializer_range
									_UpperCAmelCase													=					layer_norm_eps
									_UpperCAmelCase													=					n_attn_blocks
									_UpperCAmelCase													=					base_attn_unit_dims
									_UpperCAmelCase													=					width_multiplier
									_UpperCAmelCase													=					ffn_multiplier
									_UpperCAmelCase													=					ffn_dropout
									_UpperCAmelCase													=					attn_dropout
									_UpperCAmelCase													=					classifier_dropout_prob

									# decode head attributes for semantic segmentation
									_UpperCAmelCase													=					aspp_out_channels
									_UpperCAmelCase													=					atrous_rates
									_UpperCAmelCase													=					aspp_dropout_prob
									_UpperCAmelCase													=					semantic_loss_ignore_index




class    __lowerCAmelCase			(	__lowerCamelCase			):
			snake_case_				:			Dict								=					version.parse("1.11"			)







			@property
			def UpperCamelCase      (	self   :      Tuple				):




									"""simple docstring"""


									return OrderedDict([("pixel_values", {0: "batch", 1: "num_channels", 2: "height", 3: "width"})]				)







			@property
			def UpperCamelCase      (	self   :      List[Any]				):




									"""simple docstring"""


									if self.task == "image-classification":
															return OrderedDict([("logits", {0: "batch"})]				)
									else:
															return OrderedDict([("last_hidden_state", {0: "batch"}), ("pooler_output", {0: "batch"})]				)







			@property
			def UpperCamelCase      (	self   :      str				):




									"""simple docstring"""


									return 1e-4










import itertools
from dataclasses import dataclass
from typing import Optional

import pyarrow as pa

import datasets
from datasets.table import table_cast


lowercase_     :    Union[str, Any]      =			datasets.utils.logging.get_logger(__name__)






@dataclass
class    __lowerCAmelCase			(	datasets.BuilderConfig			):
			snake_case_				:			Optional[datasets.Features]								=					None






class    __lowerCAmelCase			(	datasets.ArrowBasedBuilder			):
			snake_case_				:			str								=					ArrowConfig







			def UpperCamelCase      (	self   :      Optional[int]				):




									"""simple docstring"""


									return datasets.DatasetInfo(features=self.config.features				)







			def UpperCamelCase      (	self   :      str   ,   snake_case__   :      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}"""				)
									_UpperCAmelCase													=					dl_manager.download_and_extract(self.config.data_files				)
									if isinstance(snake_case__   ,   (str, list, tuple)				):
															_UpperCAmelCase													=					data_files
															if isinstance(snake_case__   ,   snake_case__				):
																					_UpperCAmelCase													=					[files]
															# Use `dl_manager.iter_files` to skip hidden files in an extracted archive
															_UpperCAmelCase													=					[dl_manager.iter_files(snake_case__				) for file in files]
															return [datasets.SplitGenerator(name=datasets.Split.TRAIN   ,   gen_kwargs={"files": files}				)]
									_UpperCAmelCase													=					[]
									for split_name, files in data_files.items():
															if isinstance(snake_case__   ,   snake_case__				):
																					_UpperCAmelCase													=					[files]
															# Use `dl_manager.iter_files` to skip hidden files in an extracted archive
															_UpperCAmelCase													=					[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:
																																	_UpperCAmelCase													=					datasets.Features.from_arrow_schema(pa.ipc.open_stream(snake_case__				).schema				)
																											break
															splits.append(datasets.SplitGenerator(name=snake_case__   ,   gen_kwargs={"files": files}				)				)
									return splits







			def UpperCamelCase      (	self   :      int   ,   snake_case__   :      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
															_UpperCAmelCase													=					table_cast(snake_case__   ,   self.info.features.arrow_schema				)
									return pa_table







			def UpperCamelCase      (	self   :      Optional[Any]   ,   snake_case__   :      int				):




									"""simple docstring"""


									for file_idx, file in enumerate(itertools.chain.from_iterable(snake_case__				)				):
															with open(snake_case__   ,   "rb"				) as f:
																					try:
																											for batch_idx, record_batch in enumerate(pa.ipc.open_stream(snake_case__				)				):
																																	_UpperCAmelCase													=					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




