


'''simple docstring'''







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 A__	:






      def __init__(			self      :Optional[Any]					,						SCREAMING_SNAKE_CASE      :Dict     )	-> Any:




             '''simple docstring'''
             _a   :			Tuple					 =foo






      def __call__(			self      :Optional[int]     )	-> Dict:




             '''simple docstring'''
             return self.foo







class A__	(						datasets.Dataset				):






      @fingerprint_transform(inplace=SCREAMING_SNAKE_CASE     )
      def __UpperCAmelCase	(			self      :Union[str, Any]					,						SCREAMING_SNAKE_CASE      :str					,						*SCREAMING_SNAKE_CASE      :List[str]					,						**SCREAMING_SNAKE_CASE      :Union[str, Any]     )	-> Optional[int]:




             '''simple docstring'''
             return DatasetChild(self.data					,						fingerprint=SCREAMING_SNAKE_CASE     )






      @fingerprint_transform(inplace=SCREAMING_SNAKE_CASE     )
      def __UpperCAmelCase	(			self      :Optional[int]					,						SCREAMING_SNAKE_CASE      :Any					,						*SCREAMING_SNAKE_CASE      :Optional[int]					,						**SCREAMING_SNAKE_CASE      :int     )	-> Optional[int]:




             '''simple docstring'''
             return DatasetChild(self.data					,						fingerprint=SCREAMING_SNAKE_CASE     )







class A__	:






      def __init__(			self      :Union[str, Any]					,						SCREAMING_SNAKE_CASE      :Optional[Any]     )	-> Dict:




             '''simple docstring'''
             _a   :			Dict					 =callable






      def __call__(			self      :Union[str, Any]					,						*SCREAMING_SNAKE_CASE      :Union[str, Any]					,						**SCREAMING_SNAKE_CASE      :Tuple     )	-> Union[str, Any]:




             '''simple docstring'''
             if self.callable is not None:
                    return self.callable(*SCREAMING_SNAKE_CASE					,						**SCREAMING_SNAKE_CASE     )






      def __getstate__(			self      :List[Any]     )	-> str:




             '''simple docstring'''
             raise pickle.PicklingError()







