



import math
from typing import Optional

import numpy as np

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


__lowerCAmelCase       :					Dict      					=					logging.get_logger(__name__)

__lowerCAmelCase       :					Optional[int]      					=					{
    '''facebook/encodec_24khz''': '''https://huggingface.co/facebook/encodec_24khz/resolve/main/config.json''',
    '''facebook/encodec_48khz''': '''https://huggingface.co/facebook/encodec_48khz/resolve/main/config.json''',
}



class    _lowerCAmelCase    (				SCREAMING_SNAKE_CASE__		):





		"""simple docstring"""






		_lowerCamelCase			  =       '''encodec'''





		def __init__(					self							,    _lowercase=[1.5, 3.0, 6.0, 12.0, 24.0]							,    _lowercase=2_4_0_0_0							,    _lowercase=1							,    _lowercase=False							,    _lowercase=None							,    _lowercase=None							,    _lowercase=1_2_8							,    _lowercase=3_2							,    _lowercase=1							,    _lowercase=[8, 5, 4, 2]							,    _lowercase="weight_norm"							,    _lowercase=7							,    _lowercase=7							,    _lowercase=3							,    _lowercase=2							,    _lowercase=True							,    _lowercase="reflect"							,    _lowercase=2							,    _lowercase=2							,    _lowercase=1.0							,    _lowercase=1_0_2_4							,    _lowercase=None							,    _lowercase=True							,    **_lowercase							,    ) ->						Any:







								'''simple docstring'''

								snake_case_   : int						=			target_bandwidths
								snake_case_   : Optional[Any]						=			sampling_rate
								snake_case_   : List[str]						=			audio_channels
								snake_case_   : Union[str, Any]						=			normalize
								snake_case_   : List[str]						=			chunk_length_s
								snake_case_   : Union[str, Any]						=			overlap
								snake_case_   : Dict						=			hidden_size
								snake_case_   : Union[str, Any]						=			num_filters
								snake_case_   : Dict						=			num_residual_layers
								snake_case_   : Dict						=			upsampling_ratios
								snake_case_   : Optional[int]						=			norm_type
								snake_case_   : Optional[Any]						=			kernel_size
								snake_case_   : Dict						=			last_kernel_size
								snake_case_   : Tuple						=			residual_kernel_size
								snake_case_   : Tuple						=			dilation_growth_rate
								snake_case_   : List[Any]						=			use_causal_conv
								snake_case_   : Optional[int]						=			pad_mode
								snake_case_   : int						=			compress
								snake_case_   : int						=			num_lstm_layers
								snake_case_   : Optional[int]						=			trim_right_ratio
								snake_case_   : List[Any]						=			codebook_size
								snake_case_   : Dict						=			codebook_dim if codebook_dim is not None else hidden_size
								snake_case_   : Union[str, Any]						=			use_conv_shortcut

								if self.norm_type not in ["weight_norm", "time_group_norm"]:
														raise ValueError(
														    f'self.norm_type must be one of `"weight_norm"`, `"time_group_norm"`), got {self.norm_type}'   )

								super().__init__(**_lowercase   )





		@property
		def    UpperCAmelCase__							(					self   ) ->						Optional[int]:







								'''simple docstring'''

								if self.chunk_length_s is None:
														return None
								else:
														return int(self.chunk_length_s * self.sampling_rate   )





		@property
		def    UpperCAmelCase__							(					self   ) ->						Optional[int]:







								'''simple docstring'''

								if self.chunk_length_s is None or self.overlap is None:
														return None
								else:
														return max(1							,    int((1.0 - self.overlap) * self.chunk_length   )   )





		@property
		def    UpperCAmelCase__							(					self   ) ->						int:







								'''simple docstring'''

								snake_case_   : Optional[int]						=			np.prod(self.upsampling_ratios   )
								return math.ceil(self.sampling_rate / hop_length   )





		@property
		def    UpperCAmelCase__							(					self   ) ->						int:







								'''simple docstring'''

								return int(1_0_0_0 * self.target_bandwidths[-1] // (self.frame_rate * 1_0)   )






"""simple docstring"""





import math

import tensorflow as tf
from packaging import version
def 	__lowerCAmelCase						(		__UpperCamelCase      :			List[Any]    ):


						'''simple docstring'''






						snake_case_   : int						=			tf.convert_to_tensor(__UpperCamelCase    )
						snake_case_   : int						=			0.5 * (1.0 + tf.math.erf(x / tf.cast(tf.sqrt(2.0    )					, x.dtype    )    ))

						return x * cdf
def 	__lowerCAmelCase						(		__UpperCamelCase      :			List[str]    ):


						'''simple docstring'''






						snake_case_   : int						=			tf.convert_to_tensor(__UpperCamelCase    )
						snake_case_   : List[Any]						=			tf.cast(math.pi					, x.dtype    )
						snake_case_   : int						=			tf.cast(0.044_715					, x.dtype    )
						snake_case_   : Optional[int]						=			0.5 * (1.0 + tf.tanh(tf.sqrt(2.0 / pi    ) * (x + coeff * tf.pow(__UpperCamelCase					, 3    ))    ))

						return x * cdf
def 	__lowerCAmelCase						(		__UpperCamelCase      :			str    ):


						'''simple docstring'''






						snake_case_   : Optional[Any]						=			tf.convert_to_tensor(__UpperCamelCase    )

						return x * tf.tanh(tf.math.softplus(__UpperCamelCase    )    )
def 	__lowerCAmelCase						(		__UpperCamelCase      :			Any    ):


						'''simple docstring'''






						snake_case_   : str						=			tf.convert_to_tensor(__UpperCamelCase    )
						snake_case_   : int						=			tf.cast(0.044_715					, x.dtype    )
						snake_case_   : Optional[int]						=			tf.cast(0.7_978_845_608					, x.dtype    )

						return 0.5 * x * (1.0 + tf.tanh(x * coeffa * (1.0 + coeffa * x * x)    ))
def 	__lowerCAmelCase						(		__UpperCamelCase      :			List[str]    ):


						'''simple docstring'''






						snake_case_   : Tuple						=			tf.convert_to_tensor(__UpperCamelCase    )
						snake_case_   : str						=			tf.cast(1.702					, x.dtype    )
						return x * tf.math.sigmoid(coeff * x    )
def 	__lowerCAmelCase						(		__UpperCamelCase      :			int    ):


						'''simple docstring'''






						return tf.clip_by_value(_gelu(__UpperCamelCase    )					, -1_0					, 1_0    )
def 	__lowerCAmelCase						(		__UpperCamelCase      :			Optional[int]					, __UpperCamelCase      :			List[str]=-1    ):


						'''simple docstring'''






						snake_case_			,		snake_case_   : List[Any]						=			tf.split(__UpperCamelCase					, 2					, axis=__UpperCamelCase    )
						return a * tf.math.sigmoid(__UpperCamelCase    )


if version.parse(tf.version.VERSION) >= version.parse('''2.4'''):
					def 	__lowerCAmelCase						(		__UpperCamelCase      :			List[Any]    ):


											'''simple docstring'''






											return tf.keras.activations.gelu(__UpperCamelCase					, approximate=__UpperCamelCase    )

					__lowerCAmelCase       :					int      					=					tf.keras.activations.gelu






					__lowerCAmelCase       :					Optional[Any]      					=					approximate_gelu_wrap
else:
					__lowerCAmelCase       :					List[Any]      					=					_gelu
					__lowerCAmelCase       :					Any      					=					_gelu_new


__lowerCAmelCase       :					Dict      					=					{
    '''gelu''': gelu,
    '''gelu_10''': gelu_aa,
    '''gelu_fast''': gelu_fast,
    '''gelu_new''': gelu_new,
    '''glu''': glu,
    '''mish''': mish,
    '''quick_gelu''': quick_gelu,
    '''relu''': tf.keras.activations.relu,
    '''sigmoid''': tf.keras.activations.sigmoid,
    '''silu''': tf.keras.activations.swish,
    '''swish''': tf.keras.activations.swish,
    '''tanh''': tf.keras.activations.tanh,
}






def 	__lowerCAmelCase						(		__UpperCamelCase      :			Any    ):


						'''simple docstring'''






						if activation_string in ACTaFN:
												return ACTaFN[activation_string]
						else:
												raise KeyError(F'function {activation_string} not found in ACT2FN mapping {list(ACTaFN.keys()    )}'    )

