




import unittest

from transformers.testing_utils import is_torch_available, require_torch, tooslow

from ...generation.test_utils import torch_device
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
      import torch

      from transformers import (
          CpmAntConfig,
          CpmAntForCausalLM,
          CpmAntModel,
          CpmAntTokenizer,
      )






@require_torch
class 			A			:
     """simple docstring"""

     def __init__(    self  :   Union[str, Any]	,  A__  :   Tuple	,  A__  :   int=2	,  A__  :   Dict=8	,  A__  :   List[Any]=True	,  A__  :   Optional[int]=False	,  A__  :   Any=False	,  A__  :   Tuple=False	,  A__  :   Union[str, Any]=False	,  A__  :   List[Any]=9_9	,  A__  :   str=3_2	,  A__  :   int=3	,  A__  :   List[Any]=4	,  A__  :   List[Any]=3_7	,  A__  :   Tuple=3_2	,  A__  :   Optional[int]=1_2_8	,  A__  :   Dict=8	,  A__  :   Tuple=8	,  A__  :   Union[str, Any]=8	,  A__  :   Union[str, Any]=1.0	,  A__  :   Tuple=True	,  )				->       Optional[Any]:
           lowerCamelCase__        =				parent
           lowerCamelCase__        =				batch_size
           lowerCamelCase__        =				seq_length
           lowerCamelCase__        =				is_training
           lowerCamelCase__        =				use_token_type_ids
           lowerCamelCase__        =				use_input_mask
           lowerCamelCase__        =				use_labels
           lowerCamelCase__        =				use_mc_token_ids
           lowerCamelCase__        =				vocab_size
           lowerCamelCase__        =				hidden_size
           lowerCamelCase__        =				num_hidden_layers
           lowerCamelCase__        =				num_attention_heads
           lowerCamelCase__        =				intermediate_size
           lowerCamelCase__        =				num_buckets
           lowerCamelCase__        =				max_distance
           lowerCamelCase__        =				prompt_length
           lowerCamelCase__        =				prompt_types
           lowerCamelCase__        =				segment_types
           lowerCamelCase__        =				init_std
           lowerCamelCase__        =				return_dict




     def  __snake_case   (    self  :   List[Any]			)				->       List[str]:
           lowerCamelCase__        =				{}
           lowerCamelCase__        =				ids_tensor([self.batch_size, self.seq_length]	,  self.vocab_size			).type(torch.intaa			)
           lowerCamelCase__        =				False

           lowerCamelCase__        =				self.get_config()

           return (config, input_ids)




     def  __snake_case   (    self  :   Dict			)				->       Dict:
           return CpmAntConfig(
               vocab_size=self.vocab_size	,  hidden_size=self.hidden_size	,  num_hidden_layers=self.num_hidden_layers	,  num_attention_heads=self.num_attention_heads	,  dim_ff=self.intermediate_size	,  position_bias_num_buckets=self.num_buckets	,  position_bias_max_distance=self.max_distance	,  prompt_types=self.prompt_types	,  prompt_length=self.prompt_length	,  segment_types=self.segment_types	,  use_cache=_snake_case	,  init_std=self.init_std	,  return_dict=self.return_dict	,  )




     def  __snake_case   (    self  :   List[str]	,  A__  :   int	,  A__  :   List[str]	,  *A__  :   Optional[int]			)				->       Optional[int]:
           lowerCamelCase__        =				CpmAntModel(config=_snake_case			)
           model.to(_snake_case			)
           model.eval()

           lowerCamelCase__        =				model(**_snake_case			).last_hidden_state

           self.parent.assertEqual(hidden_states.shape	,  (self.batch_size, self.seq_length, config.hidden_size)			)




     def  __snake_case   (    self  :   Union[str, Any]	,  A__  :   List[Any]	,  A__  :   int	,  *A__  :   str			)				->       List[str]:
           lowerCamelCase__        =				CpmAntForCausalLM(_snake_case			)
           model.to(_snake_case			)
           lowerCamelCase__        =				input_ids['''input_ids'''].to(_snake_case			)
           model.eval()

           lowerCamelCase__        =				model(**_snake_case			)
           self.parent.assertEqual(
               model_output.logits.shape	,  (self.batch_size, self.seq_length, config.vocab_size + config.prompt_types * config.prompt_length)	,  )




     def  __snake_case   (    self  :   Tuple			)				->       List[str]:
           lowerCamelCase__        =				self.prepare_config_and_inputs()
           return config, inputs_dict






