





"""simple docstring"""
import functools
import operator

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


__UpperCamelCase     :						Dict						       =  logging.get_logger(__name__)

__UpperCamelCase     :						Union[str, Any]						       =  {
    '''microsoft/unispeech-sat-base-100h-libri-ft''': (
        '''https://huggingface.co/microsoft/unispeech-sat-base-100h-libri-ft/resolve/main/config.json'''
    ),
    # See all UniSpeechSat models at https://huggingface.co/models?filter=unispeech_sat
}







class       a							(   a__  ):
 snake_case__             =       '''unispeech-sat'''



 def __init__(     self				,       _snake_case=32				,       _snake_case=7_68				,       _snake_case=12				,       _snake_case=12				,       _snake_case=30_72				,       _snake_case="gelu"				,       _snake_case=0.1				,       _snake_case=0.1				,       _snake_case=0.1				,       _snake_case=0.0				,       _snake_case=0.0				,       _snake_case=0.1				,       _snake_case=0.1				,       _snake_case=0.02				,       _snake_case=1E-5				,       _snake_case="group"				,       _snake_case="gelu"				,       _snake_case=(5_12, 5_12, 5_12, 5_12, 5_12, 5_12, 5_12)				,       _snake_case=(5, 2, 2, 2, 2, 2, 2)				,       _snake_case=(10, 3, 3, 3, 3, 2, 2)				,       _snake_case=False				,       _snake_case=1_28				,       _snake_case=16				,       _snake_case=False				,       _snake_case=True				,       _snake_case=0.05				,       _snake_case=10				,       _snake_case=2				,       _snake_case=0.0				,       _snake_case=10				,       _snake_case=0				,       _snake_case=3_20				,       _snake_case=2				,       _snake_case=0.1				,       _snake_case=1_00				,       _snake_case=2_56				,       _snake_case=2_56				,       _snake_case=0.1				,       _snake_case="mean"				,       _snake_case=False				,       _snake_case=False				,       _snake_case=2_56				,       _snake_case=(5_12, 5_12, 5_12, 5_12, 15_00)				,       _snake_case=(5, 3, 3, 1, 1)				,       _snake_case=(1, 2, 3, 1, 1)				,       _snake_case=5_12				,       _snake_case=0				,       _snake_case=1				,       _snake_case=2				,       _snake_case=5_04				,       **_snake_case				,       ):







  """simple docstring"""






  super().__init__(**_snake_case				,       pad_token_id=_snake_case				,       bos_token_id=_snake_case				,       eos_token_id=_snake_case     )
  lowerCAmelCase    				= hidden_size
  lowerCAmelCase    				= feat_extract_norm
  lowerCAmelCase    				= feat_extract_activation
  lowerCAmelCase    				= list(_snake_case     )
  lowerCAmelCase    				= list(_snake_case     )
  lowerCAmelCase    				= list(_snake_case     )
  lowerCAmelCase    				= conv_bias
  lowerCAmelCase    				= num_conv_pos_embeddings
  lowerCAmelCase    				= num_conv_pos_embedding_groups
  lowerCAmelCase    				= len(self.conv_dim     )
  lowerCAmelCase    				= num_hidden_layers
  lowerCAmelCase    				= intermediate_size
  lowerCAmelCase    				= hidden_act
  lowerCAmelCase    				= num_attention_heads
  lowerCAmelCase    				= hidden_dropout
  lowerCAmelCase    				= attention_dropout
  lowerCAmelCase    				= activation_dropout
  lowerCAmelCase    				= feat_proj_dropout
  lowerCAmelCase    				= final_dropout
  lowerCAmelCase    				= layerdrop
  lowerCAmelCase    				= layer_norm_eps
  lowerCAmelCase    				= initializer_range
  lowerCAmelCase    				= vocab_size
  lowerCAmelCase    				= num_clusters
  lowerCAmelCase    				= do_stable_layer_norm
  lowerCAmelCase    				= use_weighted_layer_sum

  if (
      (len(self.conv_stride     ) != self.num_feat_extract_layers)
      or (len(self.conv_kernel     ) != self.num_feat_extract_layers)
      or (len(self.conv_dim     ) != self.num_feat_extract_layers)
  ):
   raise ValueError(
       'Configuration for convolutional layers is incorrect. It is required that `len(config.conv_dim)` =='
       ' `len(config.conv_stride)` == `len(config.conv_kernel)`, but is `len(config.conv_dim) ='
       F' {len(self.conv_dim     )}`, `len(config.conv_stride) = {len(self.conv_stride     )}`,'
       F' `len(config.conv_kernel) = {len(self.conv_kernel     )}`.'     )

  # fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
  lowerCAmelCase    				= apply_spec_augment
  lowerCAmelCase    				= mask_time_prob
  lowerCAmelCase    				= mask_time_length
  lowerCAmelCase    				= mask_time_min_masks
  lowerCAmelCase    				= mask_feature_prob
  lowerCAmelCase    				= mask_feature_length
  lowerCAmelCase    				= mask_feature_min_masks

  # parameters for pretraining with codevector quantized representations
  lowerCAmelCase    				= num_codevectors_per_group
  lowerCAmelCase    				= num_codevector_groups
  lowerCAmelCase    				= contrastive_logits_temperature
  lowerCAmelCase    				= feat_quantizer_dropout
  lowerCAmelCase    				= num_negatives
  lowerCAmelCase    				= codevector_dim
  lowerCAmelCase    				= proj_codevector_dim
  lowerCAmelCase    				= diversity_loss_weight

  # ctc loss
  lowerCAmelCase    				= ctc_loss_reduction
  lowerCAmelCase    				= ctc_zero_infinity

  # SequenceClassification-specific parameter. Feel free to ignore for other classes.
  lowerCAmelCase    				= classifier_proj_size

  # XVector-specific parameters. Feel free to ignore for other classes.
  lowerCAmelCase    				= list(_snake_case     )
  lowerCAmelCase    				= list(_snake_case     )
  lowerCAmelCase    				= list(_snake_case     )
  lowerCAmelCase    				= xvector_output_dim



 @property
 def    UpperCamelCase__  (     self     ):







  """simple docstring"""






  return functools.reduce(operator.mul				,       self.conv_stride				,       1     )












