





import importlib
import inspect
from functools import wraps
from typing import TYPE_CHECKING, Optional, Union

from .download.streaming_download_manager import (
    xbasename,
    xdirname,
    xet_parse,
    xexists,
    xgetsize,
    xglob,
    xgzip_open,
    xisdir,
    xisfile,
    xjoin,
    xlistdir,
    xnumpy_load,
    xopen,
    xpandas_read_csv,
    xpandas_read_excel,
    xPath,
    xrelpath,
    xsio_loadmat,
    xsplit,
    xsplitext,
    xwalk,
    xxml_dom_minidom_parse,
)
from .utils.logging import get_logger
from .utils.patching import patch_submodule
from .utils.py_utils import get_imports


UpperCAmelCase_											=  get_logger(__name__)


if TYPE_CHECKING:
   from .builder import DatasetBuilder
def     A__					(						SCREAMING_SNAKE_CASE_      :			Dict							,  SCREAMING_SNAKE_CASE_      :			Optional[Union[str, bool]] = None	)     ->     Any:






   """simple docstring"""







   _UpperCAmelCase											=      importlib.import_module(SCREAMING_SNAKE_CASE_	)

   # TODO(QL): always update the module to add subsequent new authentication
   if hasattr(SCREAMING_SNAKE_CASE_							,  '''_patched_for_streaming'''	) and module._patched_for_streaming:
      return

   def wrap_auth(SCREAMING_SNAKE_CASE_      :			Any	):
      @wraps(SCREAMING_SNAKE_CASE_	)
      def wrapper(*SCREAMING_SNAKE_CASE_      :			List[str]							,  **SCREAMING_SNAKE_CASE_      :			Optional[int]	):
         return function(*SCREAMING_SNAKE_CASE_							,  use_auth_token=SCREAMING_SNAKE_CASE_							,  **SCREAMING_SNAKE_CASE_	)

      _UpperCAmelCase											=      '''wrap_auth'''
      return wrapper

   # open files in a streaming fashion
   patch_submodule(SCREAMING_SNAKE_CASE_							,  '''open'''							,  wrap_auth(SCREAMING_SNAKE_CASE_	)	).start()
   patch_submodule(SCREAMING_SNAKE_CASE_							,  '''os.listdir'''							,  wrap_auth(SCREAMING_SNAKE_CASE_	)	).start()
   patch_submodule(SCREAMING_SNAKE_CASE_							,  '''os.walk'''							,  wrap_auth(SCREAMING_SNAKE_CASE_	)	).start()
   patch_submodule(SCREAMING_SNAKE_CASE_							,  '''glob.glob'''							,  wrap_auth(SCREAMING_SNAKE_CASE_	)	).start()
   # allow to navigate in remote zip files
   patch_submodule(SCREAMING_SNAKE_CASE_							,  '''os.path.join'''							,  SCREAMING_SNAKE_CASE_	).start()
   patch_submodule(SCREAMING_SNAKE_CASE_							,  '''os.path.dirname'''							,  SCREAMING_SNAKE_CASE_	).start()
   patch_submodule(SCREAMING_SNAKE_CASE_							,  '''os.path.basename'''							,  SCREAMING_SNAKE_CASE_	).start()
   patch_submodule(SCREAMING_SNAKE_CASE_							,  '''os.path.relpath'''							,  SCREAMING_SNAKE_CASE_	).start()
   patch_submodule(SCREAMING_SNAKE_CASE_							,  '''os.path.split'''							,  SCREAMING_SNAKE_CASE_	).start()
   patch_submodule(SCREAMING_SNAKE_CASE_							,  '''os.path.splitext'''							,  SCREAMING_SNAKE_CASE_	).start()
   # allow checks on paths
   patch_submodule(SCREAMING_SNAKE_CASE_							,  '''os.path.exists'''							,  wrap_auth(SCREAMING_SNAKE_CASE_	)	).start()
   patch_submodule(SCREAMING_SNAKE_CASE_							,  '''os.path.isdir'''							,  wrap_auth(SCREAMING_SNAKE_CASE_	)	).start()
   patch_submodule(SCREAMING_SNAKE_CASE_							,  '''os.path.isfile'''							,  wrap_auth(SCREAMING_SNAKE_CASE_	)	).start()
   patch_submodule(SCREAMING_SNAKE_CASE_							,  '''os.path.getsize'''							,  wrap_auth(SCREAMING_SNAKE_CASE_	)	).start()
   patch_submodule(SCREAMING_SNAKE_CASE_							,  '''pathlib.Path'''							,  SCREAMING_SNAKE_CASE_	).start()
   # file readers
   patch_submodule(SCREAMING_SNAKE_CASE_							,  '''gzip.open'''							,  wrap_auth(SCREAMING_SNAKE_CASE_	)	).start()
   patch_submodule(SCREAMING_SNAKE_CASE_							,  '''numpy.load'''							,  wrap_auth(SCREAMING_SNAKE_CASE_	)	).start()
   patch_submodule(SCREAMING_SNAKE_CASE_							,  '''pandas.read_csv'''							,  wrap_auth(SCREAMING_SNAKE_CASE_	)							,  attrs=['''__version__''']	).start()
   patch_submodule(SCREAMING_SNAKE_CASE_							,  '''pandas.read_excel'''							,  wrap_auth(SCREAMING_SNAKE_CASE_	)							,  attrs=['''__version__''']	).start()
   patch_submodule(SCREAMING_SNAKE_CASE_							,  '''scipy.io.loadmat'''							,  wrap_auth(SCREAMING_SNAKE_CASE_	)							,  attrs=['''__version__''']	).start()
   patch_submodule(SCREAMING_SNAKE_CASE_							,  '''xml.etree.ElementTree.parse'''							,  wrap_auth(SCREAMING_SNAKE_CASE_	)	).start()
   patch_submodule(SCREAMING_SNAKE_CASE_							,  '''xml.dom.minidom.parse'''							,  wrap_auth(SCREAMING_SNAKE_CASE_	)	).start()
   _UpperCAmelCase											=      True
