




"""simple docstring"""

import math

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


a         =      logging.get_logger(__name__)

a         =      {
    '''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_	(					__lowerCAmelCase							):



 '''simple docstring'''
 UpperCAmelCase   :					int				  =     '''data2vec-audio'''

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

       # ctc loss
       _A        =       ctc_loss_reduction
       _A        =       ctc_zero_infinity

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

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

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



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







"""simple docstring"""

import inspect
import os
import unittest
from pathlib import Path

import torch

import accelerate
from accelerate.test_utils import execute_subprocess_async
from accelerate.test_utils.testing import run_command





class     lowercase_	(					unittest.TestCase							):



 '''simple docstring'''
 UpperCAmelCase   :					str				  =     inspect.getfile(accelerate.test_utils							)
 UpperCAmelCase   :					Optional[Any]				  =     os.path.sep.join(mod_file.split(os.path.sep							)[:-1] + ['''scripts''', '''test_cli.py''']							)

 UpperCAmelCase   :					List[Any]				  =     ['''accelerate''', '''launch''']
 UpperCAmelCase   :					Dict				  =     Path.home() / '''.cache/huggingface/accelerate'''
 UpperCAmelCase   :					Union[str, Any]				  =     '''default_config.yaml'''
 UpperCAmelCase   :					Union[str, Any]				  =     config_folder / config_file
 UpperCAmelCase   :					Union[str, Any]				  =     config_folder / '''_default_config.yaml'''

 UpperCAmelCase   :					List[Any]				  =     Path('''tests/test_configs'''							)

 @classmethod
 def       lowerCAmelCase_							(			cls	:	List[Any]		):
       if cls.config_path.is_file():
             cls.config_path.rename(cls.changed_path		)

 @classmethod
 def       lowerCAmelCase_							(			cls	:	Tuple		):
       if cls.changed_path.is_file():
             cls.changed_path.rename(cls.config_path		)

 def       lowerCAmelCase_							(			self	:	List[Any]		):
       _A        =       self.base_cmd
       if torch.cuda.is_available() and (torch.cuda.device_count() > 1):
             cmd += ["--multi_gpu"]
       execute_subprocess_async(cmd + [self.test_file_path]   ,							env=os.environ.copy()		)

 def       lowerCAmelCase_							(			self	:	Optional[int]		):
       for config in sorted(self.test_config_path.glob('**/*.yaml'		)		):
             with self.subTest(config_file=_UpperCAmelCase		):
                   execute_subprocess_async(
                       self.base_cmd + ['--config_file', str(_UpperCAmelCase		), self.test_file_path]   ,							env=os.environ.copy()		)



 def       lowerCAmelCase_							(			self	:	Any		):
       execute_subprocess_async(['accelerate', 'test']   ,							env=os.environ.copy()		)





class     lowercase_	(					unittest.TestCase							):



 '''simple docstring'''
 UpperCAmelCase   :					Dict				  =     '''test-tpu'''
 UpperCAmelCase   :					Optional[int]				  =     '''us-central1-a'''
 UpperCAmelCase   :					List[str]				  =     '''ls'''
 UpperCAmelCase   :					str				  =     ['''accelerate''', '''tpu-config''']
 UpperCAmelCase   :					Optional[Any]				  =     '''cd /usr/share'''
 UpperCAmelCase   :					Optional[Any]				  =     '''tests/test_samples/test_command_file.sh'''
 UpperCAmelCase   :					str				  =     '''Running gcloud compute tpus tpu-vm ssh'''

 def       lowerCAmelCase_							(			self	:	Any		):
       _A        =       run_command(
           self.cmd
           + ['--command', self.command, '--tpu_zone', self.tpu_zone, '--tpu_name', self.tpu_name, '--debug']   ,							return_stdout=_UpperCAmelCase   ,							)
       self.assertIn(
           F'''{self.gcloud} test-tpu --zone us-central1-a --command {self.base_output}; ls --worker all'''   ,							_UpperCAmelCase   ,							)

 def       lowerCAmelCase_							(			self	:	Dict		):
       _A        =       run_command(
           self.cmd
           + [
               '--config_file',
               'tests/test_configs/0_12_0.yaml',
               '--command',
               self.command,
               '--tpu_zone',
               self.tpu_zone,
               '--tpu_name',
               self.tpu_name,
               '--debug',
           ]   ,							return_stdout=_UpperCAmelCase   ,							)
       self.assertIn(
           F'''{self.gcloud} test-tpu --zone us-central1-a --command {self.base_output}; ls --worker all'''   ,							_UpperCAmelCase   ,							)

 def       lowerCAmelCase_							(			self	:	Optional[int]		):
       _A        =       run_command(
           self.cmd + ['--config_file', 'tests/test_configs/latest.yaml', '--debug']   ,							return_stdout=_UpperCAmelCase		)
       self.assertIn(
           F'''{self.gcloud} test-tpu --zone us-central1-a --command {self.base_output}; echo "hello world"; echo "this is a second command" --worker all'''   ,							_UpperCAmelCase   ,							)

 def       lowerCAmelCase_							(			self	:	str		):
       _A        =       run_command(
           self.cmd + ['--config_file', 'tests/test_configs/latest.yaml', '--command', self.command, '--debug']   ,							return_stdout=_UpperCAmelCase   ,							)
       self.assertIn(
           F'''{self.gcloud} test-tpu --zone us-central1-a --command {self.base_output}; ls --worker all'''   ,							_UpperCAmelCase   ,							)

 def       lowerCAmelCase_							(			self	:	List[str]		):
       _A        =       run_command(
           self.cmd
           + [
               '--config_file',
               'tests/test_configs/latest.yaml',
               '--command',
               self.command,
               '--command',
               'echo "Hello World"',
               '--debug',
           ]   ,							return_stdout=_UpperCAmelCase   ,							)
       self.assertIn(
           F'''{self.gcloud} test-tpu --zone us-central1-a --command {self.base_output}; ls; echo "Hello World" --worker all'''   ,							_UpperCAmelCase   ,							)

 def       lowerCAmelCase_							(			self	:	str		):
       _A        =       run_command(
           self.cmd
           + ['--config_file', 'tests/test_configs/latest.yaml', '--command_file', self.command_file, '--debug']   ,							return_stdout=_UpperCAmelCase   ,							)
       self.assertIn(
           F'''{self.gcloud} test-tpu --zone us-central1-a --command {self.base_output}; echo "hello world"; echo "this is a second command" --worker all'''   ,							_UpperCAmelCase   ,							)

 def       lowerCAmelCase_							(			self	:	List[Any]		):
       _A        =       run_command(
           self.cmd
           + [
               '--config_file',
               'tests/test_configs/0_12_0.yaml',
               '--command_file',
               self.command_file,
               '--tpu_zone',
               self.tpu_zone,
               '--tpu_name',
               self.tpu_name,
               '--debug',
           ]   ,							return_stdout=_UpperCAmelCase   ,							)
       self.assertIn(
           F'''{self.gcloud} test-tpu --zone us-central1-a --command {self.base_output}; echo "hello world"; echo "this is a second command" --worker all'''   ,							_UpperCAmelCase   ,							)

 def       lowerCAmelCase_							(			self	:	int		):
       _A        =       run_command(
           self.cmd + ['--config_file', 'tests/test_configs/latest.yaml', '--install_accelerate', '--debug']   ,							return_stdout=_UpperCAmelCase   ,							)
       self.assertIn(
           F'''{self.gcloud} test-tpu --zone us-central1-a --command {self.base_output}; pip install accelerate -U; echo "hello world"; echo "this is a second command" --worker all'''   ,							_UpperCAmelCase   ,							)



 def       lowerCAmelCase_							(			self	:	Optional[int]		):
       _A        =       run_command(
           self.cmd
           + [
               '--config_file',
               'tests/test_configs/latest.yaml',
               '--install_accelerate',
               '--accelerate_version',
               '12.0.0',
               '--debug',
           ]   ,							return_stdout=_UpperCAmelCase   ,							)
       self.assertIn(
           F'''{self.gcloud} test-tpu --zone us-central1-a --command {self.base_output}; pip install accelerate==12.0.0; echo "hello world"; echo "this is a second command" --worker all'''   ,							_UpperCAmelCase   ,							)

