






import time
import warnings
from abc import ABC
from copy import deepcopy
from typing import Optional

import torch

from ..utils import add_start_docstrings, logging


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


lowercase  :							Tuple			  =    r'''
    Args:
        input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
            Indices of input sequence tokens in the vocabulary.

            Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
            [`PreTrainedTokenizer.__call__`] for details.

            [What are input IDs?](../glossary#input-ids)
        scores (`torch.FloatTensor` of shape `(batch_size, config.vocab_size)`):
            Prediction scores of a language modeling head. These can be scores for each vocabulary token before SoftMax
            or scores for each vocabulary token after SoftMax.
        kwargs (`Dict[str, Any]`, *optional*):
            Additional stopping criteria specific kwargs.

    Return:
        `bool`. `False` indicates we should continue, `True` indicates we should stop.

'''




class 		UpperCAmelCase_						(	SCREAMING_SNAKE_CASE__					):


						'''simple docstring'''




						@add_start_docstrings(_SCREAMING_SNAKE_CASE				)
						def __call__(	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				**_SCREAMING_SNAKE_CASE				) ->				bool:
								raise NotImplementedError("StoppingCriteria needs to be subclassed"				)




class 		UpperCAmelCase_						(	SCREAMING_SNAKE_CASE__					):


						'''simple docstring'''




						def __init__(	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE = None				) ->				Any:
								snake_case_				:							List[str]						 =       max_length
								snake_case_				:							Any						 =       max_position_embeddings






						@add_start_docstrings(_SCREAMING_SNAKE_CASE				)
						def __call__(	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				**_SCREAMING_SNAKE_CASE				) ->				bool:
								snake_case_				:							str						 =       input_ids.shape[-1]
								snake_case_				:							Dict						 =       cur_len >= self.max_length
								if self.max_position_embeddings is not None and not is_done and cur_len >= self.max_position_embeddings:
										logger.warning_once(
										    "This is a friendly reminder - the current text generation call will exceed the model's predefined "
										    f'''maximum length ({self.max_position_embeddings}). Depending on the model, you may observe '''
										    "exceptions, performance degradation, or nothing at all."				)
								return is_done




class 		UpperCAmelCase_						(	SCREAMING_SNAKE_CASE__					):


						'''simple docstring'''




						def __init__(	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				) ->				Dict:
								warnings.warn(
								    "The class `MaxNewTokensCriteria` is deprecated. "
								    f'''Please use `MaxLengthCriteria(max_length={start_length + max_new_tokens})` '''
								    "with `max_length = start_length + max_new_tokens` instead."		,				_SCREAMING_SNAKE_CASE		,				)
								snake_case_				:							int						 =       start_length
								snake_case_				:							Union[str, Any]						 =       max_new_tokens
								snake_case_				:							List[Any]						 =       start_length + max_new_tokens






						@add_start_docstrings(_SCREAMING_SNAKE_CASE				)
						def __call__(	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				**_SCREAMING_SNAKE_CASE				) ->				bool:
								return input_ids.shape[-1] >= self.max_length




class 		UpperCAmelCase_						(	SCREAMING_SNAKE_CASE__					):


						'''simple docstring'''




						def __init__(	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE = None				) ->				List[Any]:
								snake_case_				:							Tuple						 =       max_time
								snake_case_				:							Optional[int]						 =       time.time() if initial_timestamp is None else initial_timestamp






						@add_start_docstrings(_SCREAMING_SNAKE_CASE				)
						def __call__(	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				**_SCREAMING_SNAKE_CASE				) ->				bool:
								return time.time() - self.initial_timestamp > self.max_time




class 		UpperCAmelCase_						(	SCREAMING_SNAKE_CASE__					):


						'''simple docstring'''




						@add_start_docstrings(_SCREAMING_SNAKE_CASE				)
						def __call__(	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				**_SCREAMING_SNAKE_CASE				) ->				bool:
								return any(criteria(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				) for criteria in self				)






						@property
						def       _lowerCAmelCase       (	self				) ->				Optional[int]:
								for stopping_criterium in self:
										if isinstance(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				):
												return stopping_criterium.max_length
										elif isinstance(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				):
												return stopping_criterium.max_length
								return None




def      lowerCAmelCase__	(    _a       :			StoppingCriteriaList  ,      _a       :			int    ):
		snake_case_				:							Union[str, Any]						 =       stopping_criteria.max_length
		snake_case_				:							List[Any]						 =       deepcopy(_a    )
		if stopping_max_length is not None and stopping_max_length != max_length:
				warnings.warn("You set different `max_length` for stopping criteria and `max_length` parameter"  ,      _a    )
		elif stopping_max_length is None:
				new_stopping_criteria.append(MaxLengthCriteria(max_length=_a    )    )
		return new_stopping_criteria








import functools
import operator

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


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

lowercase  :							Any			  =    {
    '''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 		UpperCAmelCase_						(	SCREAMING_SNAKE_CASE__					):


						'''simple docstring'''




						A     :   Optional[int]						=					'sew-d'






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

								# ctc loss
								snake_case_				:							Any						 =       ctc_loss_reduction
								snake_case_				:							Tuple						 =       ctc_zero_infinity

								# sequence classification
								snake_case_				:							int						 =       use_weighted_layer_sum
								snake_case_				:							List[Any]						 =       classifier_proj_size






						@property
						def       _lowerCAmelCase       (	self				) ->				Dict:
								return functools.reduce(operator.mul		,				self.conv_stride		,				1				)