class A__	(						UpperCAmelCase__				):






      @require_transformers
      @pytest.mark.integration
      def __UpperCAmelCase	(			self      :List[Any]     )	-> Dict:




             '''simple docstring'''
             from transformers import AutoTokenizer

             def encode(SCREAMING_SNAKE_CASE      :List[Any]     ):
                    return tokenizer(SCREAMING_SNAKE_CASE     )

             # TODO: add hash consistency tests across sessions
             _a   :			str					 =AutoTokenizer.from_pretrained("""bert-base-uncased"""     )
             _a   :			Optional[Any]					 =mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE     )     ).hexdigest()
             _a   :			List[Any]					 =mda(datasets.utils.py_utils.dumps(lambda SCREAMING_SNAKE_CASE     : tokenizer(SCREAMING_SNAKE_CASE     )     )     ).hexdigest()
             _a   :			Dict					 =mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE     )     ).hexdigest()
             _a   :			List[Any]					 =AutoTokenizer.from_pretrained("""bert-base-cased"""     )
             _a   :			List[Any]					 =mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE     )     ).hexdigest()
             _a   :			Dict					 =mda(datasets.utils.py_utils.dumps(lambda SCREAMING_SNAKE_CASE     : tokenizer(SCREAMING_SNAKE_CASE     )     )     ).hexdigest()
             _a   :			Optional[Any]					 =mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE     )     ).hexdigest()
             _a   :			Optional[Any]					 =AutoTokenizer.from_pretrained("""bert-base-uncased"""     )
             _a   :			List[Any]					 =mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE     )     ).hexdigest()
             _a   :			str					 =mda(datasets.utils.py_utils.dumps(lambda SCREAMING_SNAKE_CASE     : tokenizer(SCREAMING_SNAKE_CASE     )     )     ).hexdigest()
             _a   :			Union[str, Any]					 =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 __UpperCAmelCase	(			self      :List[str]     )	-> Any:




             '''simple docstring'''
             from transformers import AutoTokenizer

             _a   :			Dict					 =AutoTokenizer.from_pretrained("""gpt2"""     )
             _a   :			int					 =mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE     )     ).hexdigest()
             tokenizer("""Hello world !"""     )  # call once to change the tokenizer's cache
             _a   :			Dict					 =mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE     )     ).hexdigest()
             self.assertEqual(SCREAMING_SNAKE_CASE					,						SCREAMING_SNAKE_CASE     )






      @require_regex
      def __UpperCAmelCase	(			self      :Dict     )	-> int:




             '''simple docstring'''
             import regex

             _a   :			Dict					 =regex.Regex("""foo"""     )
             _a   :			Any					 =mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE     )     ).hexdigest()
             _a   :			Dict					 =regex.Regex("""bar"""     )
             _a   :			Tuple					 =mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE     )     ).hexdigest()
             _a   :			Optional[int]					 =regex.Regex("""foo"""     )
             _a   :			List[str]					 =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 A__	(						UpperCAmelCase__				):






      def __UpperCAmelCase	(			self      :str     )	-> int:




             '''simple docstring'''
             def func():
                    return foo

             _a   :			Optional[Any]					 =[0]
             _a   :			Any					 =mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE     )     ).hexdigest()
             _a   :			Union[str, Any]					 =[1]
             _a   :			Union[str, Any]					 =mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE     )     ).hexdigest()
             _a   :			Optional[int]					 =[0]
             _a   :			Optional[int]					 =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 __UpperCAmelCase	(			self      :List[str]     )	-> Optional[Any]:




             '''simple docstring'''
             def func():
                    pass

             _a   :			List[str]					 =mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE     )     ).hexdigest()

             def func():
                    pass

             _a   :			str					 =mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE     )     ).hexdigest()
             self.assertEqual(SCREAMING_SNAKE_CASE					,						SCREAMING_SNAKE_CASE     )






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




             '''simple docstring'''
             _a   :			Optional[Any]					 =mda(datasets.utils.py_utils.dumps(Foo([0]     )     )     ).hexdigest()
             _a   :			str					 =mda(datasets.utils.py_utils.dumps(Foo([1]     )     )     ).hexdigest()
             _a   :			str					 =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 __UpperCAmelCase	(			self      :List[Any]     )	-> List[str]:




             '''simple docstring'''
             _a   :			List[str]					 =mda(datasets.utils.py_utils.dumps(Foo([0]     ).__call__     )     ).hexdigest()
             _a   :			Dict					 =mda(datasets.utils.py_utils.dumps(Foo([1]     ).__call__     )     ).hexdigest()
             _a   :			List[str]					 =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 __UpperCAmelCase	(			self      :Optional[int]     )	-> str:




             '''simple docstring'''
             _a   :			Dict					 =(
                 """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      :Optional[int]     ):
                    if hasattr(args[-3]					,						"""encode"""     ):
                           _a   :			Tuple					 =list(SCREAMING_SNAKE_CASE     )
                           _a   :			Tuple					 =args[-3].encode()  # co_lnotab
                           _a   :			List[Any]					 =args[-1_0].encode()  # co_code
                    if hasattr(SCREAMING_SNAKE_CASE					,						"""co_posonlyargcount"""     ):
                           if len(SCREAMING_SNAKE_CASE     ) == 1_6:
                                  return CodeType(*SCREAMING_SNAKE_CASE     )
                           elif len(SCREAMING_SNAKE_CASE     ) == 1_5:
                                  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     ) == 1_6:
                                  return CodeType(args[0]					,						*args[2:]     )
                           elif len(SCREAMING_SNAKE_CASE     ) == 1_5:
                                  return CodeType(*SCREAMING_SNAKE_CASE     )
                           return CodeType(args[0]					,						0					,						*args[1:]     )
                    if len(SCREAMING_SNAKE_CASE     ) == 1_6:
                           return CodeType(args[0]					,						*args[3:]     )
                    elif len(SCREAMING_SNAKE_CASE     ) == 1_5:
                           return CodeType(args[0]					,						*args[2:]     )
                    return CodeType(*SCREAMING_SNAKE_CASE     )

             def create_ipython_func(SCREAMING_SNAKE_CASE      :Optional[Any]					,						SCREAMING_SNAKE_CASE      :Tuple     ):
                    def func():
                           return returned_obj

                    _a   :			Optional[Any]					 =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"""     ):
                           _a   :			Union[str, Any]					 =_create_code_pyaa(
                               *[getattr(SCREAMING_SNAKE_CASE					,						SCREAMING_SNAKE_CASE     ) if k != """co_filename""" else co_filename for k in code_args_pyaa]     )
                    else:
                           _a   :			Optional[int]					 =code.replace(co_filename=SCREAMING_SNAKE_CASE     )
                    return FunctionType(SCREAMING_SNAKE_CASE					,						func.__globals__					,						func.__name__					,						func.__defaults__					,						func.__closure__     )

             _a ,   _a   :			Optional[Any]					 ="""<ipython-input-2-e0383a102aae>""", [0]
             _a   :			Union[str, Any]					 =mda(datasets.utils.py_utils.dumps(create_ipython_func(SCREAMING_SNAKE_CASE					,						SCREAMING_SNAKE_CASE     )     )     ).hexdigest()
             _a ,   _a   :			Optional[int]					 ="""<ipython-input-2-e0383a102aae>""", [1]
             _a   :			str					 =mda(datasets.utils.py_utils.dumps(create_ipython_func(SCREAMING_SNAKE_CASE					,						SCREAMING_SNAKE_CASE     )     )     ).hexdigest()
             _a ,   _a   :			List[str]					 ="""<ipython-input-5-713f6613acf3>""", [0]
             _a   :			Optional[Any]					 =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     )

             _a ,   _a   :			Tuple					 =os.path.join(gettempdir()					,						"""ipykernel_12345"""					,						"""321456789.py"""     ), [0]
             _a   :			List[str]					 =mda(datasets.utils.py_utils.dumps(create_ipython_func(SCREAMING_SNAKE_CASE					,						SCREAMING_SNAKE_CASE     )     )     ).hexdigest()
             _a ,   _a   :			List[str]					 =os.path.join(gettempdir()					,						"""ipykernel_12345"""					,						"""321456789.py"""     ), [1]
             _a   :			List[str]					 =mda(datasets.utils.py_utils.dumps(create_ipython_func(SCREAMING_SNAKE_CASE					,						SCREAMING_SNAKE_CASE     )     )     ).hexdigest()
             _a ,   _a   :			Tuple					 =os.path.join(gettempdir()					,						"""ipykernel_12345"""					,						"""654123987.py"""     ), [0]
             _a   :			Optional[Any]					 =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 __UpperCAmelCase	(			self      :str     )	-> Optional[Any]:




             '''simple docstring'''
             _a ,   _a   :			str					 =[0], [1]

             def func():
                    return foo, bar

             _a   :			int					 ="""__main__"""

             def globalvars_mocka_side_effect(SCREAMING_SNAKE_CASE      :List[str]					,						*SCREAMING_SNAKE_CASE      :Optional[Any]					,						**SCREAMING_SNAKE_CASE      :List[Any]     ):
                    return {"foo": foo, "bar": bar}

             def globalvars_mocka_side_effect(SCREAMING_SNAKE_CASE      :Tuple					,						*SCREAMING_SNAKE_CASE      :str					,						**SCREAMING_SNAKE_CASE      :Dict     ):
                    return {"bar": bar, "foo": foo}

             with patch("""dill.detect.globalvars"""					,						side_effect=SCREAMING_SNAKE_CASE     ) as globalvars_mocka:
                    _a   :			Tuple					 =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:
                    _a   :			Tuple					 =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 A__	(						UpperCAmelCase__				):






      def __UpperCAmelCase	(			self      :List[Any]     )	-> Union[str, Any]:




             '''simple docstring'''
             _a   :			List[Any]					 =Hasher.hash("""hello"""     )
             _a   :			Any					 =Hasher.hash("""hello"""     )
             _a   :			Tuple					 =Hasher.hash("""there"""     )
             self.assertEqual(SCREAMING_SNAKE_CASE					,						SCREAMING_SNAKE_CASE     )
             self.assertNotEqual(SCREAMING_SNAKE_CASE					,						SCREAMING_SNAKE_CASE     )






      def __UpperCAmelCase	(			self      :str     )	-> Dict:




             '''simple docstring'''
             _a   :			List[str]					 =Hasher.hash(Foo("""hello"""     )     )
             _a   :			List[Any]					 =Hasher.hash(Foo("""hello"""     )     )
             _a   :			List[Any]					 =Hasher.hash(Foo("""there"""     )     )
             self.assertEqual(SCREAMING_SNAKE_CASE					,						SCREAMING_SNAKE_CASE     )
             self.assertNotEqual(SCREAMING_SNAKE_CASE					,						SCREAMING_SNAKE_CASE     )






      def __UpperCAmelCase	(			self      :int     )	-> Optional[int]:




             '''simple docstring'''
             _a   :			Optional[Any]					 =Hasher()
             for x in ["hello", Foo("""hello"""     )]:
                    hasher.update(SCREAMING_SNAKE_CASE     )
             _a   :			Dict					 =hasher.hexdigest()
             _a   :			Optional[Any]					 =Hasher()
             for x in ["hello", Foo("""hello"""     )]:
                    hasher.update(SCREAMING_SNAKE_CASE     )
             _a   :			Tuple					 =hasher.hexdigest()
             _a   :			int					 =Hasher()
             for x in ["there", Foo("""there"""     )]:
                    hasher.update(SCREAMING_SNAKE_CASE     )
             _a   :			List[str]					 =hasher.hexdigest()
             self.assertEqual(SCREAMING_SNAKE_CASE					,						SCREAMING_SNAKE_CASE     )
             self.assertNotEqual(SCREAMING_SNAKE_CASE					,						SCREAMING_SNAKE_CASE     )






      def __UpperCAmelCase	(			self      :Union[str, Any]     )	-> Optional[int]:




             '''simple docstring'''
             with self.assertRaises(pickle.PicklingError     ):
                    Hasher.hash(UnpicklableCallable(Foo("""hello"""     )     )     )






      def __UpperCAmelCase	(			self      :Optional[int]     )	-> Union[str, Any]:




             '''simple docstring'''
             _a   :			Optional[int]					 ="""abc"""
             _a   :			str					 =[string, string]  # two strings have the same ids
             _a   :			List[Any]					 =[string, string]
             _a   :			Tuple					 =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]     )
             _a   :			Tuple					 =Hasher.hash(SCREAMING_SNAKE_CASE     )
             _a   :			List[str]					 =Hasher.hash(SCREAMING_SNAKE_CASE     )
             _a   :			List[str]					 =Hasher.hash(SCREAMING_SNAKE_CASE     )
             self.assertEqual(SCREAMING_SNAKE_CASE					,						SCREAMING_SNAKE_CASE     )
             self.assertEqual(SCREAMING_SNAKE_CASE					,						SCREAMING_SNAKE_CASE     )






      @require_tiktoken
      def __UpperCAmelCase	(			self      :Dict     )	-> Optional[Any]:




             '''simple docstring'''
             import tiktoken

             _a   :			Optional[Any]					 =tiktoken.get_encoding("""gpt2"""     )
             _a   :			List[str]					 =mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE     )     ).hexdigest()
             _a   :			int					 =tiktoken.get_encoding("""r50k_base"""     )
             _a   :			Optional[int]					 =mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE     )     ).hexdigest()
             _a   :			int					 =tiktoken.get_encoding("""gpt2"""     )
             _a   :			Optional[Any]					 =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 __UpperCAmelCase	(			self      :str     )	-> Tuple:




             '''simple docstring'''
             import torch

             _a   :			Dict					 =torch.tensor([1.0]     )
             _a   :			Tuple					 =mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE     )     ).hexdigest()
             _a   :			Tuple					 =torch.tensor([2.0]     )
             _a   :			Dict					 =mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE     )     ).hexdigest()
             _a   :			List[str]					 =torch.tensor([1.0]     )
             _a   :			Tuple					 =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 __UpperCAmelCase	(			self      :List[str]     )	-> int:




             '''simple docstring'''
             import spacy

             _a   :			Union[str, Any]					 =spacy.load("""en_core_web_sm"""     )
             _a   :			Union[str, Any]					 =mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE     )     ).hexdigest()
             _a   :			Any					 =spacy.load("""fr_core_news_sm"""     )
             _a   :			Tuple					 =mda(datasets.utils.py_utils.dumps(SCREAMING_SNAKE_CASE     )     ).hexdigest()
             _a   :			int					 =spacy.load("""en_core_web_sm"""     )
             _a   :			Optional[int]					 =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      SCREAMING_SNAKE_CASE_ (  _UpperCAmelCase     :     Path  )  ->      str:
       _a   :			Optional[Any]					 =tmp_path / """dir1"""
       _a   :			Tuple					 =tmp_path / """dir2"""
       dira.mkdir()
       dira.mkdir()
       _a   :			str					 ="""script.py"""
       _a   :			Dict					 =dedent(
           """
    from datasets.fingerprint import Hasher
    def foo():
        pass
    print(Hasher.hash(foo))
    """  )
       _a   :			Union[str, Any]					 =dira / script_filename
       _a   :			Dict					 =dira / script_filename
       with script_patha.open("""w"""  ) as f:
              f.write(_UpperCAmelCase  )
       with script_patha.open("""w"""  ) as f:
              f.write(_UpperCAmelCase  )
       _a   :			Optional[Any]					 =subprocess.check_output(["""python""", str(_UpperCAmelCase  )]  )
       _a   :			Tuple					 =subprocess.check_output(["""python""", str(_UpperCAmelCase  )]  )
       assert fingerprinta == fingerprinta


