



"""simple docstring"""




from ...configuration_utils import PretrainedConfig
from ...utils import logging


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

lowerCAmelCase__		:					Dict							={
    '''facebook/s2t-small-librispeech-asr''': (
        '''https://huggingface.co/facebook/s2t-small-librispeech-asr/resolve/main/config.json'''
    ),
    # See all Speech2Text models at https://huggingface.co/models?filter=speech_to_text
}

class        UpperCAmelCase_  (       snake_case_	):

						'''simple docstring'''




						UpperCamelCase__      :			Union[str, Any]      =  '''speech_to_text'''
						UpperCamelCase__      :			Any      =  ['''past_key_values''']
						UpperCamelCase__      :			int      =  {'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}






						def __init__(   self				,							_A=10_000				,							_A=12				,							_A=2_048				,							_A=4				,							_A=6				,							_A=2_048				,							_A=4				,							_A=0.0				,							_A=0.0				,							_A=True				,							_A=True				,							_A="relu"				,							_A=256				,							_A=0.1				,							_A=0.0				,							_A=0.0				,							_A=0.0_2				,							_A=2				,							_A=True				,							_A=1				,							_A=0				,							_A=2				,							_A=6_000				,							_A=1_024				,							_A=2				,							_A=(5, 5)				,							_A=1_024				,							_A=80				,							_A=1				,							**_A				,							):







													'''simple docstring'''

													__SCREAMING_SNAKE_CASE									= vocab_size
													__SCREAMING_SNAKE_CASE									= d_model
													__SCREAMING_SNAKE_CASE									= encoder_ffn_dim
													__SCREAMING_SNAKE_CASE									= encoder_layers
													__SCREAMING_SNAKE_CASE									= encoder_attention_heads
													__SCREAMING_SNAKE_CASE									= decoder_ffn_dim
													__SCREAMING_SNAKE_CASE									= decoder_layers
													__SCREAMING_SNAKE_CASE									= decoder_attention_heads
													__SCREAMING_SNAKE_CASE									= dropout
													__SCREAMING_SNAKE_CASE									= attention_dropout
													__SCREAMING_SNAKE_CASE									= activation_dropout
													__SCREAMING_SNAKE_CASE									= activation_function
													__SCREAMING_SNAKE_CASE									= init_std
													__SCREAMING_SNAKE_CASE									= encoder_layerdrop
													__SCREAMING_SNAKE_CASE									= decoder_layerdrop
													__SCREAMING_SNAKE_CASE									= use_cache
													__SCREAMING_SNAKE_CASE									= encoder_layers
													__SCREAMING_SNAKE_CASE									= scale_embedding  # scale factor will be sqrt(d_model) if True
													__SCREAMING_SNAKE_CASE									= max_source_positions
													__SCREAMING_SNAKE_CASE									= max_target_positions
													__SCREAMING_SNAKE_CASE									= num_conv_layers
													__SCREAMING_SNAKE_CASE									= list(_A		)
													__SCREAMING_SNAKE_CASE									= conv_channels
													__SCREAMING_SNAKE_CASE									= input_feat_per_channel
													__SCREAMING_SNAKE_CASE									= input_channels

													if len(self.conv_kernel_sizes		) != self.num_conv_layers:
																				raise ValueError(
																				    'Configuration for convolutional module is incorrect. '
																				    'It is required that `len(config.conv_kernel_sizes)` == `config.num_conv_layers` '
																				    f"""but is `len(config.conv_kernel_sizes) = {len(self.conv_kernel_sizes		)}`, """
																				    f"""`config.num_conv_layers = {self.num_conv_layers}`."""		)

													super().__init__(
													    pad_token_id=_A				,							bos_token_id=_A				,							eos_token_id=_A				,							is_encoder_decoder=_A				,							decoder_start_token_id=_A				,							**_A				,							)











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_  (       UpperCamelCase_	):

						'''simple docstring'''




						def __init__(   self				,							_A				,							_A				,							_A = None				,							_A = None				,							_A = False				,							**_A				,							):







													'''simple docstring'''

													super().__init__(features=_A				,							cache_dir=_A				,							keep_in_memory=_A				,							**_A		)
													__SCREAMING_SNAKE_CASE									= Sql(
													    cache_dir=_A				,							features=_A				,							sql=_A				,							con=_A				,							**_A				,							)






						def 	_A     (   self		):







													'''simple docstring'''

													__SCREAMING_SNAKE_CASE									= None
													__SCREAMING_SNAKE_CASE									= None
													__SCREAMING_SNAKE_CASE									= None
													__SCREAMING_SNAKE_CASE									= None

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

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







class        UpperCAmelCase_  :

						'''simple docstring'''




						def __init__(   self				,							_A				,							_A				,							_A				,							_A = None				,							_A = None				,							**_A				,							):







													'''simple docstring'''

													if num_proc is not None and num_proc <= 0:
																				raise ValueError(f"""num_proc {num_proc} must be an integer > 0."""		)

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






						def 	_A     (   self		):







													'''simple docstring'''

													__SCREAMING_SNAKE_CASE									= self.to_sql_kwargs.pop('sql'				,							_A		)
													__SCREAMING_SNAKE_CASE									= self.to_sql_kwargs.pop('con'				,							_A		)
													__SCREAMING_SNAKE_CASE									= self.to_sql_kwargs.pop('index'				,							_A		)

													__SCREAMING_SNAKE_CASE									= self._write(index=_A				,							**self.to_sql_kwargs		)
													return written






						def 	_A     (   self				,							_A		):







													'''simple docstring'''

													__SCREAMING_SNAKE_CASE							,	__SCREAMING_SNAKE_CASE							,	__SCREAMING_SNAKE_CASE									= args
													__SCREAMING_SNAKE_CASE									= {**to_sql_kwargs, 'if_exists': 'append'} if offset > 0 else to_sql_kwargs
													__SCREAMING_SNAKE_CASE									= query_table(
													    table=self.dataset.data				,							key=slice(_A				,							offset + self.batch_size		)				,							indices=self.dataset._indices				,							)
													__SCREAMING_SNAKE_CASE									= batch.to_pandas()
													__SCREAMING_SNAKE_CASE									= df.to_sql(self.name				,							self.con				,							index=_A				,							**_A		)
													return num_rows or len(_A		)






						def 	_A     (   self				,							_A				,							**_A		):







													'''simple docstring'''

													__SCREAMING_SNAKE_CASE									= 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:
																				__SCREAMING_SNAKE_CASE							,	__SCREAMING_SNAKE_CASE									= 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				,							_A				,							_A		)]				,							)				,							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






