





'''simple docstring'''






import multiprocessing
from typing import TYPE_CHECKING, Optional, Union

from .. import Dataset, Features, config
from ..formatting import query_table
from ..packaged_modules.sql.sql import Sql
from ..utils import logging
from .abc import AbstractDatasetInputStream


if TYPE_CHECKING:
      import sqlitea

      import sqlalchemy







class 		UpperCAmelCase   (				lowercase_):


  """simple docstring"""







  def __init__(				self    :					int							,	UpperCamelCase__    :					Union[str, "sqlalchemy.sql.Selectable"]							,	UpperCamelCase__    :					Union[str, "sqlalchemy.engine.Connection", "sqlalchemy.engine.Engine", "sqlite3.Connection"]							,	UpperCamelCase__    :					Optional[Features] = None							,	UpperCamelCase__    :					str = None							,	UpperCamelCase__    :					bool = False							,	**UpperCamelCase__    :					Tuple							,	)     ->						Dict:
    super().__init__(features=UpperCamelCase__							,	cache_dir=UpperCamelCase__							,	keep_in_memory=UpperCamelCase__							,	**UpperCamelCase__  )
    _UpperCamelCase       			=Sql(
        cache_dir=UpperCamelCase__							,	features=UpperCamelCase__							,	sql=UpperCamelCase__							,	con=UpperCamelCase__							,	**UpperCamelCase__							,	)




  def   UpperCamelCase__      (				self    :					Dict  )     ->						str:
    _UpperCamelCase       			=None
    _UpperCamelCase       			=None
    _UpperCamelCase       			=None
    _UpperCamelCase       			=None

    self.builder.download_and_prepare(
        download_config=UpperCamelCase__							,	download_mode=UpperCamelCase__							,	verification_mode=UpperCamelCase__							,	base_path=UpperCamelCase__							,	)

    # Build dataset for splits
    _UpperCamelCase       			=self.builder.as_dataset(
        split='''train'''							,	verification_mode=UpperCamelCase__							,	in_memory=self.keep_in_memory  )
    return dataset