def     A__					(						SCREAMING_SNAKE_CASE_      :			"DatasetBuilder"	)     ->     Tuple:






   """simple docstring"""







   extend_module_for_streaming(builder.__module__							,  use_auth_token=builder.use_auth_token	)
   # if needed, we also have to extend additional internal imports (like wmt14 -> wmt_utils)
   if not builder.__module__.startswith('''datasets.'''	):  # check that it's not a packaged builder like csv
      for imports in get_imports(inspect.getfile(builder.__class__	)	):
         if imports[0] == "internal":
            _UpperCAmelCase											=      imports[1]
            _UpperCAmelCase											=      '''.'''.join(builder.__module__.split('''.'''	)[:-1] + [internal_import_name]	)
            extend_module_for_streaming(SCREAMING_SNAKE_CASE_							,  use_auth_token=builder.use_auth_token	)

    # builders can inherit from other builders that might use streaming functionality
    # (for example, ImageFolder and AudioFolder inherit from FolderBuilder which implements examples generation)
    # but these parents builders are not patched automatically as they are not instantiated, so we patch them here
   from .builder import DatasetBuilder

   _UpperCAmelCase											=      [
       cls.__module__
       for cls in type(SCREAMING_SNAKE_CASE_	).__mro__[1:]  # make sure it's not the same module we've already patched
       if issubclass(cls							,  SCREAMING_SNAKE_CASE_	) and cls.__module__ != DatasetBuilder.__module__
   ]  # check it's not a standard builder from datasets.builder
   for module in parent_builder_modules:
      extend_module_for_streaming(SCREAMING_SNAKE_CASE_							,  use_auth_token=builder.use_auth_token	)






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


UpperCAmelCase_											=  logging.get_logger(__name__)

