



'''simple docstring'''






import functools
import operator

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


UpperCamelCase__:     Tuple										=    logging.get_logger(__name__)

UpperCamelCase__:     Optional[int]										=    {
    "asapp/sew-d-tiny-100k": "https://huggingface.co/asapp/sew-d-tiny-100k/resolve/main/config.json",
    # See all SEW-D models at https://huggingface.co/models?filter=sew-d
}

class        SCREAMING_SNAKE_CASE(							A__    ):







	"""simple docstring"""






	lowerCamelCase__    				= """sew-d"""







	def __init__(		self    :  str	,    __snake_case    :  Tuple=32	,    __snake_case    :  str=768	,    __snake_case    :  Optional[Any]=12	,    __snake_case    :  Optional[int]=12	,    __snake_case    :  List[Any]=3072	,    __snake_case    :  List[Any]=2	,    __snake_case    :  Any=512	,    __snake_case    :  Optional[int]=256	,    __snake_case    :  str=True	,    __snake_case    :  str=True	,    __snake_case    :  str=("p2c", "c2p")	,    __snake_case    :  Optional[Any]="layer_norm"	,    __snake_case    :  List[str]="gelu_python"	,    __snake_case    :  Optional[int]=0.1	,    __snake_case    :  Tuple=0.1	,    __snake_case    :  Union[str, Any]=0.1	,    __snake_case    :  Optional[Any]=0.0	,    __snake_case    :  Optional[int]=0.1	,    __snake_case    :  List[str]=0.02	,    __snake_case    :  Dict=1E-7	,    __snake_case    :  Any=1E-5	,    __snake_case    :  Optional[int]="group"	,    __snake_case    :  Optional[Any]="gelu"	,    __snake_case    :  Dict=(64, 128, 128, 128, 128, 256, 256, 256, 256, 512, 512, 512, 512)	,    __snake_case    :  str=(5, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1)	,    __snake_case    :  Union[str, Any]=(10, 3, 1, 3, 1, 3, 1, 3, 1, 2, 1, 2, 1)	,    __snake_case    :  Optional[Any]=False	,    __snake_case    :  Dict=128	,    __snake_case    :  int=16	,    __snake_case    :  List[Any]=True	,    __snake_case    :  Optional[int]=0.05	,    __snake_case    :  Union[str, Any]=10	,    __snake_case    :  str=2	,    __snake_case    :  Dict=0.0	,    __snake_case    :  Any=10	,    __snake_case    :  List[Any]=0	,    __snake_case    :  Union[str, Any]="mean"	,    __snake_case    :  Tuple=False	,    __snake_case    :  Optional[int]=False	,    __snake_case    :  Optional[int]=256	,    __snake_case    :  Union[str, Any]=0	,    __snake_case    :  Union[str, Any]=1	,    __snake_case    :  Optional[int]=2	,    **__snake_case    :  Union[str, Any]	,    )    ->	Dict:
								super().__init__(**__snake_case	,    pad_token_id=__snake_case	,    bos_token_id=__snake_case	,    eos_token_id=__snake_case	)
								UpperCAmelCase				: Dict											=	hidden_size
								UpperCAmelCase				: str											=	feat_extract_norm
								UpperCAmelCase				: Union[str, Any]											=	feat_extract_activation
								UpperCAmelCase				: str											=	list(__snake_case	)
								UpperCAmelCase				: List[str]											=	list(__snake_case	)
								UpperCAmelCase				: str											=	list(__snake_case	)
								UpperCAmelCase				: List[Any]											=	conv_bias
								UpperCAmelCase				: Optional[int]											=	num_conv_pos_embeddings
								UpperCAmelCase				: Any											=	num_conv_pos_embedding_groups
								UpperCAmelCase				: str											=	len(self.conv_dim	)
								UpperCAmelCase				: Optional[int]											=	num_hidden_layers
								UpperCAmelCase				: Any											=	intermediate_size
								UpperCAmelCase				: Tuple											=	squeeze_factor
								UpperCAmelCase				: int											=	max_position_embeddings
								UpperCAmelCase				: str											=	position_buckets
								UpperCAmelCase				: Dict											=	share_att_key
								UpperCAmelCase				: Tuple											=	relative_attention
								UpperCAmelCase				: Tuple											=	norm_rel_ebd
								UpperCAmelCase				: str											=	list(__snake_case	)
								UpperCAmelCase				: int											=	hidden_act
								UpperCAmelCase				: Union[str, Any]											=	num_attention_heads
								UpperCAmelCase				: int											=	hidden_dropout
								UpperCAmelCase				: Union[str, Any]											=	attention_dropout
								UpperCAmelCase				: Optional[int]											=	activation_dropout
								UpperCAmelCase				: Tuple											=	feat_proj_dropout
								UpperCAmelCase				: Union[str, Any]											=	final_dropout
								UpperCAmelCase				: str											=	layer_norm_eps
								UpperCAmelCase				: Optional[int]											=	feature_layer_norm_eps
								UpperCAmelCase				: Optional[Any]											=	initializer_range
								UpperCAmelCase				: Optional[Any]											=	vocab_size

								if (
								    (len(self.conv_stride	) != self.num_feat_extract_layers)
								    or (len(self.conv_kernel	) != self.num_feat_extract_layers)
								    or (len(self.conv_dim	) != self.num_feat_extract_layers)
								):
															raise ValueError(
															    '''Configuration for convolutional layers is incorrect.'''
															    '''It is required that `len(config.conv_dim)` == `len(config.conv_stride)` == `len(config.conv_kernel)`,'''
															    F"""but is `len(config.conv_dim) = {len(self.conv_dim	)}`, `len(config.conv_stride)"""
															    F"""= {len(self.conv_stride	)}`, `len(config.conv_kernel) = {len(self.conv_kernel	)}`."""	)

								# fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
								UpperCAmelCase				: Optional[int]											=	apply_spec_augment
								UpperCAmelCase				: Union[str, Any]											=	mask_time_prob
								UpperCAmelCase				: Optional[Any]											=	mask_time_length
								UpperCAmelCase				: Tuple											=	mask_time_min_masks
								UpperCAmelCase				: List[Any]											=	mask_feature_prob
								UpperCAmelCase				: Optional[Any]											=	mask_feature_length
								UpperCAmelCase				: Union[str, Any]											=	mask_feature_min_masks

								# ctc loss
								UpperCAmelCase				: Any											=	ctc_loss_reduction
								UpperCAmelCase				: Any											=	ctc_zero_infinity

								# sequence classification
								UpperCAmelCase				: Optional[Any]											=	use_weighted_layer_sum
								UpperCAmelCase				: List[Any]											=	classifier_proj_size







	@property
	def   A			(		self    :  Union[str, Any]	)    ->	List[Any]:
								return functools.reduce(operator.mul	,    self.conv_stride	,    1	)