class 		UpperCAmelCase   :


  """simple docstring"""







  def __init__(				self    :					Union[str, Any]							,	UpperCamelCase__    :					Dataset							,	UpperCamelCase__    :					str							,	UpperCamelCase__    :					Union[str, "sqlalchemy.engine.Connection", "sqlalchemy.engine.Engine", "sqlite3.Connection"]							,	UpperCamelCase__    :					Optional[int] = None							,	UpperCamelCase__    :					Optional[int] = None							,	**UpperCamelCase__    :					List[Any]							,	)     ->						Optional[int]:
    if num_proc is not None and num_proc <= 0:
      raise ValueError(F'''num_proc {num_proc} must be an integer > 0.'''  )

    _UpperCamelCase       			=dataset
    _UpperCamelCase       			=name
    _UpperCamelCase       			=con
    _UpperCamelCase       			=batch_size if batch_size else config.DEFAULT_MAX_BATCH_SIZE
    _UpperCamelCase       			=num_proc
    _UpperCamelCase       			=to_sql_kwargs


  def   UpperCamelCase__      (				self    :					Dict  )     ->						int:
    _UpperCamelCase       			=self.to_sql_kwargs.pop('''sql'''							,	UpperCamelCase__  )
    _UpperCamelCase       			=self.to_sql_kwargs.pop('''con'''							,	UpperCamelCase__  )
    _UpperCamelCase       			=self.to_sql_kwargs.pop('''index'''							,	UpperCamelCase__  )

    _UpperCamelCase       			=self._write(index=UpperCamelCase__							,	**self.to_sql_kwargs  )
    return written


  def   UpperCamelCase__      (				self    :					Optional[int]							,	UpperCamelCase__    :					List[Any]  )     ->						int:
    _UpperCamelCase			,     _UpperCamelCase			,     _UpperCamelCase       			=args
    _UpperCamelCase       			={**to_sql_kwargs, '''if_exists''': '''append'''} if offset > 0 else to_sql_kwargs
    _UpperCamelCase       			=query_table(
        table=self.dataset.data							,	key=slice(UpperCamelCase__							,	offset + self.batch_size  )							,	indices=self.dataset._indices							,	)
    _UpperCamelCase       			=batch.to_pandas()
    _UpperCamelCase       			=df.to_sql(self.name							,	self.con							,	index=UpperCamelCase__							,	**UpperCamelCase__  )
    return num_rows or len(UpperCamelCase__  )




  def   UpperCamelCase__      (				self    :					Union[str, Any]							,	UpperCamelCase__    :					Optional[int]							,	**UpperCamelCase__    :					Union[str, Any]  )     ->						int:
    _UpperCamelCase       			=0

    if self.num_proc is None or self.num_proc == 1:
      for offset in logging.tqdm(
          range(0							,	len(self.dataset  )							,	self.batch_size  )							,	unit='''ba'''							,	disable=not logging.is_progress_bar_enabled()							,	desc='''Creating SQL from Arrow format'''							,	):
        written += self._batch_sql((offset, index, to_sql_kwargs)  )
    else:
      _UpperCamelCase			,     _UpperCamelCase       			=len(self.dataset  ), self.batch_size
      with multiprocessing.Pool(self.num_proc  ) as pool:
        for num_rows in logging.tqdm(
            pool.imap(
                self._batch_sql							,	[(offset, index, to_sql_kwargs) for offset in range(0							,	UpperCamelCase__							,	UpperCamelCase__  )]							,	)							,	total=(num_rows // batch_size) + 1 if num_rows % batch_size else num_rows // batch_size							,	unit='''ba'''							,	disable=not logging.is_progress_bar_enabled()							,	desc='''Creating SQL from Arrow format'''							,	):
          written += num_rows

    return written













'''simple docstring'''






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


__lowerCamelCase						: Union[str, Any]		=   logging.get_logger(__name__)

__lowerCamelCase						: int		=   {
    'google/mobilenet_v2_1.4_224': 'https://huggingface.co/google/mobilenet_v2_1.4_224/resolve/main/config.json',
    'google/mobilenet_v2_1.0_224': 'https://huggingface.co/google/mobilenet_v2_1.0_224/resolve/main/config.json',
    'google/mobilenet_v2_0.75_160': 'https://huggingface.co/google/mobilenet_v2_0.75_160/resolve/main/config.json',
    'google/mobilenet_v2_0.35_96': 'https://huggingface.co/google/mobilenet_v2_0.35_96/resolve/main/config.json',
    # See all MobileNetV2 models at https://huggingface.co/models?filter=mobilenet_v2
}







class 		UpperCAmelCase   (				lowercase_):


  """simple docstring"""







  lowerCAmelCase_					=				"""mobilenet_v2"""


  def __init__(				self    :					Tuple							,	UpperCamelCase__    :					Union[str, Any]=3							,	UpperCamelCase__    :					Dict=224							,	UpperCamelCase__    :					str=1.0							,	UpperCamelCase__    :					List[Any]=8							,	UpperCamelCase__    :					Union[str, Any]=8							,	UpperCamelCase__    :					str=6							,	UpperCamelCase__    :					str=32							,	UpperCamelCase__    :					str=True							,	UpperCamelCase__    :					int=True							,	UpperCamelCase__    :					str="relu6"							,	UpperCamelCase__    :					Tuple=True							,	UpperCamelCase__    :					List[str]=0.8							,	UpperCamelCase__    :					List[str]=0.02							,	UpperCamelCase__    :					str=0.001							,	UpperCamelCase__    :					Dict=255							,	**UpperCamelCase__    :					Tuple							,	)     ->						List[Any]:
    super().__init__(**UpperCamelCase__  )

    if depth_multiplier <= 0:
      raise ValueError('''depth_multiplier must be greater than zero.'''  )

    _UpperCamelCase       			=num_channels
    _UpperCamelCase       			=image_size
    _UpperCamelCase       			=depth_multiplier
    _UpperCamelCase       			=depth_divisible_by
    _UpperCamelCase       			=min_depth
    _UpperCamelCase       			=expand_ratio
    _UpperCamelCase       			=output_stride
    _UpperCamelCase       			=first_layer_is_expansion
    _UpperCamelCase       			=finegrained_output
    _UpperCamelCase       			=hidden_act
    _UpperCamelCase       			=tf_padding
    _UpperCamelCase       			=classifier_dropout_prob
    _UpperCamelCase       			=initializer_range
    _UpperCamelCase       			=layer_norm_eps
    _UpperCamelCase       			=semantic_loss_ignore_index







class 		UpperCAmelCase   (				lowercase_):


  """simple docstring"""







  lowerCAmelCase_					=				version.parse("""1.11""")


  @property
  def   UpperCamelCase__      (				self    :					str  )     ->						Mapping[str, Mapping[int, str]]:
    return OrderedDict([('''pixel_values''', {0: '''batch'''})]  )


  @property
  def   UpperCamelCase__      (				self    :					Optional[Any]  )     ->						Mapping[str, Mapping[int, str]]:
    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    :					List[Any]  )     ->						float:
    return 1E-4






