

"""simple docstring"""





import math
from typing import Optional

import numpy as np

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


__UpperCamelCase    : Tuple				 =						logging.get_logger(__name__)

__UpperCamelCase    : 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 							SCREAMING_SNAKE_CASE   (						a_			):






					"""simple docstring"""



					lowercase__												=			"encodec"







					def __init__(			self     :							List[Any]  ,lowercase_     :							Union[str, Any]=[1.5, 3.0, 6.0, 12.0, 24.0]  ,lowercase_     :							List[str]=2_4_0_0_0  ,lowercase_     :							List[str]=1  ,lowercase_     :							Optional[int]=False  ,lowercase_     :							List[Any]=None  ,lowercase_     :							Any=None  ,lowercase_     :							Optional[int]=1_2_8  ,lowercase_     :							List[Any]=3_2  ,lowercase_     :							Tuple=1  ,lowercase_     :							Optional[int]=[8, 5, 4, 2]  ,lowercase_     :							int="weight_norm"  ,lowercase_     :							int=7  ,lowercase_     :							Any=7  ,lowercase_     :							int=3  ,lowercase_     :							str=2  ,lowercase_     :							Union[str, Any]=True  ,lowercase_     :							Dict="reflect"  ,lowercase_     :							Optional[int]=2  ,lowercase_     :							Optional[Any]=2  ,lowercase_     :							Tuple=1.0  ,lowercase_     :							int=1_0_2_4  ,lowercase_     :							Union[str, Any]=None  ,lowercase_     :							Tuple=True  ,**lowercase_     :							str  ,):
						lowerCAmelCase__      :		Optional[Any]    							=      target_bandwidths
						lowerCAmelCase__      :		Optional[int]    							=      sampling_rate
						lowerCAmelCase__      :		str    							=      audio_channels
						lowerCAmelCase__      :		Tuple    							=      normalize
						lowerCAmelCase__      :		Optional[int]    							=      chunk_length_s
						lowerCAmelCase__      :		str    							=      overlap
						lowerCAmelCase__      :		Dict    							=      hidden_size
						lowerCAmelCase__      :		int    							=      num_filters
						lowerCAmelCase__      :		Tuple    							=      num_residual_layers
						lowerCAmelCase__      :		List[str]    							=      upsampling_ratios
						lowerCAmelCase__      :		Any    							=      norm_type
						lowerCAmelCase__      :		Optional[int]    							=      kernel_size
						lowerCAmelCase__      :		Dict    							=      last_kernel_size
						lowerCAmelCase__      :		Any    							=      residual_kernel_size
						lowerCAmelCase__      :		Dict    							=      dilation_growth_rate
						lowerCAmelCase__      :		Dict    							=      use_causal_conv
						lowerCAmelCase__      :		str    							=      pad_mode
						lowerCAmelCase__      :		int    							=      compress
						lowerCAmelCase__      :		Any    							=      num_lstm_layers
						lowerCAmelCase__      :		List[Any]    							=      trim_right_ratio
						lowerCAmelCase__      :		Optional[int]    							=      codebook_size
						lowerCAmelCase__      :		Optional[int]    							=      codebook_dim if codebook_dim is not None else hidden_size
						lowerCAmelCase__      :		Optional[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 			__lowerCAmelCase					(			self     :							Optional[Any]						):
						if self.chunk_length_s is None:
							return None
						else:
							return int(self.chunk_length_s * self.sampling_rate						)







					@property
					def 			__lowerCAmelCase					(			self     :							Dict						):
						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 			__lowerCAmelCase					(			self     :							int						):
						lowerCAmelCase__      :		Union[str, Any]    							=      np.prod(self.upsampling_ratios						)
						return math.ceil(self.sampling_rate / hop_length						)







					@property
					def 			__lowerCAmelCase					(			self     :							List[str]						):
						return int(1_0_0_0 * self.target_bandwidths[-1] // (self.frame_rate * 1_0)						)







"""simple docstring"""





from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


__UpperCamelCase    : Tuple				 =						logging.get_logger(__name__)

__UpperCamelCase    : Optional[int]				 =						{
    '''google/bit-50''': '''https://huggingface.co/google/bit-50/resolve/main/config.json''',
}







class 							SCREAMING_SNAKE_CASE   (						a_       ,				a_			):






					"""simple docstring"""



					lowercase__												=			"bit"
					lowercase__												=			["preactivation", "bottleneck"]
					lowercase__												=			["SAME", "VALID"]







					def __init__(			self     :							int  ,lowercase_     :							Optional[int]=3  ,lowercase_     :							int=6_4  ,lowercase_     :							Optional[int]=[2_5_6, 5_1_2, 1_0_2_4, 2_0_4_8]  ,lowercase_     :							Union[str, Any]=[3, 4, 6, 3]  ,lowercase_     :							List[Any]="preactivation"  ,lowercase_     :							Dict="relu"  ,lowercase_     :							Dict=None  ,lowercase_     :							Optional[Any]=3_2  ,lowercase_     :							Any=0.0  ,lowercase_     :							Optional[Any]=False  ,lowercase_     :							List[Any]=3_2  ,lowercase_     :							Optional[Any]=1  ,lowercase_     :							Optional[int]=None  ,lowercase_     :							int=None  ,**lowercase_     :							List[str]  ,):
						super().__init__(**lowercase_						)
						if layer_type not in self.layer_types:
							raise ValueError(F'layer_type={layer_type} is not one of {",".join(self.layer_types						)}'						)
						if global_padding is not None:
							if global_padding.upper() in self.supported_padding:
								lowerCAmelCase__      :		Optional[Any]    							=      global_padding.upper()
							else:
								raise ValueError(F'Padding strategy {global_padding} not supported'						)
						lowerCAmelCase__      :		int    							=      num_channels
						lowerCAmelCase__      :		int    							=      embedding_size
						lowerCAmelCase__      :		Any    							=      hidden_sizes
						lowerCAmelCase__      :		int    							=      depths
						lowerCAmelCase__      :		Union[str, Any]    							=      layer_type
						lowerCAmelCase__      :		Optional[int]    							=      hidden_act
						lowerCAmelCase__      :		int    							=      global_padding
						lowerCAmelCase__      :		List[Any]    							=      num_groups
						lowerCAmelCase__      :		List[Any]    							=      drop_path_rate
						lowerCAmelCase__      :		Union[str, Any]    							=      embedding_dynamic_padding
						lowerCAmelCase__      :		int    							=      output_stride
						lowerCAmelCase__      :		Optional[Any]    							=      width_factor

						lowerCAmelCase__      :		List[str]    							=      ['''stem'''] + [F'stage{idx}' for idx in range(1  ,len(lowercase_						) + 1						)]
						lowerCAmelCase__							,lowerCAmelCase__      :		Any    							=      get_aligned_output_features_output_indices(
						    out_features=lowercase_  ,out_indices=lowercase_  ,stage_names=self.stage_names						)




