"""simple docstring"""



import os
import tempfile
from functools import partial
from unittest import TestCase
from unittest.mock import patch

import datasets
import datasets.config

from .utils import require_beam

class SCREAMING_SNAKE_CASE  (     datasets.BeamBasedBuilder						):







 """simple docstring"""


 def 							_lowerCAmelCase					( self		:   Optional[int]					)					->      List[str]:




    '''simple docstring'''






    return datasets.DatasetInfo(
        features=datasets.Features({'content': datasets.Value('string'					)}					)       , supervised_keys=_snake_case       , )


 def 							_lowerCAmelCase					( self		:   Tuple       , _snake_case		:   Optional[int]       , _snake_case		:   Optional[int]					)					->      Union[str, Any]:




    '''simple docstring'''






    return [datasets.SplitGenerator(name=datasets.Split.TRAIN       , gen_kwargs={'examples': get_test_dummy_examples()}					)]



 def 							_lowerCAmelCase					( self		:   str       , _snake_case		:   str       , _snake_case		:   List[Any]					)					->      List[str]:




    '''simple docstring'''






    import apache_beam as beam

    return pipeline | "Load Examples" >> beam.Create(_snake_case					)

class SCREAMING_SNAKE_CASE  (     datasets.BeamBasedBuilder						):







 """simple docstring"""


 def 							_lowerCAmelCase					( self		:   Optional[int]					)					->      Optional[Any]:




    '''simple docstring'''






    return datasets.DatasetInfo(
        features=datasets.Features({'a': datasets.Sequence({'b': datasets.Value('string'					)}					)}					)       , supervised_keys=_snake_case       , )


 def 							_lowerCAmelCase					( self		:   List[Any]       , _snake_case		:   Optional[Any]       , _snake_case		:   Tuple					)					->      List[Any]:




    '''simple docstring'''






    return [
        datasets.SplitGenerator(name=datasets.Split.TRAIN       , gen_kwargs={'examples': get_test_nested_examples()}					)
    ]



 def 							_lowerCAmelCase					( self		:   Tuple       , _snake_case		:   int       , _snake_case		:   List[str]					)					->      str:




    '''simple docstring'''






    import apache_beam as beam

    return pipeline | "Load Examples" >> beam.Create(_snake_case					)





def 	_lowerCamelCase			(			)				->  Optional[int]:


   '''simple docstring'''


   return [(i, {"content": content}) for i, content in enumerate(['foo', 'bar', 'foobar']       )]





def 	_lowerCamelCase			(			)				->  str:


   '''simple docstring'''


   return [(i, {"a": {"b": [content]}}) for i, content in enumerate(['foo', 'bar', 'foobar']       )]




