
import json
import os
import pickle
import subprocess
from hashlib import mda
from pathlib import Path
from tempfile import gettempdir
from textwrap import dedent
from types import CodeType, FunctionType
from unittest import TestCase
from unittest.mock import patch

import pytest
from multiprocess import Pool
from packaging import version

import datasets
from datasets.fingerprint import Hasher, fingerprint_transform
from datasets.table import InMemoryTable

from .utils import (
    require_regex,
    require_spacy,
    require_spacy_model,
    require_tiktoken,
    require_torch,
    require_transformers,
)







class  _lowerCamelCase			:

     def __init__(  self							,       SCREAMING_SNAKE_CASE_    ):
            __snake_case						       =   foo

     def __call__(  self    ):
            return self.foo







class  _lowerCamelCase			(datasets.Dataset					):

     @fingerprint_transform(inplace=SCREAMING_SNAKE_CASE_    )
     def 						__lowerCamelCase				(  self							,       SCREAMING_SNAKE_CASE_							,       *SCREAMING_SNAKE_CASE_							,       **SCREAMING_SNAKE_CASE_    ):
            return DatasetChild(self.data							,       fingerprint=SCREAMING_SNAKE_CASE_    )

     @fingerprint_transform(inplace=SCREAMING_SNAKE_CASE_    )
     def 						__lowerCamelCase				(  self							,       SCREAMING_SNAKE_CASE_							,       *SCREAMING_SNAKE_CASE_							,       **SCREAMING_SNAKE_CASE_    ):
            return DatasetChild(self.data							,       fingerprint=SCREAMING_SNAKE_CASE_    )







class  _lowerCamelCase			:

     def __init__(  self							,       SCREAMING_SNAKE_CASE_    ):
            __snake_case						       =   callable

     def __call__(  self							,       *SCREAMING_SNAKE_CASE_							,       **SCREAMING_SNAKE_CASE_    ):
            if self.callable is not None:
                   return self.callable(*SCREAMING_SNAKE_CASE_							,       **SCREAMING_SNAKE_CASE_    )

     def __getstate__(  self    ):
            raise pickle.PicklingError()







class  _lowerCamelCase			(lowerCamelCase					):

     @require_transformers
     @pytest.mark.integration
     def 						__lowerCamelCase				(  self    ):
            from transformers import AutoTokenizer

            def encode(SCREAMING_SNAKE_CASE_    ):
                   return tokenizer(SCREAMING_SNAKE_CASE_    )

            # TODO: add hash consistency tests across sessions
            __snake_case						       =   AutoTokenizer.from_pretrained('bert-base-uncased'    )
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE_    )    ).hexdigest()
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(lambda SCREAMING_SNAKE_CASE_    : tokenizer(SCREAMING_SNAKE_CASE_    )    )    ).hexdigest()
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE_    )    ).hexdigest()
            __snake_case						       =   AutoTokenizer.from_pretrained('bert-base-cased'    )
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE_    )    ).hexdigest()
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(lambda SCREAMING_SNAKE_CASE_    : tokenizer(SCREAMING_SNAKE_CASE_    )    )    ).hexdigest()
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE_    )    ).hexdigest()
            __snake_case						       =   AutoTokenizer.from_pretrained('bert-base-uncased'    )
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE_    )    ).hexdigest()
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(lambda SCREAMING_SNAKE_CASE_    : tokenizer(SCREAMING_SNAKE_CASE_    )    )    ).hexdigest()
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE_    )    ).hexdigest()
            self.assertEqual(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )
            self.assertNotEqual(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )
            self.assertEqual(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )
            self.assertNotEqual(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )
            self.assertEqual(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )
            self.assertNotEqual(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )

     @require_transformers
     @pytest.mark.integration
     def 						__lowerCamelCase				(  self    ):
            from transformers import AutoTokenizer

            __snake_case						       =   AutoTokenizer.from_pretrained('gpt2'    )
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE_    )    ).hexdigest()
            tokenizer('Hello world !'    )  # call once to change the tokenizer's cache
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE_    )    ).hexdigest()
            self.assertEqual(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )

     @require_regex
     def 						__lowerCamelCase				(  self    ):
            import regex

            __snake_case						       =   regex.Regex('foo'    )
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE_    )    ).hexdigest()
            __snake_case						       =   regex.Regex('bar'    )
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE_    )    ).hexdigest()
            __snake_case						       =   regex.Regex('foo'    )
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE_    )    ).hexdigest()
            self.assertEqual(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )
            self.assertNotEqual(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )







