




'''simple docstring'''





import sys
from dataclasses import dataclass
from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, Union

import pandas as pd
import pyarrow as pa

import datasets
import datasets.config
from datasets.features.features import require_storage_cast
from datasets.table import table_cast


if TYPE_CHECKING:
  import sqlitea

  import sqlalchemy


a		:	List[Any]       =      datasets.utils.logging.get_logger(__name__)




@dataclass
class      UpperCamelCase       (	datasets.BuilderConfig       ):
  a     :Union[str, "sqlalchemy.sql.Selectable"]          =					None
  a     :Union[str, "sqlalchemy.engine.Connection", "sqlalchemy.engine.Engine", "sqlite3.Connection"]          =					None
  a     :Optional[Union[str, List[str]]]          =					None
  a     :bool          =					True
  a     :Optional[Union[List, Tuple, Dict]]          =					None
  a     :Optional[Union[List, Dict]]          =					None
  a     :Optional[List[str]]          =					None
  a     :Optional[int]          =					1_0_0_0_0
  a     :Optional[datasets.Features]          =					None



  def     a_							(			self ):







      '''simple docstring'''


      if self.sql is None:
          raise ValueError("""sql must be specified""" )
      if self.con is None:
          raise ValueError("""con must be specified""" )



  def     a_							(			self		,     __lowerCAmelCase		,     __lowerCAmelCase = None		,     ):







      '''simple docstring'''


      _a				:							Optional[int]							       =      config_kwargs.copy()
      # We need to stringify the Selectable object to make its hash deterministic

      # The process of stringifying is explained here: http://docs.sqlalchemy.org/en/latest/faq/sqlexpressions.html
      _a				:							List[str]							       =      config_kwargs["""sql"""]
      if not isinstance(__lowerCAmelCase		,     __lowerCAmelCase ):
          if datasets.config.SQLALCHEMY_AVAILABLE and "sqlalchemy" in sys.modules:
              import sqlalchemy

              if isinstance(__lowerCAmelCase		,     sqlalchemy.sql.Selectable ):
                  _a				:							Optional[int]							       =      sqlalchemy.create_engine(config_kwargs["""con"""].split("""://""" )[0] + """://""" )
                  _a				:							Tuple							       =      str(sql.compile(dialect=engine.dialect ) )
                  _a				:							int							       =      sql_str
              else:
                  raise TypeError(
                      f'''Supported types for \'sql\' are string and sqlalchemy.sql.Selectable but got {type(__lowerCAmelCase )}: {sql}''' )
          else:
              raise TypeError(
                  f'''Supported types for \'sql\' are string and sqlalchemy.sql.Selectable but got {type(__lowerCAmelCase )}: {sql}''' )
      _a				:							Any							       =      config_kwargs["""con"""]
      if not isinstance(__lowerCAmelCase		,     __lowerCAmelCase ):
          _a				:							Tuple							       =      id(__lowerCAmelCase )
          logger.info(
              f'''SQL connection \'con\' of type {type(__lowerCAmelCase )} couldn\'t be hashed properly. To enable hashing, specify \'con\' as URI string instead.''' )

      return super().create_config_id(__lowerCAmelCase		,     custom_features=__lowerCAmelCase )



  @property
  def     a_							(			self ):







      '''simple docstring'''


      _a				:							Any							       =      {
          """index_col""": self.index_col,
          """columns""": self.columns,
          """params""": self.params,
          """coerce_float""": self.coerce_float,
          """parse_dates""": self.parse_dates,
      }
      return pd_read_sql_kwargs






class      UpperCamelCase       (	datasets.ArrowBasedBuilder       ):
  a     :List[Any]          =					SqlConfig



  def     a_							(			self ):







      '''simple docstring'''


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



  def     a_							(			self		,     __lowerCAmelCase ):







      '''simple docstring'''


      return [datasets.SplitGenerator(name=datasets.Split.TRAIN		,     gen_kwargs={} )]



  def     a_							(			self		,     __lowerCAmelCase ):







      '''simple docstring'''


      if self.config.features is not None:
          _a				:							List[Any]							       =      self.config.features.arrow_schema
          if all(not require_storage_cast(__lowerCAmelCase ) for feature in self.config.features.values() ):
              # cheaper cast
              _a				:							str							       =      pa.Table.from_arrays([pa_table[field.name] for field in schema]		,     schema=__lowerCAmelCase )
          else:
              # more expensive cast; allows str <-> int/float or str to Audio for example
              _a				:							Optional[Any]							       =      table_cast(__lowerCAmelCase		,     __lowerCAmelCase )
      return pa_table



  def     a_							(			self ):







      '''simple docstring'''


      _a				:							Any							       =      self.config.chunksize
      _a				:							Dict							       =      pd.read_sql(
          self.config.sql		,     self.config.con		,     chunksize=__lowerCAmelCase		,     **self.config.pd_read_sql_kwargs )
      _a				:							int							       =      [sql_reader] if chunksize is None else sql_reader
      for chunk_idx, df in enumerate(__lowerCAmelCase ):
          _a				:							str							       =      pa.Table.from_pandas(__lowerCAmelCase )
          yield chunk_idx, self._cast_table(__lowerCAmelCase )



