




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






   def __init__(						self :							Optional[int]    ,       UpperCamelCase_ :							Optional[Any]  )->      Union[str, Any]:
     _lowercase:			Union[str, Any]      =     foo






   def __call__(						self :							Tuple  )->      List[str]:
     return self.foo

class   UpperCAmelCase    (      datasets.Dataset ):






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






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

class   UpperCAmelCase    :






   def __init__(						self :							Tuple    ,       UpperCamelCase_ :							List[Any]  )->      Union[str, Any]:
     _lowercase:			Tuple      =     callable






   def __call__(						self :							int    ,       *UpperCamelCase_ :							Tuple    ,       **UpperCamelCase_ :							List[Any]  )->      Union[str, Any]:
     if self.callable is not None:
       return self.callable(*UpperCamelCase_    ,       **UpperCamelCase_  )






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

class   UpperCAmelCase    (      a_ ):






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

     def encode(UpperCamelCase_ :							Optional[Any]  ):
       return tokenizer(UpperCamelCase_  )

     # TODO: add hash consistency tests across sessions
     _lowercase:			int      =     AutoTokenizer.from_pretrained('bert-base-uncased'  )
     _lowercase:			Tuple      =     mda(datasets.utils.py_utils.dumps(UpperCamelCase_  )  ).hexdigest()
     _lowercase:			Optional[Any]      =     mda(datasets.utils.py_utils.dumps(lambda UpperCamelCase_  : tokenizer(UpperCamelCase_  )  )  ).hexdigest()
     _lowercase:			Optional[int]      =     mda(datasets.utils.py_utils.dumps(UpperCamelCase_  )  ).hexdigest()
     _lowercase:			List[Any]      =     AutoTokenizer.from_pretrained('bert-base-cased'  )
     _lowercase:			Optional[Any]      =     mda(datasets.utils.py_utils.dumps(UpperCamelCase_  )  ).hexdigest()
     _lowercase:			Optional[Any]      =     mda(datasets.utils.py_utils.dumps(lambda UpperCamelCase_  : tokenizer(UpperCamelCase_  )  )  ).hexdigest()
     _lowercase:			Optional[int]      =     mda(datasets.utils.py_utils.dumps(UpperCamelCase_  )  ).hexdigest()
     _lowercase:			int      =     AutoTokenizer.from_pretrained('bert-base-uncased'  )
     _lowercase:			Dict      =     mda(datasets.utils.py_utils.dumps(UpperCamelCase_  )  ).hexdigest()
     _lowercase:			Union[str, Any]      =     mda(datasets.utils.py_utils.dumps(lambda UpperCamelCase_  : tokenizer(UpperCamelCase_  )  )  ).hexdigest()
     _lowercase:			str      =     mda(datasets.utils.py_utils.dumps(UpperCamelCase_  )  ).hexdigest()
     self.assertEqual(UpperCamelCase_    ,       UpperCamelCase_  )
     self.assertNotEqual(UpperCamelCase_    ,       UpperCamelCase_  )
     self.assertEqual(UpperCamelCase_    ,       UpperCamelCase_  )
     self.assertNotEqual(UpperCamelCase_    ,       UpperCamelCase_  )
     self.assertEqual(UpperCamelCase_    ,       UpperCamelCase_  )
     self.assertNotEqual(UpperCamelCase_    ,       UpperCamelCase_  )






   @require_transformers
   @pytest.mark.integration
   def 			_a    (						self :							Optional[Any]  )->      str:
     from transformers import AutoTokenizer

     _lowercase:			Union[str, Any]      =     AutoTokenizer.from_pretrained('gpt2'  )
     _lowercase:			Tuple      =     mda(datasets.utils.py_utils.dumps(UpperCamelCase_  )  ).hexdigest()
     tokenizer('Hello world !'  )  # call once to change the tokenizer's cache
     _lowercase:			Union[str, Any]      =     mda(datasets.utils.py_utils.dumps(UpperCamelCase_  )  ).hexdigest()
     self.assertEqual(UpperCamelCase_    ,       UpperCamelCase_  )






   @require_regex
   def 			_a    (						self :							List[str]  )->      Tuple:
     import regex

     _lowercase:			Optional[int]      =     regex.Regex('foo'  )
     _lowercase:			Optional[int]      =     mda(datasets.utils.py_utils.dumps(UpperCamelCase_  )  ).hexdigest()
     _lowercase:			List[Any]      =     regex.Regex('bar'  )
     _lowercase:			Optional[int]      =     mda(datasets.utils.py_utils.dumps(UpperCamelCase_  )  ).hexdigest()
     _lowercase:			Optional[int]      =     regex.Regex('foo'  )
     _lowercase:			int      =     mda(datasets.utils.py_utils.dumps(UpperCamelCase_  )  ).hexdigest()
     self.assertEqual(UpperCamelCase_    ,       UpperCamelCase_  )
     self.assertNotEqual(UpperCamelCase_    ,       UpperCamelCase_  )

