

"""simple docstring"""






import math

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


__lowerCamelCase										=		logging.get_logger(__name__)

__lowerCamelCase										=		{
    "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     ):
     _lowerCamelCase     =       '''data2vec-audio'''







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

      # ctc loss
      __magic_name__     =      ctc_loss_reduction
      __magic_name__     =      ctc_zero_infinity

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

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

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







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




"""simple docstring"""






import os
from tempfile import TemporaryDirectory
from unittest import TestCase

import pytest
from absl.testing import parameterized

from datasets import config
from datasets.arrow_reader import HF_GCP_BASE_URL
from datasets.builder import DatasetBuilder
from datasets.dataset_dict import IterableDatasetDict
from datasets.iterable_dataset import IterableDataset
from datasets.load import dataset_module_factory, import_main_class
from datasets.utils.file_utils import cached_path


__lowerCamelCase										=		[
    {"dataset": "wikipedia", "config_name": "20220301.de"},
    {"dataset": "wikipedia", "config_name": "20220301.en"},
    {"dataset": "wikipedia", "config_name": "20220301.fr"},
    {"dataset": "wikipedia", "config_name": "20220301.frr"},
    {"dataset": "wikipedia", "config_name": "20220301.it"},
    {"dataset": "wikipedia", "config_name": "20220301.simple"},
    {"dataset": "snli", "config_name": "plain_text"},
    {"dataset": "eli5", "config_name": "LFQA_reddit"},
    {"dataset": "wiki40b", "config_name": "en"},
    {"dataset": "wiki_dpr", "config_name": "psgs_w100.nq.compressed"},
    {"dataset": "wiki_dpr", "config_name": "psgs_w100.nq.no_index"},
    {"dataset": "wiki_dpr", "config_name": "psgs_w100.multiset.no_index"},
    {"dataset": "natural_questions", "config_name": "default"},
]





def 	lowercase      (   __UpperCamelCase=True						) ->      List[Any]:
 if with_config:
  return [
      {
          "testcase_name": d["dataset"] + "/" + d["config_name"],
          "dataset": d["dataset"],
          "config_name": d["config_name"],
      }
      for d in DATASETS_ON_HF_GCP
  ]
 else:
  return [
      {"testcase_name": dataset, "dataset": dataset} for dataset in {d["dataset"] for d in DATASETS_ON_HF_GCP}
  ]
@parameterized.named_parameters(list_datasets_on_hf_gcp_parameters(with_config=__UpperCAmelCase     )     )
class        _lowercase					(     __UpperCAmelCase     ):
     _lowerCamelCase     =       None
     _lowerCamelCase     =       None







     def 	lowerCAmelCase__    (      self ,						UpperCamelCase_ ,						UpperCamelCase_       ):
      with TemporaryDirectory() as tmp_dir:
       __magic_name__     =      dataset_module_factory(UpperCamelCase_ ,						cache_dir=UpperCamelCase_       )

       __magic_name__     =      import_main_class(dataset_module.module_path ,						dataset=UpperCamelCase_       )

       __magic_name__     =      builder_cls(
           cache_dir=UpperCamelCase_ ,						config_name=UpperCamelCase_ ,						hash=dataset_module.hash ,						)

       __magic_name__     =      '''/'''.join(
           [
               HF_GCP_BASE_URL,
               builder_instance._relative_data_dir(with_hash=UpperCamelCase_       ).replace(os.sep ,						'''/'''       ),
               config.DATASET_INFO_FILENAME,
           ]       )
       __magic_name__     =      cached_path(UpperCamelCase_ ,						cache_dir=UpperCamelCase_       )
       self.assertTrue(os.path.exists(UpperCamelCase_       )       )





@pytest.mark.integration
def 	lowercase      (   __UpperCamelCase						) ->      Tuple:
 __magic_name__     =      tmp_path_factory.mktemp('''test_hf_gcp'''						) / '''test_wikipedia_simple'''
 __magic_name__     =      dataset_module_factory('''wikipedia'''      ,   cache_dir=__UpperCamelCase						)
 __magic_name__     =      import_main_class(dataset_module.module_path						)
 __magic_name__     =      builder_cls(
     cache_dir=__UpperCamelCase      ,   config_name='''20220301.frr'''      ,   hash=dataset_module.hash      ,   )
 # use the HF cloud storage, not the original download_and_prepare that uses apache-beam
 __magic_name__     =      None
 builder_instance.download_and_prepare()
 __magic_name__     =      builder_instance.as_dataset()
 assert ds





@pytest.mark.integration
def 	lowercase      (   __UpperCamelCase						) ->      Tuple:
 __magic_name__     =      dataset_module_factory('''wikipedia'''      ,   cache_dir=__UpperCamelCase						)
 __magic_name__     =      import_main_class(dataset_module.module_path      ,   dataset=__UpperCamelCase						)
 __magic_name__     =      builder_cls(
     cache_dir=__UpperCamelCase      ,   config_name='''20220301.frr'''      ,   hash=dataset_module.hash      ,   )
 __magic_name__     =      builder_instance.as_streaming_dataset()
 assert ds
 assert isinstance(__UpperCamelCase      ,   __UpperCamelCase						)
 assert "train" in ds
 assert isinstance(ds['''train''']      ,   __UpperCamelCase						)
 assert next(iter(ds['''train''']						)						)