def      SCREAMING_SNAKE_CASE_ (  )  ->      Optional[int]:
       _a   :			Any					 ={"""a""": [0, 1, 2]}
       _a   :			str					 =DatasetChild(InMemoryTable.from_pydict(_UpperCAmelCase  )  )
       _a   :			Optional[int]					 =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      SCREAMING_SNAKE_CASE_ (  )  ->      Any:
       _a   :			int					 ={"""a""": [0, 1, 2]}







       class A__	(						datasets.Dataset				):






             @fingerprint_transform(inplace=SCREAMING_SNAKE_CASE     )
             def __UpperCAmelCase	(			self      :List[Any]					,						SCREAMING_SNAKE_CASE      :Dict     )	-> Dict:




                    '''simple docstring'''
                    return DummyDatasetChild(self.data					,						fingerprint=SCREAMING_SNAKE_CASE     )

       _a   :			List[str]					 =DummyDatasetChild(InMemoryTable.from_pydict(_UpperCAmelCase  )  ).func()







       class A__	(						datasets.Dataset				):






             @fingerprint_transform(inplace=SCREAMING_SNAKE_CASE					,						version="""1.0.0"""     )
             def __UpperCAmelCase	(			self      :Tuple					,						SCREAMING_SNAKE_CASE      :List[str]     )	-> List[Any]:




                    '''simple docstring'''
                    return DummyDatasetChild(self.data					,						fingerprint=SCREAMING_SNAKE_CASE     )

       _a   :			Dict					 =DummyDatasetChild(InMemoryTable.from_pydict(_UpperCAmelCase  )  ).func()







       class A__	(						datasets.Dataset				):






             @fingerprint_transform(inplace=SCREAMING_SNAKE_CASE					,						version="""2.0.0"""     )
             def __UpperCAmelCase	(			self      :Optional[int]					,						SCREAMING_SNAKE_CASE      :Tuple     )	-> Optional[Any]:




                    '''simple docstring'''
                    return DummyDatasetChild(self.data					,						fingerprint=SCREAMING_SNAKE_CASE     )

       _a   :			Dict					 =DummyDatasetChild(InMemoryTable.from_pydict(_UpperCAmelCase  )  ).func()

       assert len({fingeprint_no_version, fingeprint_a, fingeprint_a}  ) == 3


