






"""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


_UpperCamelCase     			=  datasets.utils.logging.get_logger(__name__)







@dataclass
class 					lowerCamelCase__					(       datasets.BuilderConfig ):
    SCREAMING_SNAKE_CASE		=			None
    SCREAMING_SNAKE_CASE		=			None
    SCREAMING_SNAKE_CASE		=			None
    SCREAMING_SNAKE_CASE		=			True
    SCREAMING_SNAKE_CASE		=			None
    SCREAMING_SNAKE_CASE		=			None
    SCREAMING_SNAKE_CASE		=			None
    SCREAMING_SNAKE_CASE		=			10_000
    SCREAMING_SNAKE_CASE		=			None






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






    def 				_UpperCamelCase							( self	,A	,A = None	,):
          UpperCAmelCase							=       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
          UpperCAmelCase							=       config_kwargs["""sql"""]
          if not isinstance(A__	,A__					):
                if datasets.config.SQLALCHEMY_AVAILABLE and "sqlalchemy" in sys.modules:
                      import sqlalchemy

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

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






    @property
    def 				_UpperCamelCase							( self					):
          UpperCAmelCase							=       {
              """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 					lowerCamelCase__					(       datasets.ArrowBasedBuilder ):
    SCREAMING_SNAKE_CASE		=			SqlConfig






    def 				_UpperCamelCase							( self					):
          return datasets.DatasetInfo(features=self.config.features					)






    def 				_UpperCamelCase							( self	,A					):
          return [datasets.SplitGenerator(name=datasets.Split.TRAIN	,gen_kwargs={}					)]






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






    def 				_UpperCamelCase							( self					):
          UpperCAmelCase							=       self.config.chunksize
          UpperCAmelCase							=       pd.read_sql(
              self.config.sql	,self.config.con	,chunksize=A__	,**self.config.pd_read_sql_kwargs					)
          UpperCAmelCase							=       [sql_reader] if chunksize is None else sql_reader
          for chunk_idx, df in enumerate(A__					):
                UpperCAmelCase							=       pa.Table.from_pandas(A__					)
                yield chunk_idx, self._cast_table(A__					)





'''simple docstring'''



from typing import Mapping

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


UpperCamelCase__					:						Any											=     logging.get_logger(__name__)

class       _a (_lowerCamelCase):





       """simple docstring"""




       SCREAMING_SNAKE_CASE					=     'mt5'
       SCREAMING_SNAKE_CASE					=     ['past_key_values']






       def __init__(							self				,							A__=25_01_12				,							A__=5_12				,							A__=64				,							A__=10_24				,							A__=8				,							A__=None				,							A__=6				,							A__=32				,							A__=1_28				,							A__=0.1				,							A__=1E-6				,							A__=1.0				,							A__="gated-gelu"				,							A__=True				,							A__=True				,							A__="T5Tokenizer"				,							A__=False				,							A__=0				,							A__=1				,							A__=0				,							**A__				,							)			->	Union[str, Any]:
          super().__init__(
              is_encoder_decoder=A__				,							tokenizer_class=A__				,							tie_word_embeddings=A__				,							pad_token_id=A__				,							eos_token_id=A__				,							decoder_start_token_id=A__				,							**A__				,							)
          _SCREAMING_SNAKE_CASE          = vocab_size
          _SCREAMING_SNAKE_CASE          = d_model
          _SCREAMING_SNAKE_CASE          = d_kv
          _SCREAMING_SNAKE_CASE          = d_ff
          _SCREAMING_SNAKE_CASE          = num_layers
          _SCREAMING_SNAKE_CASE          = (
              num_decoder_layers if num_decoder_layers is not None else self.num_layers
          )  # default = symmetry
          _SCREAMING_SNAKE_CASE          = num_heads
          _SCREAMING_SNAKE_CASE          = relative_attention_num_buckets
          _SCREAMING_SNAKE_CASE          = relative_attention_max_distance
          _SCREAMING_SNAKE_CASE          = dropout_rate
          _SCREAMING_SNAKE_CASE          = layer_norm_epsilon
          _SCREAMING_SNAKE_CASE          = initializer_factor
          _SCREAMING_SNAKE_CASE          = feed_forward_proj
          _SCREAMING_SNAKE_CASE          = use_cache

          _SCREAMING_SNAKE_CASE          = self.feed_forward_proj.split("""-"""					)
          _SCREAMING_SNAKE_CASE          = act_info[-1]
          _SCREAMING_SNAKE_CASE          = act_info[0] == """gated"""

          if len(A__					) > 1 and act_info[0] != "gated" or len(A__					) > 2:
             raise ValueError(
                 F"`feed_forward_proj`: {feed_forward_proj} is not a valid activation function of the dense layer."
                 """Please make sure `feed_forward_proj` is of the format `gated-{ACT_FN}` or `{ACT_FN}`, e.g. """
                 """'gated-gelu' or 'relu'"""					)

          # for backwards compatibility
          if feed_forward_proj == "gated-gelu":
             _SCREAMING_SNAKE_CASE          = """gelu_new"""






       @property
       def 				UpperCamelCase (							self					)			->	int:
          return self.d_model






       @property
       def 				UpperCamelCase (							self					)			->	Optional[Any]:
          return self.num_heads






       @property
       def 				UpperCamelCase (							self					)			->	Dict:
          return self.num_layers






class       _a (_lowerCamelCase):





       """simple docstring"""




       @property
       # Copied from transformers.models.t5.configuration_t5.T5OnnxConfig.inputs
       def 				UpperCamelCase (							self					)			->	Mapping[str, Mapping[int, str]]:
          _SCREAMING_SNAKE_CASE          = {
              """input_ids""": {0: """batch""", 1: """encoder_sequence"""},
              """attention_mask""": {0: """batch""", 1: """encoder_sequence"""},
          }
          if self.use_past:
             _SCREAMING_SNAKE_CASE          = """past_encoder_sequence + sequence"""
             _SCREAMING_SNAKE_CASE          = {0: """batch"""}
             _SCREAMING_SNAKE_CASE          = {0: """batch""", 1: """past_decoder_sequence + sequence"""}
          else:
             _SCREAMING_SNAKE_CASE          = {0: """batch""", 1: """decoder_sequence"""}
             _SCREAMING_SNAKE_CASE          = {0: """batch""", 1: """decoder_sequence"""}

          if self.use_past:
             self.fill_with_past_key_values_(A__				,							direction="""inputs"""					)

          return common_inputs






       @property
       # Copied from transformers.models.t5.configuration_t5.T5OnnxConfig.default_onnx_opset
       def 				UpperCamelCase (							self					)			->	int:
          return 13






       @property
       def 				UpperCamelCase (							self					)			->	float:
          return 5E-4