'''simple docstring'''






import contextlib
import os
import sqlitea

import pytest

from datasets import Dataset, Features, Value
from datasets.io.sql import SqlDatasetReader, SqlDatasetWriter

from ..utils import assert_arrow_memory_doesnt_increase, assert_arrow_memory_increases, require_sqlalchemy


def 				snake_case_  (      _lowerCAmelCase						:		int     ,   _lowerCAmelCase						:		Tuple						)   ->     str:
							assert isinstance(_lowerCAmelCase     ,   _lowerCAmelCase						)
							assert dataset.num_rows == 4
							assert dataset.num_columns == 3
							assert dataset.column_names == ["col_1", "col_2", "col_3"]
							for feature, expected_dtype in expected_features.items():
														assert dataset.features[feature].dtype == expected_dtype


@require_sqlalchemy
@pytest.mark.parametrize('''keep_in_memory'''     ,   [False, True]						)
def 				snake_case_  (      _lowerCAmelCase						:		Union[str, Any]     ,   _lowerCAmelCase						:		List[str]     ,   _lowerCAmelCase						:		Any     ,   _lowerCAmelCase						:		Optional[Any]						)   ->     List[str]:
							UpperCAmelCase				: int											=	tmp_path / '''cache'''
							UpperCAmelCase				: Dict											=	{'''col_1''': '''string''', '''col_2''': '''int64''', '''col_3''': '''float64'''}
							with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
														UpperCAmelCase				: Any											=	SqlDatasetReader(
														    '''dataset'''     ,   '''sqlite:///''' + sqlite_path     ,   cache_dir=_lowerCAmelCase     ,   keep_in_memory=_lowerCAmelCase						).read()
							_check_sql_dataset(_lowerCAmelCase     ,   _lowerCAmelCase						)


@require_sqlalchemy
@pytest.mark.parametrize(
    '''features'''     ,   [
        None,
        {'''col_1''': '''string''', '''col_2''': '''int64''', '''col_3''': '''float64'''},
        {'''col_1''': '''string''', '''col_2''': '''string''', '''col_3''': '''string'''},
        {'''col_1''': '''int32''', '''col_2''': '''int32''', '''col_3''': '''int32'''},
        {'''col_1''': '''float32''', '''col_2''': '''float32''', '''col_3''': '''float32'''},
    ]     ,   )
