




import math

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


_snake_case            = logging.get_logger(__name__)

_snake_case            = {
    "facebook/data2vec-base-960h": "https://huggingface.co/facebook/data2vec-audio-base-960h/resolve/main/config.json",
    # See all Data2VecAudio models at https://huggingface.co/models?filter=data2vec-audio
}







class 		lowercase							(     UpperCamelCase__	):
     _a											=		"data2vec-audio"

     def __init__(						self	,  _a=32	,  _a=768	,  _a=12	,  _a=12	,  _a=3072	,  _a="gelu"	,  _a=0.1	,  _a=0.1	,  _a=0.1	,  _a=0.0	,  _a=0.1	,  _a=0.1	,  _a=0.02	,  _a=1e-5	,  _a="gelu"	,  _a=(512, 512, 512, 512, 512, 512, 512)	,  _a=(5, 2, 2, 2, 2, 2, 2)	,  _a=(10, 3, 3, 3, 3, 2, 2)	,  _a=False	,  _a=16	,  _a=19	,  _a=5	,  _a=0.05	,  _a=10	,  _a=2	,  _a=0.0	,  _a=10	,  _a=0	,  _a="sum"	,  _a=False	,  _a=False	,  _a=256	,  _a=(512, 512, 512, 512, 1500)	,  _a=(5, 3, 3, 1, 1)	,  _a=(1, 2, 3, 1, 1)	,  _a=512	,  _a=0	,  _a=1	,  _a=2	,  _a=False	,  _a=3	,  _a=2	,  _a=3	,  _a=None	,  **_a	,  )		->							Union[str, Any]:
           super().__init__(**_a	,  pad_token_id=_a	,  bos_token_id=_a	,  eos_token_id=_a       )
           _A							:  Any    =		hidden_size
           _A							:  List[str]    =		feat_extract_activation
           _A							:  Optional[int]    =		list(_a       )
           _A							:  Tuple    =		list(_a       )
           _A							:  Union[str, Any]    =		list(_a       )
           _A							:  Tuple    =		conv_bias
           _A							:  Optional[int]    =		num_conv_pos_embeddings
           _A							:  Tuple    =		num_conv_pos_embedding_groups
           _A							:  Optional[int]    =		conv_pos_kernel_size
           _A							:  List[str]    =		len(self.conv_dim       )
           _A							:  str    =		num_hidden_layers
           _A							:  List[str]    =		intermediate_size
           _A							:  Any    =		hidden_act
           _A							:  Optional[Any]    =		num_attention_heads
           _A							:  Optional[Any]    =		hidden_dropout
           _A							:  Union[str, Any]    =		attention_dropout
           _A							:  Optional[Any]    =		activation_dropout
           _A							:  List[Any]    =		feat_proj_dropout
           _A							:  int    =		final_dropout
           _A							:  List[Any]    =		layerdrop
           _A							:  Optional[int]    =		layer_norm_eps
           _A							:  Tuple    =		initializer_range
           _A							:  str    =		vocab_size
           _A							:  str    =		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
           _A							:  int    =		mask_time_prob
           _A							:  Union[str, Any]    =		mask_time_length
           _A							:  Dict    =		mask_time_min_masks
           _A							:  List[str]    =		mask_feature_prob
           _A							:  Optional[Any]    =		mask_feature_length
           _A							:  List[Any]    =		mask_feature_min_masks

           # ctc loss
           _A							:  Any    =		ctc_loss_reduction
           _A							:  str    =		ctc_zero_infinity

           # adapter
           _A							:  List[Any]    =		add_adapter
           _A							:  Any    =		adapter_kernel_size
           _A							:  List[Any]    =		adapter_stride
           _A							:  Optional[Any]    =		num_adapter_layers
           _A							:  Union[str, Any]    =		output_hidden_size or hidden_size

           # SequenceClassification-specific parameter. Feel free to ignore for other classes.
           _A							:  Union[str, Any]    =		classifier_proj_size

           # XVector-specific parameters. Feel free to ignore for other classes.
           _A							:  Optional[int]    =		list(_a       )
           _A							:  Dict    =		list(_a       )
           _A							:  Any    =		list(_a       )
           _A							:  int    =		xvector_output_dim



     @property
     def       a__			(						self       )		->							List[str]:
           return math.prod(self.conv_stride       )







import os
from typing import Dict, List, Union

import tensorflow as tf
from keras_nlp.tokenizers import BytePairTokenizer
from tensorflow_text import pad_model_inputs

from .tokenization_gpta import GPTaTokenizer







class 		lowercase							(     tf.keras.layers.Layer	):

     def __init__(						self	,  _a	,  _a	,  _a = None	,  _a = None       )		->							Any:
           super().__init__()
           _A							:  Dict    =		pad_token_id
           _A							:  List[Any]    =		max_length
           _A							:  Optional[int]    =		vocab
           _A							:  Optional[int]    =		merges
           _A							:  Optional[int]    =		BytePairTokenizer(_a	,  _a	,  sequence_length=_a       )

     @classmethod
     def       a__			(						cls	,  _a	,  *_a	,  **_a       )		->							str:
           _A							:  Any    =		[""" """.join(_a       ) for m in tokenizer.bpe_ranks.keys()]
           _A							:  str    =		tokenizer.get_vocab()
           return cls(_a	,  _a	,  *_a	,  **_a       )

     @classmethod
     def       a__			(						cls	,  _a	,  *_a	,  **_a       )		->							List[Any]:
           _A							:  Union[str, Any]    =		GPTaTokenizer.from_pretrained(_a	,  *_a	,  **_a       )
           return cls.from_tokenizer(_a	,  *_a	,  **_a       )

     @classmethod
     def       a__			(						cls	,  _a       )		->							Union[str, Any]:
           return cls(**_a       )

     def       a__			(						self       )		->							Union[str, Any]:
           return {
               "vocab": self.vocab,
               "merges": self.merges,
               "max_length": self.max_length,
               "pad_token_id": self.pad_token_id,
           }



     def       a__			(						self	,  _a	,  _a = None       )		->							int:
           _A							:  Optional[int]    =		self.tf_tokenizer(_a       )
           _A							:  Tuple    =		tf.ones_like(_a       )

           if self.pad_token_id is not None:
                 # pad the tokens up to max length
                 _A							:  Dict    =		max_length if max_length is not None else self.max_length

                 if max_length is not None:
                       _A    ,     _A							:  Dict    =		pad_model_inputs(
                           _a	,  max_seq_length=_a	,  pad_value=self.pad_token_id       )

           return {"attention_mask": attention_mask, "input_ids": input_ids}

