

import math

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


_UpperCAmelCase		:   Union[str, Any]										=       logging.get_logger(__name__)

_UpperCAmelCase		:   List[str]										=       {
    """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				(       lowercase_			):
				__SCREAMING_SNAKE_CASE					: int       			=			'''data2vec-audio'''




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

											# ctc loss
											snake_case_							=    ctc_loss_reduction
											snake_case_							=    ctc_zero_infinity

											# adapter
											snake_case_							=    add_adapter
											snake_case_							=    adapter_kernel_size
											snake_case_							=    adapter_stride
											snake_case_							=    num_adapter_layers
											snake_case_							=    output_hidden_size or hidden_size

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

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




				@property
				def     a							(					self       ):
											return math.prod(self.conv_stride       )







import unittest

from datasets import load_dataset

from transformers import BloomTokenizerFast
from transformers.testing_utils import require_tokenizers

from ...test_tokenization_common import TokenizerTesterMixin







@require_tokenizers
class  lowercase				(       lowercase_	,  unittest.TestCase			):
				__SCREAMING_SNAKE_CASE					: List[Any]       			=			None
				__SCREAMING_SNAKE_CASE					: Any       			=			BloomTokenizerFast
				__SCREAMING_SNAKE_CASE					: int       			=			BloomTokenizerFast
				__SCREAMING_SNAKE_CASE					: Optional[Any]       			=			True
				__SCREAMING_SNAKE_CASE					: str       			=			False
				__SCREAMING_SNAKE_CASE					: Union[str, Any]       			=			'''tokenizer_file'''
				__SCREAMING_SNAKE_CASE					: Optional[int]       			=			{'''bos_token''': '''<s>''', '''eos_token''': '''</s>''', '''unk_token''': '''<unk>''', '''pad_token''': '''<pad>'''}




				def     a							(					self       ):
											super().setUp()
											snake_case_							=    BloomTokenizerFast.from_pretrained('bigscience/tokenizer'       )
											tokenizer.save_pretrained(self.tmpdirname       )




				def     a							(					self      ,   **snake_case       ):
											kwargs.update(self.special_tokens_map       )
											return BloomTokenizerFast.from_pretrained(self.tmpdirname      ,   **snake_case       )




				def     a							(					self       ):
											snake_case_							=    self.get_rust_tokenizer()

											snake_case_							=    ['The quick brown fox</s>', 'jumps over the lazy dog</s>']
											snake_case_							=    [[2175, 2_3714, 7_3173, 14_4252, 2], [77, 13_2619, 3478, 368, 10_9586, 3_5433, 2]]

											snake_case_							=    tokenizer.batch_encode_plus(snake_case       )['input_ids']
											self.assertListEqual(snake_case      ,   snake_case       )

											snake_case_							=    tokenizer.batch_decode(snake_case       )
											self.assertListEqual(snake_case      ,   snake_case       )




				def     a							(					self      ,   snake_case=6       ):
											for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
																		with self.subTest(F'''{tokenizer.__class__.__name__} ({pretrained_name})'''       ):
																									snake_case_							=    self.rust_tokenizer_class.from_pretrained(snake_case      ,   **snake_case       )
																									# tokenizer_r.pad_token = None # Hotfixing padding = None
																									# Simple input
																									snake_case_							=    'This is a simple input'
																									snake_case_							=    ['This is a simple input 1', 'This is a simple input 2']
																									snake_case_							=    ('This is a simple input', 'This is a pair')
																									snake_case_							=    [
																									    ('This is a simple input 1', 'This is a simple input 2'),
																									    ('This is a simple pair 1', 'This is a simple pair 2'),
																									]

																									# Simple input tests
																									try:
																																tokenizer_r.encode(snake_case      ,   max_length=snake_case       )
																																tokenizer_r.encode_plus(snake_case      ,   max_length=snake_case       )

																																tokenizer_r.batch_encode_plus(snake_case      ,   max_length=snake_case       )
																																tokenizer_r.encode(snake_case      ,   max_length=snake_case       )
																																tokenizer_r.batch_encode_plus(snake_case      ,   max_length=snake_case       )
																									except ValueError:
																																self.fail('Bloom Tokenizer should be able to deal with padding'       )

																									snake_case_							=    None  # Hotfixing padding = None
																									self.assertRaises(snake_case      ,   tokenizer_r.encode      ,   snake_case      ,   max_length=snake_case      ,   padding='max_length'       )

																									# Simple input
																									self.assertRaises(snake_case      ,   tokenizer_r.encode_plus      ,   snake_case      ,   max_length=snake_case      ,   padding='max_length'       )

																									# Simple input
																									self.assertRaises(
																									    snake_case      ,   tokenizer_r.batch_encode_plus      ,   snake_case      ,   max_length=snake_case      ,   padding='max_length'      ,   )

																									# Pair input
																									self.assertRaises(snake_case      ,   tokenizer_r.encode      ,   snake_case      ,   max_length=snake_case      ,   padding='max_length'       )

																									# Pair input
																									self.assertRaises(snake_case      ,   tokenizer_r.encode_plus      ,   snake_case      ,   max_length=snake_case      ,   padding='max_length'       )

																									# Pair input
																									self.assertRaises(
																									    snake_case      ,   tokenizer_r.batch_encode_plus      ,   snake_case      ,   max_length=snake_case      ,   padding='max_length'      ,   )




				def     a							(					self       ):
											snake_case_							=    self.get_rust_tokenizer()
											snake_case_							=    load_dataset('xnli'      ,   'all_languages'      ,   split='test'      ,   streaming=snake_case       )

											snake_case_							=    next(iter(snake_case       )       )['premise']  # pick up one data
											snake_case_							=    list(sample_data.values()       )

											snake_case_							=    list(map(tokenizer.encode      ,   snake_case       )       )
											snake_case_							=    [tokenizer.decode(snake_case      ,   clean_up_tokenization_spaces=snake_case       ) for x in output_tokens]
											self.assertListEqual(snake_case      ,   snake_case       )




				def     a							(					self       ):
											# The test has to be overriden because BLOOM uses ALiBi positional embeddings that does not have
											# any sequence length constraints. This test of the parent class will fail since it relies on the
											# maximum sequence length of the positoonal embeddings.
											self.assertGreaterEqual(len(self.tokenizer_class.pretrained_vocab_files_map       )      ,   1       )
											self.assertGreaterEqual(len(list(self.tokenizer_class.pretrained_vocab_files_map.values()       )[0]       )      ,   1       )