class SCREAMING_SNAKE_CASE  (     snake_case__						):







 """simple docstring"""


 @require_beam
 def 							_lowerCAmelCase					( self		:   List[str]					)					->      List[str]:




    '''simple docstring'''






    a__  					=		len(get_test_dummy_examples()					)
    with tempfile.TemporaryDirectory() as tmp_cache_dir:
       a__  					=		DummyBeamDataset(cache_dir=_snake_case       , beam_runner='DirectRunner'					)
       builder.download_and_prepare()
       self.assertTrue(
           os.path.exists(
               os.path.join(_snake_case       , builder.name       , 'default'       , '0.0.0'       , F'''{builder.name}-train.arrow'''					)					)					)
       self.assertDictEqual(builder.info.features       , datasets.Features({'content': datasets.Value('string'					)}					)					)
       a__  					=		builder.as_dataset()
       self.assertEqual(dset['train'].num_rows       , _snake_case					)
       self.assertEqual(dset['train'].info.splits['train'].num_examples       , _snake_case					)
       self.assertDictEqual(dset['train'][0]       , get_test_dummy_examples()[0][1]					)
       self.assertDictEqual(
           dset['train'][expected_num_examples - 1]       , get_test_dummy_examples()[expected_num_examples - 1][1]					)
       self.assertTrue(
           os.path.exists(os.path.join(_snake_case       , builder.name       , 'default'       , '0.0.0'       , 'dataset_info.json'					)					)					)
       del dset


 @require_beam
 def 							_lowerCAmelCase					( self		:   List[Any]					)					->      Optional[Any]:




    '''simple docstring'''






    import apache_beam as beam

    a__  					=		beam.io.parquetio.WriteToParquet

    a__  					=		len(get_test_dummy_examples()					)
    with tempfile.TemporaryDirectory() as tmp_cache_dir:
       a__  					=		DummyBeamDataset(cache_dir=_snake_case       , beam_runner='DirectRunner'					)
       with patch('apache_beam.io.parquetio.WriteToParquet'					) as write_parquet_mock:
          a__  					=		partial(_snake_case       , num_shards=2					)
          builder.download_and_prepare()
       self.assertTrue(
           os.path.exists(
               os.path.join(
                   _snake_case       , builder.name       , 'default'       , '0.0.0'       , F'''{builder.name}-train-00000-of-00002.arrow'''					)					)					)
       self.assertTrue(
           os.path.exists(
               os.path.join(
                   _snake_case       , builder.name       , 'default'       , '0.0.0'       , F'''{builder.name}-train-00000-of-00002.arrow'''					)					)					)
       self.assertDictEqual(builder.info.features       , datasets.Features({'content': datasets.Value('string'					)}					)					)
       a__  					=		builder.as_dataset()
       self.assertEqual(dset['train'].num_rows       , _snake_case					)
       self.assertEqual(dset['train'].info.splits['train'].num_examples       , _snake_case					)
       # Order is not preserved when sharding, so we just check that all the elements are there
       self.assertListEqual(sorted(dset['train']['content']					)       , sorted(['foo', 'bar', 'foobar']					)					)
       self.assertTrue(
           os.path.exists(os.path.join(_snake_case       , builder.name       , 'default'       , '0.0.0'       , 'dataset_info.json'					)					)					)
       del dset


 @require_beam
 def 							_lowerCAmelCase					( self		:   Dict					)					->      Union[str, Any]:




    '''simple docstring'''






    with tempfile.TemporaryDirectory() as tmp_cache_dir:
       a__  					=		DummyBeamDataset(cache_dir=_snake_case					)
       self.assertRaises(datasets.builder.MissingBeamOptions       , builder.download_and_prepare					)



 @require_beam
 def 							_lowerCAmelCase					( self		:   Union[str, Any]					)					->      Tuple:




    '''simple docstring'''






    a__  					=		len(get_test_nested_examples()					)
    with tempfile.TemporaryDirectory() as tmp_cache_dir:
       a__  					=		NestedBeamDataset(cache_dir=_snake_case       , beam_runner='DirectRunner'					)
       builder.download_and_prepare()
       self.assertTrue(
           os.path.exists(
               os.path.join(_snake_case       , builder.name       , 'default'       , '0.0.0'       , F'''{builder.name}-train.arrow'''					)					)					)
       self.assertDictEqual(
           builder.info.features       , datasets.Features({'a': datasets.Sequence({'b': datasets.Value('string'					)}					)}					)					)
       a__  					=		builder.as_dataset()
       self.assertEqual(dset['train'].num_rows       , _snake_case					)
       self.assertEqual(dset['train'].info.splits['train'].num_examples       , _snake_case					)
       self.assertDictEqual(dset['train'][0]       , get_test_nested_examples()[0][1]					)
       self.assertDictEqual(
           dset['train'][expected_num_examples - 1]       , get_test_nested_examples()[expected_num_examples - 1][1]					)
       self.assertTrue(
           os.path.exists(os.path.join(_snake_case       , builder.name       , 'default'       , '0.0.0'       , 'dataset_info.json'					)					)					)
       del dset









from collections import OrderedDict
from typing import TYPE_CHECKING, Any, Mapping, Optional, Union

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


if TYPE_CHECKING:
		from ... import FeatureExtractionMixin, PreTrainedTokenizerBase, TensorType


_lowercase		:  Tuple			       =logging.get_logger(__name__)

_lowercase		:  Any			       ={
    """microsoft/deberta-v2-xlarge""": """https://huggingface.co/microsoft/deberta-v2-xlarge/resolve/main/config.json""",
    """microsoft/deberta-v2-xxlarge""": """https://huggingface.co/microsoft/deberta-v2-xxlarge/resolve/main/config.json""",
    """microsoft/deberta-v2-xlarge-mnli""": (
        """https://huggingface.co/microsoft/deberta-v2-xlarge-mnli/resolve/main/config.json"""
    ),
    """microsoft/deberta-v2-xxlarge-mnli""": (
        """https://huggingface.co/microsoft/deberta-v2-xxlarge-mnli/resolve/main/config.json"""
    ),
}