class  _lowerCamelCase			(lowerCamelCase					):

     def 						__lowerCamelCase				(  self    ):
            def func():
                   return foo

            __snake_case						       =   [0]
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE_    )    ).hexdigest()
            __snake_case						       =   [1]
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE_    )    ).hexdigest()
            __snake_case						       =   [0]
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE_    )    ).hexdigest()
            self.assertEqual(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )
            self.assertNotEqual(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )

     def 						__lowerCamelCase				(  self    ):
            def func():
                   pass

            __snake_case						       =   mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE_    )    ).hexdigest()

            def func():
                   pass

            __snake_case						       =   mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE_    )    ).hexdigest()
            self.assertEqual(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )

     def 						__lowerCamelCase				(  self    ):
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(Foo([0]    )    )    ).hexdigest()
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(Foo([1]    )    )    ).hexdigest()
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(Foo([0]    )    )    ).hexdigest()
            self.assertEqual(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )
            self.assertNotEqual(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )

     def 						__lowerCamelCase				(  self    ):
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(Foo([0]    ).__call__    )    ).hexdigest()
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(Foo([1]    ).__call__    )    ).hexdigest()
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(Foo([0]    ).__call__    )    ).hexdigest()
            self.assertEqual(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )
            self.assertNotEqual(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )

     def 						__lowerCamelCase				(  self    ):
            __snake_case						       =   (
                'co_argcount',
                'co_kwonlyargcount',
                'co_nlocals',
                'co_stacksize',
                'co_flags',
                'co_code',
                'co_consts',
                'co_names',
                'co_varnames',
                'co_filename',
                'co_name',
                'co_firstlineno',
                'co_lnotab',
                'co_freevars',
                'co_cellvars',
            )

            def _create_code_pyaa(*SCREAMING_SNAKE_CASE_    ):
                   if hasattr(args[-3]							,       'encode'    ):
                          __snake_case						       =   list(SCREAMING_SNAKE_CASE_    )
                          __snake_case						       =   args[-3].encode()  # co_lnotab
                          __snake_case						       =   args[-10].encode()  # co_code
                   if hasattr(SCREAMING_SNAKE_CASE_							,       'co_posonlyargcount'    ):
                          if len(SCREAMING_SNAKE_CASE_    ) == 16:
                                 return CodeType(*SCREAMING_SNAKE_CASE_    )
                          elif len(SCREAMING_SNAKE_CASE_    ) == 15:
                                 return CodeType(args[0]							,       0							,       *args[1:]    )
                          return CodeType(args[0]							,       0							,       0							,       *args[1:]    )
                   elif hasattr(SCREAMING_SNAKE_CASE_							,       'co_kwonlyargcount'    ):
                          if len(SCREAMING_SNAKE_CASE_    ) == 16:
                                 return CodeType(args[0]							,       *args[2:]    )
                          elif len(SCREAMING_SNAKE_CASE_    ) == 15:
                                 return CodeType(*SCREAMING_SNAKE_CASE_    )
                          return CodeType(args[0]							,       0							,       *args[1:]    )
                   if len(SCREAMING_SNAKE_CASE_    ) == 16:
                          return CodeType(args[0]							,       *args[3:]    )
                   elif len(SCREAMING_SNAKE_CASE_    ) == 15:
                          return CodeType(args[0]							,       *args[2:]    )
                   return CodeType(*SCREAMING_SNAKE_CASE_    )

            def create_ipython_func(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    ):
                   def func():
                          return returned_obj

                   __snake_case						       =   func.__code__
                   # Use _create_code from dill in order to make it work for different python versions
                   if datasets.config.PY_VERSION < version.parse('3.8'    ):
                          __snake_case						       =   _create_code_pyaa(
                              *[getattr(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    ) if k != 'co_filename' else co_filename for k in code_args_pyaa]    )
                   else:
                          __snake_case						       =   code.replace(co_filename=SCREAMING_SNAKE_CASE_    )
                   return FunctionType(SCREAMING_SNAKE_CASE_							,       func.__globals__							,       func.__name__							,       func.__defaults__							,       func.__closure__    )

            __snake_case       ,       __snake_case						       =   '<ipython-input-2-e0383a102aae>', [0]
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(create_ipython_func(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )    )    ).hexdigest()
            __snake_case       ,       __snake_case						       =   '<ipython-input-2-e0383a102aae>', [1]
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(create_ipython_func(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )    )    ).hexdigest()
            __snake_case       ,       __snake_case						       =   '<ipython-input-5-713f6613acf3>', [0]
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(create_ipython_func(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )    )    ).hexdigest()
            self.assertEqual(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )
            self.assertNotEqual(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )

            __snake_case       ,       __snake_case						       =   os.path.join(gettempdir()							,       'ipykernel_12345'							,       '321456789.py'    ), [0]
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(create_ipython_func(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )    )    ).hexdigest()
            __snake_case       ,       __snake_case						       =   os.path.join(gettempdir()							,       'ipykernel_12345'							,       '321456789.py'    ), [1]
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(create_ipython_func(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )    )    ).hexdigest()
            __snake_case       ,       __snake_case						       =   os.path.join(gettempdir()							,       'ipykernel_12345'							,       '654123987.py'    ), [0]
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(create_ipython_func(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )    )    ).hexdigest()
            self.assertEqual(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )
            self.assertNotEqual(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )

     def 						__lowerCamelCase				(  self    ):
            __snake_case       ,       __snake_case						       =   [0], [1]

            def func():
                   return foo, bar

            __snake_case						       =   '__main__'

            def globalvars_mocka_side_effect(SCREAMING_SNAKE_CASE_							,       *SCREAMING_SNAKE_CASE_							,       **SCREAMING_SNAKE_CASE_    ):
                   return {"foo": foo, "bar": bar}

            def globalvars_mocka_side_effect(SCREAMING_SNAKE_CASE_							,       *SCREAMING_SNAKE_CASE_							,       **SCREAMING_SNAKE_CASE_    ):
                   return {"bar": bar, "foo": foo}

            with patch('dill.detect.globalvars'							,       side_effect=SCREAMING_SNAKE_CASE_    ) as globalvars_mocka:
                   __snake_case						       =   mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE_    )    ).hexdigest()
                   self.assertGreater(globalvars_mocka.call_count							,       0    )
            with patch('dill.detect.globalvars'							,       side_effect=SCREAMING_SNAKE_CASE_    ) as globalvars_mocka:
                   __snake_case						       =   mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE_    )    ).hexdigest()
                   self.assertGreater(globalvars_mocka.call_count							,       0    )
            self.assertEqual(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )







