


'''simple docstring'''
import importlib.metadata
import sys

from transformers.testing_utils import TestCasePlus
from transformers.utils.versions import require_version, require_version_core


lowerCAmelCase  =				importlib.metadata.version("""numpy""")
lowerCAmelCase  =				""".""".join([str(x) for x in sys.version_info[:3]])






class 					lowerCAmelCase_     (    UpperCAmelCase  ):






       def      UpperCamelCase	(   self      )->			Dict:
            # lt + different version strings
            require_version_core('numpy<1000.4.5'      )
            require_version_core('numpy<1000.4'      )
            require_version_core('numpy<1000'      )

            # le
            require_version_core('numpy<=1000.4.5'      )
            require_version_core(F'numpy<={numpy_ver}'      )

            # eq
            require_version_core(F'numpy=={numpy_ver}'      )

            # ne
            require_version_core('numpy!=1000.4.5'      )

            # ge
            require_version_core('numpy>=1.0'      )
            require_version_core('numpy>=1.0.0'      )
            require_version_core(F'numpy>={numpy_ver}'      )

            # gt
            require_version_core('numpy>1.0.0'      )

            # mix
            require_version_core('numpy>1.0.0,<1000'      )

            # requirement w/o version
            require_version_core('numpy'      )

            # unmet requirements due to version conflict
            for req in ["numpy==1.0.0", "numpy>=1000.0.0", F'numpy<{numpy_ver}']:
                 try:
                      require_version_core(_UpperCamelCase      )
                 except ImportError as e:
                      self.assertIn(F'{req} is required' ,    str(_UpperCamelCase      )      )
                      self.assertIn('but found' ,    str(_UpperCamelCase      )      )

        # unmet requirements due to missing module
            for req in ["numpipypie>1", "numpipypie2"]:
                 try:
                      require_version_core(_UpperCamelCase      )
                 except importlib.metadata.PackageNotFoundError as e:
                      self.assertIn(F'The \'{req}\' distribution was not found and is required by this application' ,    str(_UpperCamelCase      )      )
                      self.assertIn('Try: pip install transformers -U' ,    str(_UpperCamelCase      )      )

        # bogus requirements formats:
        # 1. whole thing
            for req in ["numpy??1.0.0", "numpy1.0.0"]:
                 try:
                      require_version_core(_UpperCamelCase      )
                 except ValueError as e:
                      self.assertIn('requirement needs to be in the pip package format' ,    str(_UpperCamelCase      )      )
        # 2. only operators
            for req in ["numpy=1.0.0", "numpy == 1.00", "numpy<>1.0.0", "numpy><1.00", "numpy>>1.0.0"]:
                 try:
                      require_version_core(_UpperCamelCase      )
                 except ValueError as e:
                      self.assertIn('need one of ' ,    str(_UpperCamelCase      )      )






       def      UpperCamelCase	(   self      )->			List[str]:
            # matching requirement
            require_version('python>=3.6.0'      )

            # not matching requirements
            for req in ["python>9.9.9", "python<3.0.0"]:
                 try:
                      require_version_core(_UpperCamelCase      )
                 except ImportError as e:
                      self.assertIn(F'{req} is required' ,    str(_UpperCamelCase      )      )
                      self.assertIn(F'but found python=={python_ver}' ,    str(_UpperCamelCase      )      )









'''simple docstring'''
from typing import List, Optional, Tuple, Union

from . import logging
from .import_utils import is_torch_available, is_torch_version


if is_torch_available():
    import torch

lowerCAmelCase  =				logging.get_logger(__name__)  # pylint: disable=invalid-name

try:
    from torch._dynamo import allow_in_graph as maybe_allow_in_graph
except (ImportError, ModuleNotFoundError):

    def 				lowerCamelCase_   (   cls				:					Tuple		)				->  Dict:







         """simple docstring"""
         return cls

def 				lowerCamelCase_   (   __UpperCamelCase				:					Union[Tuple, List]       ,						__UpperCamelCase				:					Optional[Union[List["torch.Generator"], "torch.Generator"]] = None       ,						__UpperCamelCase				:					Optional["torch.device"] = None       ,						__UpperCamelCase				:					Optional["torch.dtype"] = None       ,						__UpperCamelCase				:					Optional["torch.layout"] = None       ,						)				->  Tuple:







     """simple docstring"""
     _A				=       device
     _A				=       shape[0]

     _A				=       layout or torch.strided
     _A				=       device or torch.device('cpu'		)

     if generator is not None:
          _A				=       generator.device.type if not isinstance(__UpperCamelCase       ,						__UpperCamelCase		) else generator[0].device.type
          if gen_device_type != device.type and gen_device_type == "cpu":
               _A				=       'cpu'
               if device != "mps":
                    logger.info(
                        F'The passed generator was created on \'cpu\' even though a tensor on {device} was expected.'
                        F' Tensors will be created on \'cpu\' and then moved to {device}. Note that one can probably'
                        F' slighly speed up this function by passing a generator that was created on the {device} device.'		)
          elif gen_device_type != device.type and gen_device_type == "cuda":
               raise ValueError(F'Cannot generate a {device} tensor from a generator of type {gen_device_type}.'		)

     if isinstance(__UpperCamelCase       ,						__UpperCamelCase		):
          _A				=       (1,) + shape[1:]
          _A				=       [
              torch.randn(__UpperCamelCase       ,						generator=generator[i]       ,						device=__UpperCamelCase       ,						dtype=__UpperCamelCase       ,						layout=__UpperCamelCase		)
              for i in range(__UpperCamelCase		)
          ]
          _A				=       torch.cat(__UpperCamelCase       ,						dim=0		).to(__UpperCamelCase		)
     else:
          _A				=       torch.randn(__UpperCamelCase       ,						generator=__UpperCamelCase       ,						device=__UpperCamelCase       ,						dtype=__UpperCamelCase       ,						layout=__UpperCamelCase		).to(__UpperCamelCase		)

     return latents

def 				lowerCamelCase_   (   __UpperCamelCase				:					Any		)				->  Optional[int]:







     """simple docstring"""
     if is_torch_version('<'       ,						'2.0.0'		) or not hasattr(__UpperCamelCase       ,						'_dynamo'		):
          return False
     return isinstance(__UpperCamelCase       ,						torch._dynamo.eval_frame.OptimizedModule		)