"""simple docstring"""
from dataclasses import dataclass
from typing import Optional, Tuple, Union

import torch
import torch.nn as nn

from ..configuration_utils import ConfigMixin, register_to_config
from ..utils import BaseOutput, apply_forward_hook
from .modeling_utils import ModelMixin
from .vae import Decoder, DecoderOutput, Encoder, VectorQuantizer







@dataclass
class       a							(   a__  ):
 snake_case__             =       42







class       a							(   a__   , a__  ):



 @register_to_config
 def __init__(     self				,       _snake_case = 3				,       _snake_case = 3				,       _snake_case = ("DownEncoderBlock2D",)				,       _snake_case = ("UpDecoderBlock2D",)				,       _snake_case = (64,)				,       _snake_case = 1				,       _snake_case = "silu"				,       _snake_case = 3				,       _snake_case = 32				,       _snake_case = 2_56				,       _snake_case = 32				,       _snake_case = None				,       _snake_case = 0.18_215				,       _snake_case = "group"				,       ):







  """simple docstring"""






  super().__init__()

  # pass init params to Encoder
  lowerCAmelCase    				= Encoder(
      in_channels=_snake_case				,       out_channels=_snake_case				,       down_block_types=_snake_case				,       block_out_channels=_snake_case				,       layers_per_block=_snake_case				,       act_fn=_snake_case				,       norm_num_groups=_snake_case				,       double_z=_snake_case				,       )

  lowerCAmelCase    				= vq_embed_dim if vq_embed_dim is not None else latent_channels

  lowerCAmelCase    				= nn.Convad(_snake_case				,       _snake_case				,       1     )
  lowerCAmelCase    				= VectorQuantizer(_snake_case				,       _snake_case				,       beta=0.25				,       remap=_snake_case				,       sane_index_shape=_snake_case     )
  lowerCAmelCase    				= nn.Convad(_snake_case				,       _snake_case				,       1     )

  # pass init params to Decoder
  lowerCAmelCase    				= Decoder(
      in_channels=_snake_case				,       out_channels=_snake_case				,       up_block_types=_snake_case				,       block_out_channels=_snake_case				,       layers_per_block=_snake_case				,       act_fn=_snake_case				,       norm_num_groups=_snake_case				,       norm_type=_snake_case				,       )



 @apply_forward_hook
 def    UpperCamelCase__  (     self				,       _snake_case				,       _snake_case = True     ):







  """simple docstring"""






  lowerCAmelCase    				= self.encoder(_snake_case     )
  lowerCAmelCase    				= self.quant_conv(_snake_case     )

  if not return_dict:
   return (h,)

  return VQEncoderOutput(latents=_snake_case     )



 @apply_forward_hook
 def    UpperCamelCase__  (     self				,       _snake_case				,       _snake_case = False				,       _snake_case = True     ):







  """simple docstring"""






  if not force_not_quantize:
   lowerCAmelCase				,lowerCAmelCase				,lowerCAmelCase    				= self.quantize(_snake_case     )
  else:
   lowerCAmelCase    				= h
  lowerCAmelCase    				= self.post_quant_conv(_snake_case     )
  lowerCAmelCase    				= self.decoder(_snake_case				,       quant if self.config.norm_type == 'spatial' else None     )

  if not return_dict:
   return (dec,)

  return DecoderOutput(sample=_snake_case     )



 def    UpperCamelCase__  (     self				,       _snake_case				,       _snake_case = True     ):







  """simple docstring"""






  lowerCAmelCase    				= sample
  lowerCAmelCase    				= self.encode(_snake_case     ).latents
  lowerCAmelCase    				= self.decode(_snake_case     ).sample

  if not return_dict:
   return (dec,)

  return DecoderOutput(sample=_snake_case     )