@require_torch
class 			A			(		a_			,						a_			,						unittest.TestCase		):
     """simple docstring"""

     _snake_case:	Union[str, Any]     =(CpmAntModel, CpmAntForCausalLM) if is_torch_available() else ()
     _snake_case:	Union[str, Any]     =(
         {'feature-extraction': CpmAntModel, 'text-generation': CpmAntForCausalLM} if is_torch_available() else {}
     )

     _snake_case:	Optional[int]     =False
     _snake_case:	Any     =False
     _snake_case:	Dict     =False
     _snake_case:	int     =False
     _snake_case:	Optional[Any]     =False




     def  __snake_case   (    self  :   int			)				->       Tuple:
           lowerCamelCase__        =				CpmAntModelTester(self			)
           lowerCamelCase__        =				ConfigTester(self	,  config_class=_snake_case			)




     def  __snake_case   (    self  :   List[str]			)				->       Any:
           self.config_tester.create_and_test_config_common_properties()
           self.config_tester.create_and_test_config_to_json_string()
           self.config_tester.create_and_test_config_to_json_file()
           self.config_tester.create_and_test_config_from_and_save_pretrained()
           self.config_tester.check_config_can_be_init_without_params()
           self.config_tester.check_config_arguments_init()




     def  __snake_case   (    self  :   int			)				->       List[Any]:
           unittest.skip('CPMAnt doesn\'t support input_embeds.'			)(self.test_inputs_embeds			)




     def  __snake_case   (    self  :   List[str]			)				->       Tuple:
           unittest.skip(
               'CPMAnt doesn\'t support retain grad in hidden_states or attentions, because prompt management will peel off the output.hidden_states from graph.\\n                 So is attentions. We strongly recommand you use loss to tune model.'			)(self.test_retain_grad_hidden_states_attentions			)




     def  __snake_case   (    self  :   Tuple			)				->       Union[str, Any]:
           lowerCamelCase__        =				self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_cpmant_model(_snake_case	,  _snake_case			)




     def  __snake_case   (    self  :   Union[str, Any]			)				->       int:
           lowerCamelCase__        =				self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_lm_head_model(_snake_case	,  _snake_case			)






@require_torch
class 			A			(		unittest.TestCase		):
     """simple docstring"""

     @tooslow
     def  __snake_case   (    self  :   Tuple			)				->       int:
           lowerCamelCase__        =				'''今天天气真好！'''
           lowerCamelCase__        =				'''openbmb/cpm-ant-10b'''
           lowerCamelCase__        =				CpmAntModel.from_pretrained(_snake_case			)
           lowerCamelCase__        =				CpmAntTokenizer.from_pretrained(_snake_case			)
           lowerCamelCase__        =				tokenizer(_snake_case	,  return_tensors='pt'			)
           lowerCamelCase__        =				model(**_snake_case			).last_hidden_state

           lowerCamelCase__        =				torch.tensor(
               [[[6.1708, 5.9244, 1.0835], [6.5207, 6.2893, -11.3324], [-1.0107, -0.0576, -5.9577]]]	,  )
           self.assertTrue(torch.allclose(hidden_states[:, :3, :3]	,  _snake_case	,  atol=1E-2			)			)