class 						UpperCamelCase_  (  snake_case__							):
					_a      :						int						    =					'deberta-v2'



					def __init__(		self     :     Any       ,      lowerCamelCase     :     Dict=12_81_00       ,      lowerCamelCase     :     List[Any]=15_36       ,      lowerCamelCase     :     Union[str, Any]=24       ,      lowerCamelCase     :     Union[str, Any]=24       ,      lowerCamelCase     :     Optional[int]=61_44       ,      lowerCamelCase     :     Any="gelu"       ,      lowerCamelCase     :     int=0.1       ,      lowerCamelCase     :     str=0.1       ,      lowerCamelCase     :     Optional[int]=5_12       ,      lowerCamelCase     :     str=0       ,      lowerCamelCase     :     Union[str, Any]=0.02       ,      lowerCamelCase     :     List[str]=1E-7       ,      lowerCamelCase     :     Dict=False       ,      lowerCamelCase     :     List[Any]=-1       ,      lowerCamelCase     :     Union[str, Any]=0       ,      lowerCamelCase     :     Optional[int]=True       ,      lowerCamelCase     :     Optional[int]=None       ,      lowerCamelCase     :     Tuple=0       ,      lowerCamelCase     :     Tuple="gelu"       ,      **lowerCamelCase     :     Optional[int]       ,      ):
							super().__init__(**lowerCamelCase						)

							lowerCamelCase_	:     Any 						=      hidden_size
							lowerCamelCase_	:     Dict 						=      num_hidden_layers
							lowerCamelCase_	:     Optional[int] 						=      num_attention_heads
							lowerCamelCase_	:     Optional[int] 						=      intermediate_size
							lowerCamelCase_	:     str 						=      hidden_act
							lowerCamelCase_	:     int 						=      hidden_dropout_prob
							lowerCamelCase_	:     Tuple 						=      attention_probs_dropout_prob
							lowerCamelCase_	:     Union[str, Any] 						=      max_position_embeddings
							lowerCamelCase_	:     Union[str, Any] 						=      type_vocab_size
							lowerCamelCase_	:     List[Any] 						=      initializer_range
							lowerCamelCase_	:     Optional[Any] 						=      relative_attention
							lowerCamelCase_	:     List[Any] 						=      max_relative_positions
							lowerCamelCase_	:     Optional[int] 						=      pad_token_id
							lowerCamelCase_	:     int 						=      position_biased_input

							# Backwards compatibility
							if type(lowerCamelCase						) == str:
									lowerCamelCase_	:     Dict 						=      [x.strip() for x in pos_att_type.lower().split('|'						)]

							lowerCamelCase_	:     Optional[Any] 						=      pos_att_type
							lowerCamelCase_	:     List[Any] 						=      vocab_size
							lowerCamelCase_	:     Any 						=      layer_norm_eps

							lowerCamelCase_	:     int 						=      kwargs.get('pooler_hidden_size'       ,      lowerCamelCase						)
							lowerCamelCase_	:     Dict 						=      pooler_dropout
							lowerCamelCase_	:     Tuple 						=      pooler_hidden_act






class 						UpperCamelCase_  (  snake_case__							):



					@property
					def   __a     (		self     :     Optional[int]						):
							if self.task == "multiple-choice":
									lowerCamelCase_	:     Optional[Any] 						=      {0: 'batch', 1: 'choice', 2: 'sequence'}
							else:
									lowerCamelCase_	:     Any 						=      {0: 'batch', 1: 'sequence'}
							if self._config.type_vocab_size > 0:
									return OrderedDict(
									    [('input_ids', dynamic_axis), ('attention_mask', dynamic_axis), ('token_type_ids', dynamic_axis)]						)
							else:
									return OrderedDict([('input_ids', dynamic_axis), ('attention_mask', dynamic_axis)]						)



					@property
					def   __a     (		self     :     List[Any]						):
							return 12





					def   __a     (		self     :     Tuple       ,      lowerCamelCase     :     Union["PreTrainedTokenizerBase", "FeatureExtractionMixin"]       ,      lowerCamelCase     :     int = -1       ,      lowerCamelCase     :     int = -1       ,      lowerCamelCase     :     int = -1       ,      lowerCamelCase     :     bool = False       ,      lowerCamelCase     :     Optional["TensorType"] = None       ,      lowerCamelCase     :     int = 3       ,      lowerCamelCase     :     int = 40       ,      lowerCamelCase     :     int = 40       ,      lowerCamelCase     :     "PreTrainedTokenizerBase" = None       ,      ):
							lowerCamelCase_	:     Union[str, Any] 						=      super().generate_dummy_inputs(preprocessor=lowerCamelCase       ,      framework=lowerCamelCase						)
							if self._config.type_vocab_size == 0 and "token_type_ids" in dummy_inputs:
									del dummy_inputs["token_type_ids"]
							return dummy_inputs