UpperCAmelCase_											=  {
    "microsoft/deberta-base": "https://huggingface.co/microsoft/deberta-base/resolve/main/config.json",
    "microsoft/deberta-large": "https://huggingface.co/microsoft/deberta-large/resolve/main/config.json",
    "microsoft/deberta-xlarge": "https://huggingface.co/microsoft/deberta-xlarge/resolve/main/config.json",
    "microsoft/deberta-base-mnli": "https://huggingface.co/microsoft/deberta-base-mnli/resolve/main/config.json",
    "microsoft/deberta-large-mnli": "https://huggingface.co/microsoft/deberta-large-mnli/resolve/main/config.json",
    "microsoft/deberta-xlarge-mnli": "https://huggingface.co/microsoft/deberta-xlarge-mnli/resolve/main/config.json",
}




class  __UpperCamelCase						(       A__						):
     __A  :     Dict            =      """deberta"""





     def __init__(    self							,       _UpperCamelCase=50265							,       _UpperCamelCase=768							,       _UpperCamelCase=12							,       _UpperCamelCase=12							,       _UpperCamelCase=3072							,       _UpperCamelCase="gelu"							,       _UpperCamelCase=0.1							,       _UpperCamelCase=0.1							,       _UpperCamelCase=512							,       _UpperCamelCase=0							,       _UpperCamelCase=0.02							,       _UpperCamelCase=1e-7							,       _UpperCamelCase=False							,       _UpperCamelCase=-1							,       _UpperCamelCase=0							,       _UpperCamelCase=True							,       _UpperCamelCase=None							,       _UpperCamelCase=0							,       _UpperCamelCase="gelu"							,       **_UpperCamelCase							,       ):
        super().__init__(**_UpperCamelCase				)

        _UpperCAmelCase											=      hidden_size
        _UpperCAmelCase											=      num_hidden_layers
        _UpperCAmelCase											=      num_attention_heads
        _UpperCAmelCase											=      intermediate_size
        _UpperCAmelCase											=      hidden_act
        _UpperCAmelCase											=      hidden_dropout_prob
        _UpperCAmelCase											=      attention_probs_dropout_prob
        _UpperCAmelCase											=      max_position_embeddings
        _UpperCAmelCase											=      type_vocab_size
        _UpperCAmelCase											=      initializer_range
        _UpperCAmelCase											=      relative_attention
        _UpperCAmelCase											=      max_relative_positions
        _UpperCAmelCase											=      pad_token_id
        _UpperCAmelCase											=      position_biased_input

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

        _UpperCAmelCase											=      pos_att_type
        _UpperCAmelCase											=      vocab_size
        _UpperCAmelCase											=      layer_norm_eps

        _UpperCAmelCase											=      kwargs.get('''pooler_hidden_size'''							,       _UpperCamelCase				)
        _UpperCAmelCase											=      pooler_dropout
        _UpperCAmelCase											=      pooler_hidden_act




class  __UpperCamelCase						(       A__						):





     @property
     def 		UpperCamelCase(    self				):
        if self.task == "multiple-choice":
           _UpperCAmelCase											=      {0: '''batch''', 1: '''choice''', 2: '''sequence'''}
        else:
           _UpperCAmelCase											=      {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 		UpperCamelCase(    self				):
        return 12





     def 		UpperCamelCase(    self							,       _UpperCamelCase							,       _UpperCamelCase = -1							,       _UpperCamelCase = -1							,       _UpperCamelCase = -1							,       _UpperCamelCase = False							,       _UpperCamelCase = None							,       _UpperCamelCase = 3							,       _UpperCamelCase = 40							,       _UpperCamelCase = 40							,       _UpperCamelCase = None							,       ):
        _UpperCAmelCase											=      super().generate_dummy_inputs(preprocessor=_UpperCamelCase							,       framework=_UpperCamelCase				)
        if self._config.type_vocab_size == 0 and "token_type_ids" in dummy_inputs:
           del dummy_inputs["token_type_ids"]
        return dummy_inputs