

'''simple docstring'''



import torch
import torch.nn as nn
from transformers.modeling_utils import ModuleUtilsMixin
from transformers.models.ta.modeling_ta import TaBlock, TaConfig, TaLayerNorm

from ...configuration_utils import ConfigMixin, register_to_config
from ...models import ModelMixin



class lowerCamelCase			(  lowercase_	,						lowercase_	,						lowercase_						):



			'''simple docstring'''






			@register_to_config
			def __init__(				self	:						List[Any]		,      lowerCAmelCase_	:						int		,      lowerCAmelCase_	:						int		,      lowerCAmelCase_	:						int		,      lowerCAmelCase_	:						float		,      lowerCAmelCase_	:						int		,      lowerCAmelCase_	:						int		,      lowerCAmelCase_	:						int		,      lowerCAmelCase_	:						int		,      lowerCAmelCase_	:						str		,      lowerCAmelCase_	:						bool = False		,      )      ->		str:





									'''simple docstring'''
									super().__init__()

									A__					:       List[str]     =nn.Embedding(lowerCAmelCase_		,      lowerCAmelCase_			)

									A__					:       Dict     =nn.Embedding(lowerCAmelCase_		,      lowerCAmelCase_			)
									A__					:       Optional[int]     =False

									A__					:       Tuple     =nn.Dropout(p=lowerCAmelCase_			)

									A__					:       Union[str, Any]     =TaConfig(
									    vocab_size=lowerCAmelCase_		,      d_model=lowerCAmelCase_		,      num_heads=lowerCAmelCase_		,      d_kv=lowerCAmelCase_		,      d_ff=lowerCAmelCase_		,      dropout_rate=lowerCAmelCase_		,      feed_forward_proj=lowerCAmelCase_		,      is_decoder=lowerCAmelCase_		,      is_encoder_decoder=lowerCAmelCase_		,      )

									A__					:       List[Any]     =nn.ModuleList()
									for lyr_num in range(lowerCAmelCase_			):
															A__					:       Any     =TaBlock(lowerCAmelCase_			)
															self.encoders.append(lowerCAmelCase_			)

									A__					:       Any     =TaLayerNorm(lowerCAmelCase_			)
									A__					:       Any     =nn.Dropout(p=lowerCAmelCase_			)



			def lowercase__						(				self	:						List[str]		,      lowerCAmelCase_	:						Tuple		,      lowerCAmelCase_	:						Union[str, Any]			)      ->		Optional[Any]:





									'''simple docstring'''
									A__					:       Optional[int]     =self.token_embedder(lowerCAmelCase_			)

									A__					:       List[Any]     =encoder_input_tokens.shape[1]
									A__					:       Optional[int]     =torch.arange(lowerCAmelCase_		,      device=encoder_input_tokens.device			)
									x += self.position_encoding(lowerCAmelCase_			)

									A__					:       Dict     =self.dropout_pre(lowerCAmelCase_			)

									# inverted the attention mask
									A__					:       Any     =encoder_input_tokens.size()
									A__					:       List[str]     =self.get_extended_attention_mask(lowerCAmelCase_		,      lowerCAmelCase_			)

									for lyr in self.encoders:
															A__					:       int     =lyr(lowerCAmelCase_		,      lowerCAmelCase_			)[0]
									A__					:       Optional[Any]     =self.layer_norm(lowerCAmelCase_			)

									return self.dropout_post(lowerCAmelCase_			), encoder_inputs_mask




'''simple docstring'''



from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_speech_available, is_torch_available


__snake_case			:     Any										=      {
    'configuration_audio_spectrogram_transformer': [
        'AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'ASTConfig',
    ]
}

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__snake_case			:     Optional[int]										=      [
		    'AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST',
		    'ASTForAudioClassification',
		    'ASTModel',
		    'ASTPreTrainedModel',
		]

try:
		if not is_speech_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__snake_case			:     List[Any]										=      ['ASTFeatureExtractor']

if TYPE_CHECKING:
		from .configuration_audio_spectrogram_transformer import (
		    AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP,
		    ASTConfig,
		)

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_audio_spectrogram_transformer import (
				    AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
				    ASTForAudioClassification,
				    ASTModel,
				    ASTPreTrainedModel,
				)

		try:
				if not is_speech_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .feature_extraction_audio_spectrogram_transformer import ASTFeatureExtractor


else:
		import sys

		__snake_case			:     Optional[Any]										=      _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)