class  _lowerCamelCase			(lowerCamelCase					):

     def 						__lowerCamelCase				(  self    ):
            __snake_case						       =   Hasher.hash('hello'    )
            __snake_case						       =   Hasher.hash('hello'    )
            __snake_case						       =   Hasher.hash('there'    )
            self.assertEqual(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )
            self.assertNotEqual(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )

     def 						__lowerCamelCase				(  self    ):
            __snake_case						       =   Hasher.hash(Foo('hello'    )    )
            __snake_case						       =   Hasher.hash(Foo('hello'    )    )
            __snake_case						       =   Hasher.hash(Foo('there'    )    )
            self.assertEqual(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )
            self.assertNotEqual(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )

     def 						__lowerCamelCase				(  self    ):
            __snake_case						       =   Hasher()
            for x in ["hello", Foo('hello'    )]:
                   hasher.update(SCREAMING_SNAKE_CASE_    )
            __snake_case						       =   hasher.hexdigest()
            __snake_case						       =   Hasher()
            for x in ["hello", Foo('hello'    )]:
                   hasher.update(SCREAMING_SNAKE_CASE_    )
            __snake_case						       =   hasher.hexdigest()
            __snake_case						       =   Hasher()
            for x in ["there", Foo('there'    )]:
                   hasher.update(SCREAMING_SNAKE_CASE_    )
            __snake_case						       =   hasher.hexdigest()
            self.assertEqual(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )
            self.assertNotEqual(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )

     def 						__lowerCamelCase				(  self    ):
            with self.assertRaises(pickle.PicklingError    ):
                   Hasher.hash(UnpicklableCallable(Foo('hello'    )    )    )

     def 						__lowerCamelCase				(  self    ):
            __snake_case						       =   'abc'
            __snake_case						       =   [string, string]  # two strings have the same ids
            __snake_case						       =   [string, string]
            __snake_case						       =   json.loads(f'''["{string}", "{string}"]'''    )  # two strings have different ids
            self.assertIs(obja[0]							,       SCREAMING_SNAKE_CASE_    )
            self.assertIs(obja[0]							,       obja[1]    )
            self.assertIs(obja[0]							,       SCREAMING_SNAKE_CASE_    )
            self.assertIs(obja[0]							,       obja[1]    )
            self.assertIsNot(obja[0]							,       SCREAMING_SNAKE_CASE_    )
            self.assertIsNot(obja[0]							,       obja[1]    )
            __snake_case						       =   Hasher.hash(SCREAMING_SNAKE_CASE_    )
            __snake_case						       =   Hasher.hash(SCREAMING_SNAKE_CASE_    )
            __snake_case						       =   Hasher.hash(SCREAMING_SNAKE_CASE_    )
            self.assertEqual(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )
            self.assertEqual(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )

     @require_tiktoken
     def 						__lowerCamelCase				(  self    ):
            import tiktoken

            __snake_case						       =   tiktoken.get_encoding('gpt2'    )
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE_    )    ).hexdigest()
            __snake_case						       =   tiktoken.get_encoding('r50k_base'    )
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE_    )    ).hexdigest()
            __snake_case						       =   tiktoken.get_encoding('gpt2'    )
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE_    )    ).hexdigest()
            self.assertEqual(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )
            self.assertNotEqual(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )

     @require_torch
     def 						__lowerCamelCase				(  self    ):
            import torch

            __snake_case						       =   torch.tensor([1.0]    )
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE_    )    ).hexdigest()
            __snake_case						       =   torch.tensor([2.0]    )
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE_    )    ).hexdigest()
            __snake_case						       =   torch.tensor([1.0]    )
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE_    )    ).hexdigest()
            self.assertEqual(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )
            self.assertNotEqual(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )

     @require_spacy
     @require_spacy_model('en_core_web_sm'    )
     @require_spacy_model('fr_core_news_sm'    )
     @pytest.mark.integration
     def 						__lowerCamelCase				(  self    ):
            import spacy

            __snake_case						       =   spacy.load('en_core_web_sm'    )
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE_    )    ).hexdigest()
            __snake_case						       =   spacy.load('fr_core_news_sm'    )
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE_    )    ).hexdigest()
            __snake_case						       =   spacy.load('en_core_web_sm'    )
            __snake_case						       =   mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE_    )    ).hexdigest()
            self.assertEqual(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )
            self.assertNotEqual(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )





@pytest.mark.integration
def        __lowercase(							__snake_case				:		Path					)       ->   int:
       __snake_case						       =   tmp_path / 'dir1'
       __snake_case						       =   tmp_path / 'dir2'
       dira.mkdir()
       dira.mkdir()
       __snake_case						       =   'script.py'
       __snake_case						       =   dedent(
           '\n    from datasets.fingerprint import Hasher\n    def foo():\n        pass\n    print(Hasher.hash(foo))\n    '					)
       __snake_case						       =   dira / script_filename
       __snake_case						       =   dira / script_filename
       with script_patha.open('w'					) as f:
              f.write(__snake_case					)
       with script_patha.open('w'					) as f:
              f.write(__snake_case					)
       __snake_case						       =   subprocess.check_output(['python', str(__snake_case					)]					)
       __snake_case						       =   subprocess.check_output(['python', str(__snake_case					)]					)
       assert fingerprinta == fingerprinta
def        __lowercase(							)       ->   Any:
       __snake_case						       =   {'a': [0, 1, 2]}
       __snake_case						       =   DatasetChild(InMemoryTable.from_pydict(__snake_case					)					)
       __snake_case						       =   dataset.funca()._fingerprint
       assert expected_fingerprint == dataset.funca()._fingerprint
       assert expected_fingerprint != dataset.funca()._fingerprint

       with Pool(2					) as p:
              assert expected_fingerprint == p.apply_async(dataset.funca					).get()._fingerprint
              assert expected_fingerprint != p.apply_async(dataset.funca					).get()._fingerprint