@require_torch
class 			A			(		unittest.TestCase		):
     """simple docstring"""

     @tooslow
     def  __snake_case   (    self  :   int			)				->       int:
           lowerCamelCase__        =				'''今天天气真好！'''
           lowerCamelCase__        =				'''openbmb/cpm-ant-10b'''
           lowerCamelCase__        =				CpmAntForCausalLM.from_pretrained(_snake_case			)
           lowerCamelCase__        =				CpmAntTokenizer.from_pretrained(_snake_case			)
           lowerCamelCase__        =				tokenizer(_snake_case	,  return_tensors='pt'			)
           lowerCamelCase__        =				model(**_snake_case			).logits

           lowerCamelCase__        =				torch.tensor(
               [[[-6.4267, -6.4083, -6.3958], [-5.8802, -5.9447, -5.7811], [-5.3896, -5.4820, -5.4295]]]	,  )
           self.assertTrue(torch.allclose(hidden_states[:, :3, :3]	,  _snake_case	,  atol=1E-2			)			)




     @tooslow
     def  __snake_case   (    self  :   int			)				->       List[Any]:
           lowerCamelCase__        =				'''openbmb/cpm-ant-10b'''
           lowerCamelCase__        =				CpmAntForCausalLM.from_pretrained(_snake_case			)
           lowerCamelCase__        =				CpmAntTokenizer.from_pretrained(_snake_case			)
           lowerCamelCase__        =				'''今天天气不错，'''
           lowerCamelCase__        =				'''今天天气不错，阳光明媚，我和妈妈一起去超市买东西。\n在超市里，我看到了一个很好玩的玩具，它的名字叫“机器人”。它有一个圆圆的脑袋，两只圆圆的眼睛，还有一个圆圆的'''
           lowerCamelCase__        =				tokenizer(_snake_case	,  return_tensors='pt'			)
           lowerCamelCase__        =				model.generate(**_snake_case			)
           lowerCamelCase__        =				tokenizer.batch_decode(_snake_case			)
           self.assertEqual(_snake_case	,  _snake_case			)




     @tooslow
     def  __snake_case   (    self  :   List[str]			)				->       Tuple:
           lowerCamelCase__        =				'''openbmb/cpm-ant-10b'''
           lowerCamelCase__        =				CpmAntForCausalLM.from_pretrained(_snake_case			)
           lowerCamelCase__        =				CpmAntTokenizer.from_pretrained(_snake_case			)
           lowerCamelCase__        =				['''今天天气不错，''', '''新年快乐，万事如意！''']
           lowerCamelCase__        =				[
               '''今天天气不错，阳光明媚，我和妈妈一起去超市买东西。\n在超市里，我看到了一个很好玩的玩具，它的名字叫“机器人”。它有一个圆圆的脑袋，两只圆圆的眼睛，还有一个圆圆的''',
               '''新年快乐，万事如意！在这辞旧迎新的美好时刻，我谨代表《农村新技术》杂志社全体同仁，向一直以来关心、支持《农村新技术》杂志发展的各级领导、各界朋友和广大读者致以最诚挚的''',
           ]
           lowerCamelCase__        =				tokenizer(_snake_case	,  return_tensors='pt'	,  padding=_snake_case			)
           lowerCamelCase__        =				model.generate(**_snake_case			)
           lowerCamelCase__        =				tokenizer.batch_decode(_snake_case			)
           self.assertEqual(_snake_case	,  _snake_case			)





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			:
     """simple docstring"""

     def __init__(    self  :   Optional[int]	,  A__  :   Optional[Any]			)				->       Dict:
           lowerCamelCase__        =				foo




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






class 			A			(		datasets.Dataset		):
     """simple docstring"""

     @fingerprint_transform(inplace=A__			)
     def  __snake_case   (    self  :   Optional[Any]	,  A__  :   Tuple	,  *A__  :   List[str]	,  **A__  :   List[Any]			)				->       Dict:
           return DatasetChild(self.data	,  fingerprint=A__			)




     @fingerprint_transform(inplace=A__			)
     def  __snake_case   (    self  :   Any	,  A__  :   Optional[int]	,  *A__  :   List[str]	,  **A__  :   Union[str, Any]			)				->       List[Any]:
           return DatasetChild(self.data	,  fingerprint=A__			)