class   UpperCAmelCase    (      a_ ):






   def 			_a    (						self :							Tuple  )->      Tuple:
     def func():
       return foo

     _lowercase:			List[str]      =     [0]
     _lowercase:			Dict      =     mda(datasets.utils.py_utils.dumps(UpperCamelCase_  )  ).hexdigest()
     _lowercase:			Dict      =     [1]
     _lowercase:			List[str]      =     mda(datasets.utils.py_utils.dumps(UpperCamelCase_  )  ).hexdigest()
     _lowercase:			List[Any]      =     [0]
     _lowercase:			Optional[int]      =     mda(datasets.utils.py_utils.dumps(UpperCamelCase_  )  ).hexdigest()
     self.assertEqual(UpperCamelCase_    ,       UpperCamelCase_  )
     self.assertNotEqual(UpperCamelCase_    ,       UpperCamelCase_  )






   def 			_a    (						self :							int  )->      List[str]:
     def func():
       pass

     _lowercase:			List[str]      =     mda(datasets.utils.py_utils.dumps(UpperCamelCase_  )  ).hexdigest()

     def func():
       pass

     _lowercase:			Any      =     mda(datasets.utils.py_utils.dumps(UpperCamelCase_  )  ).hexdigest()
     self.assertEqual(UpperCamelCase_    ,       UpperCamelCase_  )






   def 			_a    (						self :							List[Any]  )->      List[str]:
     _lowercase:			List[Any]      =     mda(datasets.utils.py_utils.dumps(Foo([0]  )  )  ).hexdigest()
     _lowercase:			Any      =     mda(datasets.utils.py_utils.dumps(Foo([1]  )  )  ).hexdigest()
     _lowercase:			str      =     mda(datasets.utils.py_utils.dumps(Foo([0]  )  )  ).hexdigest()
     self.assertEqual(UpperCamelCase_    ,       UpperCamelCase_  )
     self.assertNotEqual(UpperCamelCase_    ,       UpperCamelCase_  )






   def 			_a    (						self :							str  )->      Dict:
     _lowercase:			str      =     mda(datasets.utils.py_utils.dumps(Foo([0]  ).__call__  )  ).hexdigest()
     _lowercase:			List[Any]      =     mda(datasets.utils.py_utils.dumps(Foo([1]  ).__call__  )  ).hexdigest()
     _lowercase:			Optional[Any]      =     mda(datasets.utils.py_utils.dumps(Foo([0]  ).__call__  )  ).hexdigest()
     self.assertEqual(UpperCamelCase_    ,       UpperCamelCase_  )
     self.assertNotEqual(UpperCamelCase_    ,       UpperCamelCase_  )






   def 			_a    (						self :							List[Any]  )->      Union[str, Any]:
     _lowercase:			int      =     (
         '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(*UpperCamelCase_ :							List[str]  ):
       if hasattr(args[-3]    ,       'encode'  ):
         _lowercase:			Optional[int]      =     list(UpperCamelCase_  )
         _lowercase:			Optional[int]      =     args[-3].encode()  # co_lnotab
         _lowercase:			int      =     args[-10].encode()  # co_code
       if hasattr(UpperCamelCase_    ,       'co_posonlyargcount'  ):
         if len(UpperCamelCase_  ) == 16:
           return CodeType(*UpperCamelCase_  )
         elif len(UpperCamelCase_  ) == 15:
           return CodeType(args[0]    ,       0    ,       *args[1:]  )
         return CodeType(args[0]    ,       0    ,       0    ,       *args[1:]  )
       elif hasattr(UpperCamelCase_    ,       'co_kwonlyargcount'  ):
         if len(UpperCamelCase_  ) == 16:
           return CodeType(args[0]    ,       *args[2:]  )
         elif len(UpperCamelCase_  ) == 15:
           return CodeType(*UpperCamelCase_  )
         return CodeType(args[0]    ,       0    ,       *args[1:]  )
       if len(UpperCamelCase_  ) == 16:
         return CodeType(args[0]    ,       *args[3:]  )
       elif len(UpperCamelCase_  ) == 15:
         return CodeType(args[0]    ,       *args[2:]  )
       return CodeType(*UpperCamelCase_  )

     def create_ipython_func(UpperCamelCase_ :							int    ,       UpperCamelCase_ :							List[Any]  ):
       def func():
         return returned_obj

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

     _lowercase:			List[Any]      =     '<ipython-input-2-e0383a102aae>', [0]
     _lowercase:			Dict      =     mda(datasets.utils.py_utils.dumps(create_ipython_func(UpperCamelCase_    ,       UpperCamelCase_  )  )  ).hexdigest()
     _lowercase:			Any      =     '<ipython-input-2-e0383a102aae>', [1]
     _lowercase:			Tuple      =     mda(datasets.utils.py_utils.dumps(create_ipython_func(UpperCamelCase_    ,       UpperCamelCase_  )  )  ).hexdigest()
     _lowercase:			str      =     '<ipython-input-5-713f6613acf3>', [0]
     _lowercase:			str      =     mda(datasets.utils.py_utils.dumps(create_ipython_func(UpperCamelCase_    ,       UpperCamelCase_  )  )  ).hexdigest()
     self.assertEqual(UpperCamelCase_    ,       UpperCamelCase_  )
     self.assertNotEqual(UpperCamelCase_    ,       UpperCamelCase_  )

     _lowercase:			Union[str, Any]      =     os.path.join(gettempdir()    ,       'ipykernel_12345'    ,       '321456789.py'  ), [0]
     _lowercase:			List[Any]      =     mda(datasets.utils.py_utils.dumps(create_ipython_func(UpperCamelCase_    ,       UpperCamelCase_  )  )  ).hexdigest()
     _lowercase:			str      =     os.path.join(gettempdir()    ,       'ipykernel_12345'    ,       '321456789.py'  ), [1]
     _lowercase:			List[Any]      =     mda(datasets.utils.py_utils.dumps(create_ipython_func(UpperCamelCase_    ,       UpperCamelCase_  )  )  ).hexdigest()
     _lowercase:			Optional[Any]      =     os.path.join(gettempdir()    ,       'ipykernel_12345'    ,       '654123987.py'  ), [0]
     _lowercase:			int      =     mda(datasets.utils.py_utils.dumps(create_ipython_func(UpperCamelCase_    ,       UpperCamelCase_  )  )  ).hexdigest()
     self.assertEqual(UpperCamelCase_    ,       UpperCamelCase_  )
     self.assertNotEqual(UpperCamelCase_    ,       UpperCamelCase_  )






   def 			_a    (						self :							str  )->      List[Any]:
     _lowercase:			str      =     [0], [1]

     def func():
       return foo, bar

     _lowercase:			int      =     '__main__'

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

     def globalvars_mocka_side_effect(UpperCamelCase_ :							int    ,       *UpperCamelCase_ :							Tuple    ,       **UpperCamelCase_ :							Any  ):
       return {"bar": bar, "foo": foo}

     with patch('dill.detect.globalvars'    ,       side_effect=UpperCamelCase_  ) as globalvars_mocka:
       _lowercase:			Any      =     mda(datasets.utils.py_utils.dumps(UpperCamelCase_  )  ).hexdigest()
       self.assertGreater(globalvars_mocka.call_count    ,       0  )
     with patch('dill.detect.globalvars'    ,       side_effect=UpperCamelCase_  ) as globalvars_mocka:
       _lowercase:			Optional[Any]      =     mda(datasets.utils.py_utils.dumps(UpperCamelCase_  )  ).hexdigest()
       self.assertGreater(globalvars_mocka.call_count    ,       0  )
     self.assertEqual(UpperCamelCase_    ,       UpperCamelCase_  )

class   UpperCAmelCase    (      a_ ):






   def 			_a    (						self :							List[Any]  )->      str:
     _lowercase:			List[Any]      =     Hasher.hash('hello'  )
     _lowercase:			Optional[Any]      =     Hasher.hash('hello'  )
     _lowercase:			Tuple      =     Hasher.hash('there'  )
     self.assertEqual(UpperCamelCase_    ,       UpperCamelCase_  )
     self.assertNotEqual(UpperCamelCase_    ,       UpperCamelCase_  )






   def 			_a    (						self :							Dict  )->      Dict:
     _lowercase:			Tuple      =     Hasher.hash(Foo('hello'  )  )
     _lowercase:			str      =     Hasher.hash(Foo('hello'  )  )
     _lowercase:			int      =     Hasher.hash(Foo('there'  )  )
     self.assertEqual(UpperCamelCase_    ,       UpperCamelCase_  )
     self.assertNotEqual(UpperCamelCase_    ,       UpperCamelCase_  )






   def 			_a    (						self :							List[Any]  )->      List[Any]:
     _lowercase:			Optional[Any]      =     Hasher()
     for x in ["hello", Foo('hello'  )]:
       hasher.update(UpperCamelCase_  )
     _lowercase:			Dict      =     hasher.hexdigest()
     _lowercase:			Union[str, Any]      =     Hasher()
     for x in ["hello", Foo('hello'  )]:
       hasher.update(UpperCamelCase_  )
     _lowercase:			int      =     hasher.hexdigest()
     _lowercase:			Tuple      =     Hasher()
     for x in ["there", Foo('there'  )]:
       hasher.update(UpperCamelCase_  )
     _lowercase:			Union[str, Any]      =     hasher.hexdigest()
     self.assertEqual(UpperCamelCase_    ,       UpperCamelCase_  )
     self.assertNotEqual(UpperCamelCase_    ,       UpperCamelCase_  )






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






   def 			_a    (						self :							Any  )->      Dict:
     _lowercase:			Optional[Any]      =     'abc'
     _lowercase:			List[Any]      =     [string, string]  # two strings have the same ids
     _lowercase:			List[str]      =     [string, string]
     _lowercase:			Tuple      =     json.loads(f'[\"{string}\", \"{string}\"]'  )  # two strings have different ids
     self.assertIs(obja[0]    ,       UpperCamelCase_  )
     self.assertIs(obja[0]    ,       obja[1]  )
     self.assertIs(obja[0]    ,       UpperCamelCase_  )
     self.assertIs(obja[0]    ,       obja[1]  )
     self.assertIsNot(obja[0]    ,       UpperCamelCase_  )
     self.assertIsNot(obja[0]    ,       obja[1]  )
     _lowercase:			Optional[int]      =     Hasher.hash(UpperCamelCase_  )
     _lowercase:			str      =     Hasher.hash(UpperCamelCase_  )
     _lowercase:			int      =     Hasher.hash(UpperCamelCase_  )
     self.assertEqual(UpperCamelCase_    ,       UpperCamelCase_  )
     self.assertEqual(UpperCamelCase_    ,       UpperCamelCase_  )






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

     _lowercase:			Optional[Any]      =     tiktoken.get_encoding('gpt2'  )
     _lowercase:			Optional[int]      =     mda(datasets.utils.py_utils.dumps(UpperCamelCase_  )  ).hexdigest()
     _lowercase:			Optional[Any]      =     tiktoken.get_encoding('r50k_base'  )
     _lowercase:			Dict      =     mda(datasets.utils.py_utils.dumps(UpperCamelCase_  )  ).hexdigest()
     _lowercase:			str      =     tiktoken.get_encoding('gpt2'  )
     _lowercase:			List[Any]      =     mda(datasets.utils.py_utils.dumps(UpperCamelCase_  )  ).hexdigest()
     self.assertEqual(UpperCamelCase_    ,       UpperCamelCase_  )
     self.assertNotEqual(UpperCamelCase_    ,       UpperCamelCase_  )






   @require_torch
   def 			_a    (						self :							Optional[Any]  )->      Tuple:
     import torch

     _lowercase:			str      =     torch.tensor([1.0]  )
     _lowercase:			Optional[int]      =     mda(datasets.utils.py_utils.dumps(UpperCamelCase_  )  ).hexdigest()
     _lowercase:			Optional[Any]      =     torch.tensor([2.0]  )
     _lowercase:			Union[str, Any]      =     mda(datasets.utils.py_utils.dumps(UpperCamelCase_  )  ).hexdigest()
     _lowercase:			Union[str, Any]      =     torch.tensor([1.0]  )
     _lowercase:			Any      =     mda(datasets.utils.py_utils.dumps(UpperCamelCase_  )  ).hexdigest()
     self.assertEqual(UpperCamelCase_    ,       UpperCamelCase_  )
     self.assertNotEqual(UpperCamelCase_    ,       UpperCamelCase_  )






   @require_spacy
   @require_spacy_model('en_core_web_sm'  )
   @require_spacy_model('fr_core_news_sm'  )
   @pytest.mark.integration
   def 			_a    (						self :							Optional[int]  )->      Tuple:
     import spacy

     _lowercase:			List[Any]      =     spacy.load('en_core_web_sm'  )
     _lowercase:			Optional[int]      =     mda(datasets.utils.py_utils.dumps(UpperCamelCase_  )  ).hexdigest()
     _lowercase:			List[Any]      =     spacy.load('fr_core_news_sm'  )
     _lowercase:			Any      =     mda(datasets.utils.py_utils.dumps(UpperCamelCase_  )  ).hexdigest()
     _lowercase:			List[Any]      =     spacy.load('en_core_web_sm'  )
     _lowercase:			Any      =     mda(datasets.utils.py_utils.dumps(UpperCamelCase_  )  ).hexdigest()
     self.assertEqual(UpperCamelCase_    ,       UpperCamelCase_  )
     self.assertNotEqual(UpperCamelCase_    ,       UpperCamelCase_  )


@pytest.mark.integration
def 		_lowerCamelCase					(       UpperCamelCase				)      ->		Tuple:





  """simple docstring"""





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


def 		_lowerCamelCase					(       )      ->		List[Any]:





  """simple docstring"""





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





  """simple docstring"""





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

  class   UpperCAmelCase    (      datasets.Dataset ):






     @fingerprint_transform(inplace=UpperCamelCase_  )
     def 			_a    (						self :							Any    ,       UpperCamelCase_ :							Dict  )->      int:
       return DummyDatasetChild(self.data    ,       fingerprint=UpperCamelCase_  )
  _lowercase:			str      =     DummyDatasetChild(InMemoryTable.from_pydict(lowercase_				)				).func()

  class   UpperCAmelCase    (      datasets.Dataset ):






     @fingerprint_transform(inplace=UpperCamelCase_    ,       version='1.0.0'  )
     def 			_a    (						self :							int    ,       UpperCamelCase_ :							Optional[Any]  )->      Tuple:
       return DummyDatasetChild(self.data    ,       fingerprint=UpperCamelCase_  )
  _lowercase:			Optional[int]      =     DummyDatasetChild(InMemoryTable.from_pydict(lowercase_				)				).func()

  class   UpperCAmelCase    (      datasets.Dataset ):






     @fingerprint_transform(inplace=UpperCamelCase_    ,       version='2.0.0'  )
     def 			_a    (						self :							Optional[int]    ,       UpperCamelCase_ :							Optional[Any]  )->      Tuple:
       return DummyDatasetChild(self.data    ,       fingerprint=UpperCamelCase_  )
  _lowercase:			Tuple      =     DummyDatasetChild(InMemoryTable.from_pydict(lowercase_				)				).func()

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





def 		_lowerCamelCase					(       )      ->		Any:





  """simple docstring"""





  _lowercase:			Union[str, Any]      =     Hasher()
  hasher.update(lambda UpperCamelCase				: x				)

from typing import TYPE_CHECKING

from ..utils import OptionalDependencyNotAvailable, _LazyModule, is_flax_available, is_tf_available, is_torch_available


UpperCAmelCase      		=					{
    '''configuration_utils''': ['''GenerationConfig'''],
    '''streamers''': ['''TextIteratorStreamer''', '''TextStreamer'''],
}

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 UpperCAmelCase      		=					[
     '''Constraint''',
     '''ConstraintListState''',
     '''DisjunctiveConstraint''',
     '''PhrasalConstraint''',
 ]
 UpperCAmelCase      		=					[
     '''BeamHypotheses''',
     '''BeamScorer''',
     '''BeamSearchScorer''',
     '''ConstrainedBeamSearchScorer''',
 ]
 UpperCAmelCase      		=					[
     '''EpsilonLogitsWarper''',
     '''EtaLogitsWarper''',
     '''ForcedBOSTokenLogitsProcessor''',
     '''ForcedEOSTokenLogitsProcessor''',
     '''HammingDiversityLogitsProcessor''',
     '''InfNanRemoveLogitsProcessor''',
     '''LogitsProcessor''',
     '''LogitsProcessorList''',
     '''LogitsWarper''',
     '''MinLengthLogitsProcessor''',
     '''MinNewTokensLengthLogitsProcessor''',
     '''NoBadWordsLogitsProcessor''',
     '''NoRepeatNGramLogitsProcessor''',
     '''PrefixConstrainedLogitsProcessor''',
     '''RepetitionPenaltyLogitsProcessor''',
     '''SequenceBiasLogitsProcessor''',
     '''EncoderRepetitionPenaltyLogitsProcessor''',
     '''TemperatureLogitsWarper''',
     '''TopKLogitsWarper''',
     '''TopPLogitsWarper''',
     '''TypicalLogitsWarper''',
     '''EncoderNoRepeatNGramLogitsProcessor''',
     '''ExponentialDecayLengthPenalty''',
     '''LogitNormalization''',
 ]
 UpperCAmelCase      		=					[
     '''MaxNewTokensCriteria''',
     '''MaxLengthCriteria''',
     '''MaxTimeCriteria''',
     '''StoppingCriteria''',
     '''StoppingCriteriaList''',
     '''validate_stopping_criteria''',
 ]
 UpperCAmelCase      		=					[
     '''GenerationMixin''',
     '''top_k_top_p_filtering''',
     '''GreedySearchEncoderDecoderOutput''',
     '''GreedySearchDecoderOnlyOutput''',
     '''SampleEncoderDecoderOutput''',
     '''SampleDecoderOnlyOutput''',
     '''BeamSearchEncoderDecoderOutput''',
     '''BeamSearchDecoderOnlyOutput''',
     '''BeamSampleEncoderDecoderOutput''',
     '''BeamSampleDecoderOnlyOutput''',
     '''ContrastiveSearchEncoderDecoderOutput''',
     '''ContrastiveSearchDecoderOnlyOutput''',
 ]

try:
 if not is_tf_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 UpperCAmelCase      		=					[
     '''TFForcedBOSTokenLogitsProcessor''',
     '''TFForcedEOSTokenLogitsProcessor''',
     '''TFLogitsProcessor''',
     '''TFLogitsProcessorList''',
     '''TFLogitsWarper''',
     '''TFMinLengthLogitsProcessor''',
     '''TFNoBadWordsLogitsProcessor''',
     '''TFNoRepeatNGramLogitsProcessor''',
     '''TFRepetitionPenaltyLogitsProcessor''',
     '''TFTemperatureLogitsWarper''',
     '''TFTopKLogitsWarper''',
     '''TFTopPLogitsWarper''',
     '''TFForceTokensLogitsProcessor''',
     '''TFSuppressTokensAtBeginLogitsProcessor''',
     '''TFSuppressTokensLogitsProcessor''',
 ]
 UpperCAmelCase      		=					[
     '''TFGenerationMixin''',
     '''tf_top_k_top_p_filtering''',
     '''TFGreedySearchDecoderOnlyOutput''',
     '''TFGreedySearchEncoderDecoderOutput''',
     '''TFSampleEncoderDecoderOutput''',
     '''TFSampleDecoderOnlyOutput''',
     '''TFBeamSearchEncoderDecoderOutput''',
     '''TFBeamSearchDecoderOnlyOutput''',
     '''TFBeamSampleEncoderDecoderOutput''',
     '''TFBeamSampleDecoderOnlyOutput''',
     '''TFContrastiveSearchEncoderDecoderOutput''',
     '''TFContrastiveSearchDecoderOnlyOutput''',
 ]

try:
 if not is_flax_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 UpperCAmelCase      		=					[
     '''FlaxForcedBOSTokenLogitsProcessor''',
     '''FlaxForcedEOSTokenLogitsProcessor''',
     '''FlaxLogitsProcessor''',
     '''FlaxLogitsProcessorList''',
     '''FlaxLogitsWarper''',
     '''FlaxMinLengthLogitsProcessor''',
     '''FlaxTemperatureLogitsWarper''',
     '''FlaxTopKLogitsWarper''',
     '''FlaxTopPLogitsWarper''',
 ]
 UpperCAmelCase      		=					[
     '''FlaxGenerationMixin''',
     '''FlaxGreedySearchOutput''',
     '''FlaxSampleOutput''',
     '''FlaxBeamSearchOutput''',
 ]

if TYPE_CHECKING:
 from .configuration_utils import GenerationConfig
 from .streamers import TextIteratorStreamer, TextStreamer

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .beam_constraints import Constraint, ConstraintListState, DisjunctiveConstraint, PhrasalConstraint
  from .beam_search import BeamHypotheses, BeamScorer, BeamSearchScorer, ConstrainedBeamSearchScorer
  from .logits_process import (
      EncoderNoRepeatNGramLogitsProcessor,
      EncoderRepetitionPenaltyLogitsProcessor,
      EpsilonLogitsWarper,
      EtaLogitsWarper,
      ExponentialDecayLengthPenalty,
      ForcedBOSTokenLogitsProcessor,
      ForcedEOSTokenLogitsProcessor,
      HammingDiversityLogitsProcessor,
      InfNanRemoveLogitsProcessor,
      LogitNormalization,
      LogitsProcessor,
      LogitsProcessorList,
      LogitsWarper,
      MinLengthLogitsProcessor,
      MinNewTokensLengthLogitsProcessor,
      NoBadWordsLogitsProcessor,
      NoRepeatNGramLogitsProcessor,
      PrefixConstrainedLogitsProcessor,
      RepetitionPenaltyLogitsProcessor,
      SequenceBiasLogitsProcessor,
      TemperatureLogitsWarper,
      TopKLogitsWarper,
      TopPLogitsWarper,
      TypicalLogitsWarper,
  )
  from .stopping_criteria import (
      MaxLengthCriteria,
      MaxNewTokensCriteria,
      MaxTimeCriteria,
      StoppingCriteria,
      StoppingCriteriaList,
      validate_stopping_criteria,
  )
  from .utils import (
      BeamSampleDecoderOnlyOutput,
      BeamSampleEncoderDecoderOutput,
      BeamSearchDecoderOnlyOutput,
      BeamSearchEncoderDecoderOutput,
      ContrastiveSearchDecoderOnlyOutput,
      ContrastiveSearchEncoderDecoderOutput,
      GenerationMixin,
      GreedySearchDecoderOnlyOutput,
      GreedySearchEncoderDecoderOutput,
      SampleDecoderOnlyOutput,
      SampleEncoderDecoderOutput,
      top_k_top_p_filtering,
  )

 try:
  if not is_tf_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .tf_logits_process import (
      TFForcedBOSTokenLogitsProcessor,
      TFForcedEOSTokenLogitsProcessor,
      TFForceTokensLogitsProcessor,
      TFLogitsProcessor,
      TFLogitsProcessorList,
      TFLogitsWarper,
      TFMinLengthLogitsProcessor,
      TFNoBadWordsLogitsProcessor,
      TFNoRepeatNGramLogitsProcessor,
      TFRepetitionPenaltyLogitsProcessor,
      TFSuppressTokensAtBeginLogitsProcessor,
      TFSuppressTokensLogitsProcessor,
      TFTemperatureLogitsWarper,
      TFTopKLogitsWarper,
      TFTopPLogitsWarper,
  )
  from .tf_utils import (
      TFBeamSampleDecoderOnlyOutput,
      TFBeamSampleEncoderDecoderOutput,
      TFBeamSearchDecoderOnlyOutput,
      TFBeamSearchEncoderDecoderOutput,
      TFContrastiveSearchDecoderOnlyOutput,
      TFContrastiveSearchEncoderDecoderOutput,
      TFGenerationMixin,
      TFGreedySearchDecoderOnlyOutput,
      TFGreedySearchEncoderDecoderOutput,
      TFSampleDecoderOnlyOutput,
      TFSampleEncoderDecoderOutput,
      tf_top_k_top_p_filtering,
  )

 try:
  if not is_flax_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .flax_logits_process import (
      FlaxForcedBOSTokenLogitsProcessor,
      FlaxForcedEOSTokenLogitsProcessor,
      FlaxLogitsProcessor,
      FlaxLogitsProcessorList,
      FlaxLogitsWarper,
      FlaxMinLengthLogitsProcessor,
      FlaxTemperatureLogitsWarper,
      FlaxTopKLogitsWarper,
      FlaxTopPLogitsWarper,
  )
  from .flax_utils import FlaxBeamSearchOutput, FlaxGenerationMixin, FlaxGreedySearchOutput, FlaxSampleOutput
else:
 import sys

 UpperCAmelCase      		=					_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)