def        __lowercase(							)       ->   Any:
       __snake_case						       =   {'a': [0, 1, 2]}







       class  _lowerCamelCase			(datasets.Dataset					):

            @fingerprint_transform(inplace=SCREAMING_SNAKE_CASE_    )
            def 						__lowerCamelCase				(  self							,       SCREAMING_SNAKE_CASE_    ):
                   return DummyDatasetChild(self.data							,       fingerprint=SCREAMING_SNAKE_CASE_    )





       __snake_case						       =   DummyDatasetChild(InMemoryTable.from_pydict(__snake_case					)					).func()







       class  _lowerCamelCase			(datasets.Dataset					):

            @fingerprint_transform(inplace=SCREAMING_SNAKE_CASE_							,       version='1.0.0'    )
            def 						__lowerCamelCase				(  self							,       SCREAMING_SNAKE_CASE_    ):
                   return DummyDatasetChild(self.data							,       fingerprint=SCREAMING_SNAKE_CASE_    )





       __snake_case						       =   DummyDatasetChild(InMemoryTable.from_pydict(__snake_case					)					).func()







       class  _lowerCamelCase			(datasets.Dataset					):

            @fingerprint_transform(inplace=SCREAMING_SNAKE_CASE_							,       version='2.0.0'    )
            def 						__lowerCamelCase				(  self							,       SCREAMING_SNAKE_CASE_    ):
                   return DummyDatasetChild(self.data							,       fingerprint=SCREAMING_SNAKE_CASE_    )





       __snake_case						       =   DummyDatasetChild(InMemoryTable.from_pydict(__snake_case					)					).func()

       assert len({fingeprint_no_version, fingeprint_a, fingeprint_a}					) == 3
def        __lowercase(							)       ->   Tuple:
       # AttributeError: module 'dill._dill' has no attribute 'stack'
       __snake_case						       =   Hasher()
       hasher.update(lambda __snake_case					: x					)


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


lowerCamelCase_				:							Any       =    logging.get_logger(__name__)

lowerCamelCase_				:							Optional[Any]       =    {
    "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  _lowerCamelCase			(lowerCamelCase					):
     lowercase__				  =			"""deberta"""

     def __init__(  self							,       SCREAMING_SNAKE_CASE_=50_265							,       SCREAMING_SNAKE_CASE_=768							,       SCREAMING_SNAKE_CASE_=12							,       SCREAMING_SNAKE_CASE_=12							,       SCREAMING_SNAKE_CASE_=3_072							,       SCREAMING_SNAKE_CASE_="gelu"							,       SCREAMING_SNAKE_CASE_=0.1							,       SCREAMING_SNAKE_CASE_=0.1							,       SCREAMING_SNAKE_CASE_=512							,       SCREAMING_SNAKE_CASE_=0							,       SCREAMING_SNAKE_CASE_=0.0_2							,       SCREAMING_SNAKE_CASE_=1E-7							,       SCREAMING_SNAKE_CASE_=False							,       SCREAMING_SNAKE_CASE_=-1							,       SCREAMING_SNAKE_CASE_=0							,       SCREAMING_SNAKE_CASE_=True							,       SCREAMING_SNAKE_CASE_=None							,       SCREAMING_SNAKE_CASE_=0							,       SCREAMING_SNAKE_CASE_="gelu"							,       **SCREAMING_SNAKE_CASE_							,       ):
            super().__init__(**SCREAMING_SNAKE_CASE_    )

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

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

            __snake_case						       =   pos_att_type
            __snake_case						       =   vocab_size
            __snake_case						       =   layer_norm_eps

            __snake_case						       =   kwargs.get('pooler_hidden_size'							,       SCREAMING_SNAKE_CASE_    )
            __snake_case						       =   pooler_dropout
            __snake_case						       =   pooler_hidden_act







class  _lowerCamelCase			(lowerCamelCase					):

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

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