
"""simple docstring"""
import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin




class    _snake_case  (						_lowercase       ):
							SCREAMING_SNAKE_CASE		     =						"AutoFeatureExtractor"
							SCREAMING_SNAKE_CASE		     =						"Speech2Text2Tokenizer"






							def __init__(					self						:			Optional[int]						, snake_case__						:			int						, snake_case__						:			Optional[int]    ):






												"""simple docstring"""



												super().__init__(UpperCAmelCase_						, UpperCAmelCase_    )
												__a:						Union[str, Any]		    =					self.feature_extractor
												__a:						int		    =					False






							def __call__(					self						:			Optional[int]						, *snake_case__						:			Union[str, Any]						, **snake_case__						:			Tuple    ):






												"""simple docstring"""



												if self._in_target_context_manager:
																	return self.current_processor(*UpperCAmelCase_						, **UpperCAmelCase_    )

												if "raw_speech" in kwargs:
																	warnings.warn("""Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead."""    )
																	__a:						List[Any]		    =					kwargs.pop("""raw_speech"""    )
												else:
																	__a:						Tuple		    =					kwargs.pop("""audio"""						, UpperCAmelCase_    )
												__a:						Any		    =					kwargs.pop("""sampling_rate"""						, UpperCAmelCase_    )
												__a:						Any		    =					kwargs.pop("""text"""						, UpperCAmelCase_    )
												if len(UpperCAmelCase_    ) > 0:
																	__a:						Union[str, Any]		    =					args[0]
																	__a:						List[str]		    =					args[1:]

												if audio is None and text is None:
																	raise ValueError("""You need to specify either an `audio` or `text` input to process."""    )

												if audio is not None:
																	__a:						Optional[int]		    =					self.feature_extractor(UpperCAmelCase_						, *UpperCAmelCase_						, sampling_rate=UpperCAmelCase_						, **UpperCAmelCase_    )
												if text is not None:
																	__a:						str		    =					self.tokenizer(UpperCAmelCase_						, **UpperCAmelCase_    )

												if text is None:
																	return inputs
												elif audio is None:
																	return encodings
												else:
																	__a:						Optional[Any]		    =					encodings['input_ids']
																	return inputs






							def 							__lowercase  (					self						:			Optional[int]						, *snake_case__						:			str						, **snake_case__						:			Any    ):






												"""simple docstring"""



												return self.tokenizer.batch_decode(*UpperCAmelCase_						, **UpperCAmelCase_    )






							def 							__lowercase  (					self						:			int						, *snake_case__						:			int						, **snake_case__						:			str    ):






												"""simple docstring"""



												return self.tokenizer.decode(*UpperCAmelCase_						, **UpperCAmelCase_    )






							@contextmanager
							def 							__lowercase  (					self						:			int    ):






												"""simple docstring"""



												warnings.warn(
												    """`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your """
												    """labels by using the argument `text` of the regular `__call__` method (either in the same call as """
												    """your audio inputs, or in a separate call."""    )
												__a:						List[str]		    =					True
												__a:						Dict		    =					self.tokenizer
												yield
												__a:						Optional[int]		    =					self.feature_extractor
												__a:						Dict		    =					False


"""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    _snake_case  (						_lowercase ,				_lowercase ,				_lowercase       ):






							@register_to_config
							def __init__(					self						:			str						, snake_case__						:			int						, snake_case__						:			int						, snake_case__						:			int						, snake_case__						:			float						, snake_case__						:			int						, snake_case__						:			int						, snake_case__						:			int						, snake_case__						:			int						, snake_case__						:			str						, snake_case__						:			bool = False						, ):






												"""simple docstring"""



												super().__init__()

												__a:						Optional[Any]		    =					nn.Linear(snake_case__						, snake_case__						, bias=snake_case__    )

												__a:						Optional[Any]		    =					nn.Embedding(snake_case__						, snake_case__    )
												__a:						Any		    =					False

												__a:						Any		    =					nn.Dropout(p=snake_case__    )

												__a:						List[str]		    =					TaConfig(
												    d_model=snake_case__						, num_heads=snake_case__						, d_kv=snake_case__						, d_ff=snake_case__						, feed_forward_proj=snake_case__						, dropout_rate=snake_case__						, is_decoder=snake_case__						, is_encoder_decoder=snake_case__						, )
												__a:						Optional[int]		    =					nn.ModuleList()
												for lyr_num in range(snake_case__    ):
																	__a:						Union[str, Any]		    =					TaBlock(snake_case__    )
																	self.encoders.append(snake_case__    )

												__a:						List[str]		    =					TaLayerNorm(snake_case__    )
												__a:						Optional[int]		    =					nn.Dropout(p=snake_case__    )






							def 							__lowercase  (					self						:			str						, snake_case__						:			Optional[Any]						, snake_case__						:			int    ):






												"""simple docstring"""



												__a:						str		    =					self.input_proj(snake_case__    )

												# terminal relative positional encodings
												__a:						Optional[int]		    =					encoder_inputs.shape[1]
												__a:						List[Any]		    =					torch.arange(snake_case__						, device=encoder_inputs.device    )

												__a:						Union[str, Any]		    =					encoder_inputs_mask.sum(-1    )
												__a:						str		    =					torch.roll(input_positions.unsqueeze(0    )						, tuple(seq_lens.tolist()    )						, dims=0    )
												x += self.position_encoding(snake_case__    )

												__a:						Any		    =					self.dropout_pre(snake_case__    )

												# inverted the attention mask
												__a:						Any		    =					encoder_inputs.size()
												__a:						str		    =					self.get_extended_attention_mask(snake_case__						, snake_case__    )

												for lyr in self.encoders:
																	__a:						Any		    =					lyr(snake_case__						, snake_case__    )[0]
												__a:						int		    =					self.layer_norm(snake_case__    )

												return self.dropout_post(snake_case__    ), encoder_inputs_mask