class 			A			:
     """simple docstring"""

     def __init__(    self  :   List[Any]	,  A__  :   Tuple			)				->       List[Any]:
           lowerCamelCase__        =				callable




     def __call__(    self  :   Dict	,  *A__  :   Dict	,  **A__  :   List[str]			)				->       List[str]:
           if self.callable is not None:
                 return self.callable(*A__	,  **A__			)




     def __getstate__(    self  :   Optional[Any]			)				->       Union[str, Any]:
           raise pickle.PicklingError()






class 			A			(		_lowerCAmelCase		):
     """simple docstring"""

     @require_transformers
     @pytest.mark.integration
     def  __snake_case   (    self  :   str			)				->       int:
           from transformers import AutoTokenizer

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

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




     @require_transformers
     @pytest.mark.integration
     def  __snake_case   (    self  :   int			)				->       List[str]:
           from transformers import AutoTokenizer

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




     @require_regex
     def  __snake_case   (    self  :   Dict			)				->       Dict:
           import regex

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






class 			A			(		_lowerCAmelCase		):
     """simple docstring"""

     def  __snake_case   (    self  :   Tuple			)				->       List[Any]:
           def func():
                 return foo

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




     def  __snake_case   (    self  :   Optional[int]			)				->       str:
           def func():
                 pass

           lowerCamelCase__        =				mda(datasets.utils.py_utils.dumps(A__			)			).hexdigest()

           def func():
                 pass

           lowerCamelCase__        =				mda(datasets.utils.py_utils.dumps(A__			)			).hexdigest()
           self.assertEqual(A__	,  A__			)




     def  __snake_case   (    self  :   List[Any]			)				->       Optional[Any]:
           lowerCamelCase__        =				mda(datasets.utils.py_utils.dumps(Foo([0]			)			)			).hexdigest()
           lowerCamelCase__        =				mda(datasets.utils.py_utils.dumps(Foo([1]			)			)			).hexdigest()
           lowerCamelCase__        =				mda(datasets.utils.py_utils.dumps(Foo([0]			)			)			).hexdigest()
           self.assertEqual(A__	,  A__			)
           self.assertNotEqual(A__	,  A__			)




     def  __snake_case   (    self  :   Union[str, Any]			)				->       str:
           lowerCamelCase__        =				mda(datasets.utils.py_utils.dumps(Foo([0]			).__call__			)			).hexdigest()
           lowerCamelCase__        =				mda(datasets.utils.py_utils.dumps(Foo([1]			).__call__			)			).hexdigest()
           lowerCamelCase__        =				mda(datasets.utils.py_utils.dumps(Foo([0]			).__call__			)			).hexdigest()
           self.assertEqual(A__	,  A__			)
           self.assertNotEqual(A__	,  A__			)




     def  __snake_case   (    self  :   Optional[Any]			)				->       Optional[Any]:
           lowerCamelCase__        =				(
               '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(*A__  :   Any			):
                 if hasattr(args[-3]	,  'encode'			):
                       lowerCamelCase__        =				list(A__			)
                       lowerCamelCase__        =				args[-3].encode()  # co_lnotab
                       lowerCamelCase__        =				args[-1_0].encode()  # co_code
                 if hasattr(A__	,  'co_posonlyargcount'			):
                       if len(A__			) == 1_6:
                             return CodeType(*A__			)
                       elif len(A__			) == 1_5:
                             return CodeType(args[0]	,  0	,  *args[1:]			)
                       return CodeType(args[0]	,  0	,  0	,  *args[1:]			)
                 elif hasattr(A__	,  'co_kwonlyargcount'			):
                       if len(A__			) == 1_6:
                             return CodeType(args[0]	,  *args[2:]			)
                       elif len(A__			) == 1_5:
                             return CodeType(*A__			)
                       return CodeType(args[0]	,  0	,  *args[1:]			)
                 if len(A__			) == 1_6:
                       return CodeType(args[0]	,  *args[3:]			)
                 elif len(A__			) == 1_5:
                       return CodeType(args[0]	,  *args[2:]			)
                 return CodeType(*A__			)

           def create_ipython_func(A__  :   Any	,  A__  :   Tuple			):
                 def func():
                       return returned_obj

                 lowerCamelCase__        =				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'			):
                       lowerCamelCase__        =				_create_code_pyaa(
                           *[getattr(A__	,  A__			) if k != 'co_filename' else co_filename for k in code_args_pyaa]			)
                 else:
                       lowerCamelCase__        =				code.replace(co_filename=A__			)
                 return FunctionType(A__	,  func.__globals__	,  func.__name__	,  func.__defaults__	,  func.__closure__			)

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

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




     def  __snake_case   (    self  :   Optional[Any]			)				->       List[Any]:
           lowerCamelCase__  ,		lowerCamelCase__        =				[0], [1]

           def func():
                 return foo, bar

           lowerCamelCase__        =				'__main__'

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

           def globalvars_mocka_side_effect(A__  :   Any	,  *A__  :   Optional[int]	,  **A__  :   Tuple			):
                 return {"bar": bar, "foo": foo}

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






class 			A			(		_lowerCAmelCase		):
     """simple docstring"""

     def  __snake_case   (    self  :   str			)				->       List[str]:
           lowerCamelCase__        =				Hasher.hash('hello'			)
           lowerCamelCase__        =				Hasher.hash('hello'			)
           lowerCamelCase__        =				Hasher.hash('there'			)
           self.assertEqual(A__	,  A__			)
           self.assertNotEqual(A__	,  A__			)




     def  __snake_case   (    self  :   List[str]			)				->       Optional[Any]:
           lowerCamelCase__        =				Hasher.hash(Foo('hello'			)			)
           lowerCamelCase__        =				Hasher.hash(Foo('hello'			)			)
           lowerCamelCase__        =				Hasher.hash(Foo('there'			)			)
           self.assertEqual(A__	,  A__			)
           self.assertNotEqual(A__	,  A__			)




     def  __snake_case   (    self  :   Tuple			)				->       str:
           lowerCamelCase__        =				Hasher()
           for x in ["hello", Foo('hello'			)]:
                 hasher.update(A__			)
           lowerCamelCase__        =				hasher.hexdigest()
           lowerCamelCase__        =				Hasher()
           for x in ["hello", Foo('hello'			)]:
                 hasher.update(A__			)
           lowerCamelCase__        =				hasher.hexdigest()
           lowerCamelCase__        =				Hasher()
           for x in ["there", Foo('there'			)]:
                 hasher.update(A__			)
           lowerCamelCase__        =				hasher.hexdigest()
           self.assertEqual(A__	,  A__			)
           self.assertNotEqual(A__	,  A__			)




     def  __snake_case   (    self  :   Any			)				->       Tuple:
           with self.assertRaises(pickle.PicklingError			):
                 Hasher.hash(UnpicklableCallable(Foo('hello'			)			)			)




     def  __snake_case   (    self  :   Optional[int]			)				->       Optional[Any]:
           lowerCamelCase__        =				'abc'
           lowerCamelCase__        =				[string, string]  # two strings have the same ids
           lowerCamelCase__        =				[string, string]
           lowerCamelCase__        =				json.loads(F"""[\"{string}\", \"{string}\"]"""			)  # two strings have different ids
           self.assertIs(obja[0]	,  A__			)
           self.assertIs(obja[0]	,  obja[1]			)
           self.assertIs(obja[0]	,  A__			)
           self.assertIs(obja[0]	,  obja[1]			)
           self.assertIsNot(obja[0]	,  A__			)
           self.assertIsNot(obja[0]	,  obja[1]			)
           lowerCamelCase__        =				Hasher.hash(A__			)
           lowerCamelCase__        =				Hasher.hash(A__			)
           lowerCamelCase__        =				Hasher.hash(A__			)
           self.assertEqual(A__	,  A__			)
           self.assertEqual(A__	,  A__			)




     @require_tiktoken
     def  __snake_case   (    self  :   Union[str, Any]			)				->       str:
           import tiktoken

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




     @require_torch
     def  __snake_case   (    self  :   Optional[Any]			)				->       List[Any]:
           import torch

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




     @require_spacy
     @require_spacy_model('en_core_web_sm'			)
     @require_spacy_model('fr_core_news_sm'			)
     @pytest.mark.integration
     def  __snake_case   (    self  :   Tuple			)				->       List[str]:
           import spacy

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

@pytest.mark.integration
def 			lowerCAmelCase_			(  lowerCamelCase:       Path						)					->			Optional[int]:


      '''simple docstring'''




      lowerCamelCase__        =				tmp_path / 'dir1'
      lowerCamelCase__        =				tmp_path / 'dir2'
      dira.mkdir()
      dira.mkdir()
      lowerCamelCase__        =				'script.py'
      lowerCamelCase__        =				dedent(
          '\n    from datasets.fingerprint import Hasher\n    def foo():\n        pass\n    print(Hasher.hash(foo))\n    '						)
      lowerCamelCase__        =				dira / script_filename
      lowerCamelCase__        =				dira / script_filename
      with script_patha.open('w'						) as f:
            f.write(lowerCamelCase						)
      with script_patha.open('w'						) as f:
            f.write(lowerCamelCase						)
      lowerCamelCase__        =				subprocess.check_output(['python', str(lowerCamelCase						)]						)
      lowerCamelCase__        =				subprocess.check_output(['python', str(lowerCamelCase						)]						)
      assert fingerprinta == fingerprinta

def 			lowerCAmelCase_			(  )					->			int:


      '''simple docstring'''




      lowerCamelCase__        =				{'a': [0, 1, 2]}
      lowerCamelCase__        =				DatasetChild(InMemoryTable.from_pydict(lowerCamelCase						)						)
      lowerCamelCase__        =				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 			lowerCAmelCase_			(  )					->			Union[str, Any]:


      '''simple docstring'''




      lowerCamelCase__        =				{'a': [0, 1, 2]}






      class 			A			(		datasets.Dataset		):
           """simple docstring"""

           @fingerprint_transform(inplace=A__			)
           def  __snake_case   (    self  :   Any	,  A__  :   Union[str, Any]			)				->       List[Any]:
                 return DummyDatasetChild(self.data	,  fingerprint=A__			)
      lowerCamelCase__        =				DummyDatasetChild(InMemoryTable.from_pydict(lowerCamelCase						)						).func()






      class 			A			(		datasets.Dataset		):
           """simple docstring"""

           @fingerprint_transform(inplace=A__	,  version='1.0.0'			)
           def  __snake_case   (    self  :   str	,  A__  :   List[Any]			)				->       List[str]:
                 return DummyDatasetChild(self.data	,  fingerprint=A__			)
      lowerCamelCase__        =				DummyDatasetChild(InMemoryTable.from_pydict(lowerCamelCase						)						).func()






      class 			A			(		datasets.Dataset		):
           """simple docstring"""

           @fingerprint_transform(inplace=A__	,  version='2.0.0'			)
           def  __snake_case   (    self  :   List[str]	,  A__  :   int			)				->       int:
                 return DummyDatasetChild(self.data	,  fingerprint=A__			)
      lowerCamelCase__        =				DummyDatasetChild(InMemoryTable.from_pydict(lowerCamelCase						)						).func()

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


def 			lowerCAmelCase_			(  )					->			int:


      '''simple docstring'''




      lowerCamelCase__        =				Hasher()
      hasher.update(lambda lowerCamelCase						: x						)