


import flax.linen as nn
import jax.numpy as jnp

from .attention_flax import FlaxTransformeraDModel
from .resnet_flax import FlaxDownsampleaD, FlaxResnetBlockaD, FlaxUpsampleaD

class 		__a				(    nn.Module      ):
		_a     :  int
		_a     :  int
		_a     :  float           =     0.0
		_a     :  int           =     1
		_a     :  int           =     1
		_a     :  bool           =     True
		_a     :  bool           =     False
		_a     :  bool           =     False
		_a     :  bool           =     False
		_a     :  jnp.dtype           =     jnp.floataa
		def      UpperCAmelCase__    (      self						)			->	List[str]:




									"""simple docstring"""





									_UpperCAmelCase					=      []
									_UpperCAmelCase					=      []

									for i in range(self.num_layers						):
																_UpperCAmelCase					=      self.in_channels if i == 0 else self.out_channels

																_UpperCAmelCase					=      FlaxResnetBlockaD(
																    in_channels=_SCREAMING_SNAKE_CASE      ,   out_channels=self.out_channels      ,   dropout_prob=self.dropout      ,   dtype=self.dtype      ,   )
																resnets.append(_SCREAMING_SNAKE_CASE						)

																_UpperCAmelCase					=      FlaxTransformeraDModel(
																    in_channels=self.out_channels      ,   n_heads=self.num_attention_heads      ,   d_head=self.out_channels // self.num_attention_heads      ,   depth=1      ,   use_linear_projection=self.use_linear_projection      ,   only_cross_attention=self.only_cross_attention      ,   use_memory_efficient_attention=self.use_memory_efficient_attention      ,   dtype=self.dtype      ,   )
																attentions.append(_SCREAMING_SNAKE_CASE						)

									_UpperCAmelCase					=      resnets
									_UpperCAmelCase					=      attentions

									if self.add_downsample:
																_UpperCAmelCase					=      FlaxDownsampleaD(self.out_channels      ,   dtype=self.dtype						)






		def __call__(      self      ,   _SCREAMING_SNAKE_CASE      ,   _SCREAMING_SNAKE_CASE      ,   _SCREAMING_SNAKE_CASE      ,   _SCREAMING_SNAKE_CASE=True						)			->	Tuple:




									"""simple docstring"""





									_UpperCAmelCase					=      ()

									for resnet, attn in zip(self.resnets      ,   self.attentions						):
																_UpperCAmelCase					=      resnet(_SCREAMING_SNAKE_CASE      ,   _SCREAMING_SNAKE_CASE      ,   deterministic=_SCREAMING_SNAKE_CASE						)
																_UpperCAmelCase					=      attn(_SCREAMING_SNAKE_CASE      ,   _SCREAMING_SNAKE_CASE      ,   deterministic=_SCREAMING_SNAKE_CASE						)
																output_states += (hidden_states,)

									if self.add_downsample:
																_UpperCAmelCase					=      self.downsamplers_a(_SCREAMING_SNAKE_CASE						)
																output_states += (hidden_states,)

									return hidden_states, output_states



class 		__a				(    nn.Module      ):
		_a     :  int
		_a     :  int
		_a     :  float           =     0.0
		_a     :  int           =     1
		_a     :  bool           =     True
		_a     :  jnp.dtype           =     jnp.floataa
		def      UpperCAmelCase__    (      self						)			->	str:




									"""simple docstring"""





									_UpperCAmelCase					=      []

									for i in range(self.num_layers						):
																_UpperCAmelCase					=      self.in_channels if i == 0 else self.out_channels

																_UpperCAmelCase					=      FlaxResnetBlockaD(
																    in_channels=_SCREAMING_SNAKE_CASE      ,   out_channels=self.out_channels      ,   dropout_prob=self.dropout      ,   dtype=self.dtype      ,   )
																resnets.append(_SCREAMING_SNAKE_CASE						)
									_UpperCAmelCase					=      resnets

									if self.add_downsample:
																_UpperCAmelCase					=      FlaxDownsampleaD(self.out_channels      ,   dtype=self.dtype						)






		def __call__(      self      ,   _SCREAMING_SNAKE_CASE      ,   _SCREAMING_SNAKE_CASE      ,   _SCREAMING_SNAKE_CASE=True						)			->	List[str]:




									"""simple docstring"""





									_UpperCAmelCase					=      ()

									for resnet in self.resnets:
																_UpperCAmelCase					=      resnet(_SCREAMING_SNAKE_CASE      ,   _SCREAMING_SNAKE_CASE      ,   deterministic=_SCREAMING_SNAKE_CASE						)
																output_states += (hidden_states,)

									if self.add_downsample:
																_UpperCAmelCase					=      self.downsamplers_a(_SCREAMING_SNAKE_CASE						)
																output_states += (hidden_states,)

									return hidden_states, output_states



class 		__a				(    nn.Module      ):
		_a     :  int
		_a     :  int
		_a     :  int
		_a     :  float           =     0.0
		_a     :  int           =     1
		_a     :  int           =     1
		_a     :  bool           =     True
		_a     :  bool           =     False
		_a     :  bool           =     False
		_a     :  bool           =     False
		_a     :  jnp.dtype           =     jnp.floataa
		def      UpperCAmelCase__    (      self						)			->	Optional[Any]:




									"""simple docstring"""





									_UpperCAmelCase					=      []
									_UpperCAmelCase					=      []

									for i in range(self.num_layers						):
																_UpperCAmelCase					=      self.in_channels if (i == self.num_layers - 1) else self.out_channels
																_UpperCAmelCase					=      self.prev_output_channel if i == 0 else self.out_channels

																_UpperCAmelCase					=      FlaxResnetBlockaD(
																    in_channels=resnet_in_channels + res_skip_channels      ,   out_channels=self.out_channels      ,   dropout_prob=self.dropout      ,   dtype=self.dtype      ,   )
																resnets.append(_SCREAMING_SNAKE_CASE						)

																_UpperCAmelCase					=      FlaxTransformeraDModel(
																    in_channels=self.out_channels      ,   n_heads=self.num_attention_heads      ,   d_head=self.out_channels // self.num_attention_heads      ,   depth=1      ,   use_linear_projection=self.use_linear_projection      ,   only_cross_attention=self.only_cross_attention      ,   use_memory_efficient_attention=self.use_memory_efficient_attention      ,   dtype=self.dtype      ,   )
																attentions.append(_SCREAMING_SNAKE_CASE						)

									_UpperCAmelCase					=      resnets
									_UpperCAmelCase					=      attentions

									if self.add_upsample:
																_UpperCAmelCase					=      FlaxUpsampleaD(self.out_channels      ,   dtype=self.dtype						)






		def __call__(      self      ,   _SCREAMING_SNAKE_CASE      ,   _SCREAMING_SNAKE_CASE      ,   _SCREAMING_SNAKE_CASE      ,   _SCREAMING_SNAKE_CASE      ,   _SCREAMING_SNAKE_CASE=True						)			->	Optional[Any]:




									"""simple docstring"""





									for resnet, attn in zip(self.resnets      ,   self.attentions						):
																# pop res hidden states
																_UpperCAmelCase					=      res_hidden_states_tuple[-1]
																_UpperCAmelCase					=      res_hidden_states_tuple[:-1]
																_UpperCAmelCase					=      jnp.concatenate((hidden_states, res_hidden_states)      ,   axis=-1						)

																_UpperCAmelCase					=      resnet(_SCREAMING_SNAKE_CASE      ,   _SCREAMING_SNAKE_CASE      ,   deterministic=_SCREAMING_SNAKE_CASE						)
																_UpperCAmelCase					=      attn(_SCREAMING_SNAKE_CASE      ,   _SCREAMING_SNAKE_CASE      ,   deterministic=_SCREAMING_SNAKE_CASE						)

									if self.add_upsample:
																_UpperCAmelCase					=      self.upsamplers_a(_SCREAMING_SNAKE_CASE						)

									return hidden_states



class 		__a				(    nn.Module      ):
		_a     :  int
		_a     :  int
		_a     :  int
		_a     :  float           =     0.0
		_a     :  int           =     1
		_a     :  bool           =     True
		_a     :  jnp.dtype           =     jnp.floataa
		def      UpperCAmelCase__    (      self						)			->	Optional[int]:




									"""simple docstring"""





									_UpperCAmelCase					=      []

									for i in range(self.num_layers						):
																_UpperCAmelCase					=      self.in_channels if (i == self.num_layers - 1) else self.out_channels
																_UpperCAmelCase					=      self.prev_output_channel if i == 0 else self.out_channels

																_UpperCAmelCase					=      FlaxResnetBlockaD(
																    in_channels=resnet_in_channels + res_skip_channels      ,   out_channels=self.out_channels      ,   dropout_prob=self.dropout      ,   dtype=self.dtype      ,   )
																resnets.append(_SCREAMING_SNAKE_CASE						)

									_UpperCAmelCase					=      resnets

									if self.add_upsample:
																_UpperCAmelCase					=      FlaxUpsampleaD(self.out_channels      ,   dtype=self.dtype						)






		def __call__(      self      ,   _SCREAMING_SNAKE_CASE      ,   _SCREAMING_SNAKE_CASE      ,   _SCREAMING_SNAKE_CASE      ,   _SCREAMING_SNAKE_CASE=True						)			->	List[Any]:




									"""simple docstring"""





									for resnet in self.resnets:
																# pop res hidden states
																_UpperCAmelCase					=      res_hidden_states_tuple[-1]
																_UpperCAmelCase					=      res_hidden_states_tuple[:-1]
																_UpperCAmelCase					=      jnp.concatenate((hidden_states, res_hidden_states)      ,   axis=-1						)

																_UpperCAmelCase					=      resnet(_SCREAMING_SNAKE_CASE      ,   _SCREAMING_SNAKE_CASE      ,   deterministic=_SCREAMING_SNAKE_CASE						)

									if self.add_upsample:
																_UpperCAmelCase					=      self.upsamplers_a(_SCREAMING_SNAKE_CASE						)

									return hidden_states



class 		__a				(    nn.Module      ):
		_a     :  int
		_a     :  float           =     0.0
		_a     :  int           =     1
		_a     :  int           =     1
		_a     :  bool           =     False
		_a     :  bool           =     False
		_a     :  jnp.dtype           =     jnp.floataa
		def      UpperCAmelCase__    (      self						)			->	Any:




									"""simple docstring"""





									_UpperCAmelCase					=      [
									    FlaxResnetBlockaD(
									        in_channels=self.in_channels      ,   out_channels=self.in_channels      ,   dropout_prob=self.dropout      ,   dtype=self.dtype      ,   )
									]

									_UpperCAmelCase					=      []

									for _ in range(self.num_layers						):
																_UpperCAmelCase					=      FlaxTransformeraDModel(
																    in_channels=self.in_channels      ,   n_heads=self.num_attention_heads      ,   d_head=self.in_channels // self.num_attention_heads      ,   depth=1      ,   use_linear_projection=self.use_linear_projection      ,   use_memory_efficient_attention=self.use_memory_efficient_attention      ,   dtype=self.dtype      ,   )
																attentions.append(_SCREAMING_SNAKE_CASE						)

																_UpperCAmelCase					=      FlaxResnetBlockaD(
																    in_channels=self.in_channels      ,   out_channels=self.in_channels      ,   dropout_prob=self.dropout      ,   dtype=self.dtype      ,   )
																resnets.append(_SCREAMING_SNAKE_CASE						)

									_UpperCAmelCase					=      resnets
									_UpperCAmelCase					=      attentions






		def __call__(      self      ,   _SCREAMING_SNAKE_CASE      ,   _SCREAMING_SNAKE_CASE      ,   _SCREAMING_SNAKE_CASE      ,   _SCREAMING_SNAKE_CASE=True						)			->	int:




									"""simple docstring"""





									_UpperCAmelCase					=      self.resnets[0](_SCREAMING_SNAKE_CASE      ,   _SCREAMING_SNAKE_CASE						)
									for attn, resnet in zip(self.attentions      ,   self.resnets[1:]						):
																_UpperCAmelCase					=      attn(_SCREAMING_SNAKE_CASE      ,   _SCREAMING_SNAKE_CASE      ,   deterministic=_SCREAMING_SNAKE_CASE						)
																_UpperCAmelCase					=      resnet(_SCREAMING_SNAKE_CASE      ,   _SCREAMING_SNAKE_CASE      ,   deterministic=_SCREAMING_SNAKE_CASE						)

									return hidden_states




import warnings
from contextlib import contextmanager

from ....processing_utils import ProcessorMixin

class 		__a				(    UpperCAmelCase      ):
		_a     :  Optional[int]           =     'MCTCTFeatureExtractor'
		_a     :  int           =     'AutoTokenizer'
		def __init__(      self      ,   _SCREAMING_SNAKE_CASE      ,   _SCREAMING_SNAKE_CASE						)			->	List[str]:




									"""simple docstring"""





									super().__init__(_SCREAMING_SNAKE_CASE      ,   _SCREAMING_SNAKE_CASE						)
									_UpperCAmelCase					=      self.feature_extractor
									_UpperCAmelCase					=      False
		def __call__(      self      ,   *_SCREAMING_SNAKE_CASE      ,   **_SCREAMING_SNAKE_CASE						)			->	Tuple:




									"""simple docstring"""





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

									if "raw_speech" in kwargs:
																warnings.warn('Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead.'						)
																_UpperCAmelCase					=      kwargs.pop('raw_speech'						)
									else:
																_UpperCAmelCase					=      kwargs.pop('audio'      ,   _SCREAMING_SNAKE_CASE						)
									_UpperCAmelCase					=      kwargs.pop('sampling_rate'      ,   _SCREAMING_SNAKE_CASE						)
									_UpperCAmelCase					=      kwargs.pop('text'      ,   _SCREAMING_SNAKE_CASE						)
									if len(_SCREAMING_SNAKE_CASE						) > 0:
																_UpperCAmelCase					=      args[0]
																_UpperCAmelCase					=      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:
																_UpperCAmelCase					=      self.feature_extractor(_SCREAMING_SNAKE_CASE      ,   *_SCREAMING_SNAKE_CASE      ,   sampling_rate=_SCREAMING_SNAKE_CASE      ,   **_SCREAMING_SNAKE_CASE						)
									if text is not None:
																_UpperCAmelCase					=      self.tokenizer(_SCREAMING_SNAKE_CASE      ,   **_SCREAMING_SNAKE_CASE						)

									if text is None:
																return inputs
									elif audio is None:
																return encodings
									else:
																_UpperCAmelCase					=      encodings['input_ids']
																return inputs
		def      UpperCAmelCase__    (      self      ,   *_SCREAMING_SNAKE_CASE      ,   **_SCREAMING_SNAKE_CASE						)			->	Optional[int]:




									"""simple docstring"""





									return self.tokenizer.batch_decode(*_SCREAMING_SNAKE_CASE      ,   **_SCREAMING_SNAKE_CASE						)
		def      UpperCAmelCase__    (      self      ,   *_SCREAMING_SNAKE_CASE      ,   **_SCREAMING_SNAKE_CASE						)			->	str:




									"""simple docstring"""





									if self._in_target_context_manager:
																return self.current_processor.pad(*_SCREAMING_SNAKE_CASE      ,   **_SCREAMING_SNAKE_CASE						)

									_UpperCAmelCase					=      kwargs.pop('input_features'      ,   _SCREAMING_SNAKE_CASE						)
									_UpperCAmelCase					=      kwargs.pop('labels'      ,   _SCREAMING_SNAKE_CASE						)
									if len(_SCREAMING_SNAKE_CASE						) > 0:
																_UpperCAmelCase					=      args[0]
																_UpperCAmelCase					=      args[1:]

									if input_features is not None:
																_UpperCAmelCase					=      self.feature_extractor.pad(_SCREAMING_SNAKE_CASE      ,   *_SCREAMING_SNAKE_CASE      ,   **_SCREAMING_SNAKE_CASE						)
									if labels is not None:
																_UpperCAmelCase					=      self.tokenizer.pad(_SCREAMING_SNAKE_CASE      ,   **_SCREAMING_SNAKE_CASE						)

									if labels is None:
																return input_features
									elif input_features is None:
																return labels
									else:
																_UpperCAmelCase					=      labels['input_ids']
																return input_features
		def      UpperCAmelCase__    (      self      ,   *_SCREAMING_SNAKE_CASE      ,   **_SCREAMING_SNAKE_CASE						)			->	int:




									"""simple docstring"""





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






		@contextmanager
		def      UpperCAmelCase__    (      self						)			->	Optional[Any]:




									"""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.'						)
									_UpperCAmelCase					=      True
									_UpperCAmelCase					=      self.tokenizer
									yield
									_UpperCAmelCase					=      self.feature_extractor
									_UpperCAmelCase					=      False