def 				snake_case_  (      _lowerCAmelCase						:		int     ,   _lowerCAmelCase						:		Any     ,   _lowerCAmelCase						:		Optional[int]     ,   _lowerCAmelCase						:		str						)   ->     Optional[int]:
							UpperCAmelCase				: Union[str, Any]											=	tmp_path / '''cache'''
							UpperCAmelCase				: Union[str, Any]											=	{'''col_1''': '''string''', '''col_2''': '''int64''', '''col_3''': '''float64'''}
							UpperCAmelCase				: str											=	features.copy() if features else default_expected_features
							UpperCAmelCase				: Optional[Any]											=	(
							    Features({feature: Value(_lowerCAmelCase						) for feature, dtype in features.items()}						) if features is not None else None
							)
							UpperCAmelCase				: Tuple											=	SqlDatasetReader('''dataset'''     ,   '''sqlite:///''' + sqlite_path     ,   features=_lowerCAmelCase     ,   cache_dir=_lowerCAmelCase						).read()
							_check_sql_dataset(_lowerCAmelCase     ,   _lowerCAmelCase						)


def 				snake_case_  (      _lowerCAmelCase						:		List[Any]						)   ->     Dict:
							with contextlib.closing(sqlitea.connect(_lowerCAmelCase						)						) as con:
														UpperCAmelCase				: Any											=	con.cursor()
														cur.execute('''SELECT * FROM dataset'''						)
														for row in cur:
																					yield row


@require_sqlalchemy
def 				snake_case_  (      _lowerCAmelCase						:		Union[str, Any]     ,   _lowerCAmelCase						:		str     ,   _lowerCAmelCase						:		Any						)   ->     Optional[int]:
							UpperCAmelCase				: Optional[int]											=	tmp_path / '''cache'''
							UpperCAmelCase				: int											=	os.path.join(_lowerCAmelCase     ,   '''tmp.sql'''						)
							UpperCAmelCase				: Any											=	SqlDatasetReader('''dataset'''     ,   '''sqlite:///''' + sqlite_path     ,   cache_dir=_lowerCAmelCase						).read()
							SqlDatasetWriter(_lowerCAmelCase     ,   '''dataset'''     ,   '''sqlite:///''' + output_sqlite_path     ,   num_proc=1						).write()

							UpperCAmelCase				: List[Any]											=	iter_sql_file(_lowerCAmelCase						)
							UpperCAmelCase				: List[Any]											=	iter_sql_file(_lowerCAmelCase						)

							for rowa, rowa in zip(_lowerCAmelCase     ,   _lowerCAmelCase						):
														assert rowa == rowa


@require_sqlalchemy
def 				snake_case_  (      _lowerCAmelCase						:		int     ,   _lowerCAmelCase						:		Optional[Any]     ,   _lowerCAmelCase						:		Union[str, Any]						)   ->     int:
							UpperCAmelCase				: Optional[Any]											=	tmp_path / '''cache'''
							UpperCAmelCase				: Any											=	os.path.join(_lowerCAmelCase     ,   '''tmp.sql'''						)
							UpperCAmelCase				: List[str]											=	SqlDatasetReader('''dataset'''     ,   '''sqlite:///''' + sqlite_path     ,   cache_dir=_lowerCAmelCase						).read()
							SqlDatasetWriter(_lowerCAmelCase     ,   '''dataset'''     ,   '''sqlite:///''' + output_sqlite_path     ,   num_proc=2						).write()

							UpperCAmelCase				: List[str]											=	iter_sql_file(_lowerCAmelCase						)
							UpperCAmelCase				: Any											=	iter_sql_file(_lowerCAmelCase						)

							for rowa, rowa in zip(_lowerCAmelCase     ,   _lowerCAmelCase						):
														assert rowa == rowa




@require_sqlalchemy
def 				snake_case_  (      _lowerCAmelCase						:		Union[str, Any]     ,   _lowerCAmelCase						:		Any     ,   _lowerCAmelCase						:		Optional[Any]						)   ->     List[Any]:
							UpperCAmelCase				: Union[str, Any]											=	tmp_path / '''cache'''
							UpperCAmelCase				: Tuple											=	os.path.join(_lowerCAmelCase     ,   '''tmp.sql'''						)
							UpperCAmelCase				: Optional[int]											=	SqlDatasetReader('''dataset'''     ,   '''sqlite:///''' + sqlite_path     ,   cache_dir=_lowerCAmelCase						).read()
							with pytest.raises(_lowerCAmelCase						):
														SqlDatasetWriter(_lowerCAmelCase     ,   '''dataset'''     ,   '''sqlite:///''' + output_sqlite_path     ,   num_proc=0						).write()