import copy
from typing import Dict

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto.configuration_auto import CONFIG_MAPPING
from ..bit import BitConfig


lowerCAmelCase      :				List[Any]     			=logging.get_logger(__name__)

lowerCAmelCase      :				Optional[int]     			={
    "google/vit-hybrid-base-bit-384": "https://huggingface.co/vit-hybrid-base-bit-384/resolve/main/config.json",
    # See all ViT hybrid models at https://huggingface.co/models?filter=vit
}




class 						__snake_case						(			__lowerCAmelCase		):





      '''simple docstring'''






      _snake_case     		=							'vit-hybrid'



      def __init__(       self  :					str     ,	_UpperCamelCase  :					int=None     ,	_UpperCamelCase  :					Union[str, Any]=768     ,	_UpperCamelCase  :					List[Any]=12     ,	_UpperCamelCase  :					List[Any]=12     ,	_UpperCamelCase  :					Optional[int]=3072     ,	_UpperCamelCase  :					Optional[int]="gelu"     ,	_UpperCamelCase  :					int=0.0     ,	_UpperCamelCase  :					Tuple=0.0     ,	_UpperCamelCase  :					Dict=0.0_2     ,	_UpperCamelCase  :					Dict=1E-1_2     ,	_UpperCamelCase  :					Union[str, Any]=224     ,	_UpperCamelCase  :					str=1     ,	_UpperCamelCase  :					Optional[int]=3     ,	_UpperCamelCase  :					Dict=[1, 1024, 24, 24]     ,	_UpperCamelCase  :					Optional[Any]=True     ,	**_UpperCamelCase  :					List[Any]     ,	)					->str:


          """simple docstring"""


          super().__init__(**_UpperCamelCase)

          if backbone_config is None:
              logger.info("""`backbone_config` is `None`. Initializing the config with a `BiT` backbone.""")
              _lowerCamelCase  :		Tuple			    =    {
                  """global_padding""": """same""",
                  """layer_type""": """bottleneck""",
                  """depths""": [3, 4, 9],
                  """out_features""": ["""stage3"""],
                  """embedding_dynamic_padding""": True,
              }

          if isinstance(_UpperCamelCase     ,	_UpperCamelCase):
              if "model_type" in backbone_config:
                  _lowerCamelCase  :		int			    =    CONFIG_MAPPING[backbone_config["""model_type"""]]
              else:
                  logger.info(
                      """`model_type` is not found in `backbone_config`. Use `Bit` as the backbone configuration class.""")
                  _lowerCamelCase  :		Optional[int]			    =    BitConfig
              _lowerCamelCase  :		List[Any]			    =    backbone_config_class(**_UpperCamelCase)

          _lowerCamelCase  :		Any			    =    backbone_featmap_shape
          _lowerCamelCase  :		Dict			    =    backbone_config
          _lowerCamelCase  :		Tuple			    =    hidden_size
          _lowerCamelCase  :		Union[str, Any]			    =    num_hidden_layers
          _lowerCamelCase  :		Optional[Any]			    =    num_attention_heads
          _lowerCamelCase  :		Optional[Any]			    =    intermediate_size
          _lowerCamelCase  :		List[Any]			    =    hidden_act
          _lowerCamelCase  :		Dict			    =    hidden_dropout_prob
          _lowerCamelCase  :		Optional[Any]			    =    attention_probs_dropout_prob
          _lowerCamelCase  :		Union[str, Any]			    =    initializer_range
          _lowerCamelCase  :		Any			    =    layer_norm_eps
          _lowerCamelCase  :		Optional[int]			    =    image_size
          _lowerCamelCase  :		Any			    =    patch_size
          _lowerCamelCase  :		Optional[Any]			    =    num_channels
          _lowerCamelCase  :		List[str]			    =    qkv_bias




      def 						_SCREAMING_SNAKE_CASE     (       self  :					Optional[Any])					->Dict[str, any]:


          """simple docstring"""


          _lowerCamelCase  :		Dict			    =    copy.deepcopy(self.__dict__)
          _lowerCamelCase  :		List[Any]			    =    self.backbone_config.to_dict()
          _lowerCamelCase  :		List[str]			    =    self.__class__.model_type
          return output