def      SCREAMING_SNAKE_CASE_ (  )  ->      str:
       # AttributeError: module 'dill._dill' has no attribute 'stack'
       _a   :			List[Any]					 =Hasher()
       hasher.update(lambda _UpperCAmelCase  : x  )






'''simple docstring'''







import inspect
import os
import unittest

import torch

import accelerate
from accelerate import debug_launcher
from accelerate.test_utils import (
    execute_subprocess_async,
    require_cpu,
    require_multi_gpu,
    require_single_gpu,
    test_sync,
)
from accelerate.utils import patch_environment







class A__	(						unittest.TestCase				):






      def __UpperCAmelCase	(			self      :List[Any]     )	-> List[str]:




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






      @require_cpu
      def __UpperCAmelCase	(			self      :List[str]     )	-> Optional[Any]:




             '''simple docstring'''
             debug_launcher(test_sync.main					,						num_processes=1     )






      @require_cpu
      def __UpperCAmelCase	(			self      :int     )	-> Union[str, Any]:




             '''simple docstring'''
             debug_launcher(test_sync.main     )






      @require_single_gpu
      def __UpperCAmelCase	(			self      :Any     )	-> Optional[int]:




             '''simple docstring'''
             test_sync.main()






      @require_multi_gpu
      def __UpperCAmelCase	(			self      :Optional[Any]     )	-> int:




             '''simple docstring'''
             print(f"Found {torch.cuda.device_count()} devices."     )
             _a   :			int					 =["""torchrun""", f"--nproc_per_node={torch.cuda.device_count()}", self.test_file_path]
             with patch_environment(omp_num_threads=1     ):
                    execute_subprocess_async(SCREAMING_SNAKE_CASE					,						env=os.environ.copy()     )


