

'''simple docstring'''



import unittest

import numpy as np

from transformers import is_tf_available
from transformers.testing_utils import require_tf


if is_tf_available():
   import tensorflow as tf

   from transformers.activations_tf import get_tf_activation

@require_tf
class 			SCREAMING_SNAKE_CASE					(							unittest.TestCase					):




      def 	__UpperCAmelCase			(					self :		Any   ):



          """simple docstring"""





          _snake_case : str												=		tf.constant([-100, -1.0, -0.1, 0, 0.1, 1.0, 100.0]   )
          _snake_case : int												=		get_tf_activation('gelu'   )
          _snake_case : Optional[int]												=		get_tf_activation('gelu_10'   )

          _snake_case : Any												=		gelu(snake_case   )
          _snake_case : Any												=		geluaa(snake_case   )

          _snake_case : Optional[int]												=		tf.where(y_gelu_aa < 10.0     ,					1.0     ,					0.0   )

          self.assertEqual(tf.math.reduce_max(snake_case   ).numpy().item()     ,					10.0   )
          self.assertTrue(np.allclose(y_gelu * clipped_mask     ,					y_gelu_aa * clipped_mask   )   )




      def 	__UpperCAmelCase			(					self :		List[Any]   ):



          """simple docstring"""





          get_tf_activation('gelu'   )
          get_tf_activation('gelu_10'   )
          get_tf_activation('gelu_fast'   )
          get_tf_activation('gelu_new'   )
          get_tf_activation('glu'   )
          get_tf_activation('mish'   )
          get_tf_activation('quick_gelu'   )
          get_tf_activation('relu'   )
          get_tf_activation('sigmoid'   )
          get_tf_activation('silu'   )
          get_tf_activation('swish'   )
          get_tf_activation('tanh'   )
          with self.assertRaises(snake_case   ):
              get_tf_activation('bogus'   )
          with self.assertRaises(snake_case   ):
              get_tf_activation(snake_case   )






'''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

SCREAMING_SNAKE_CASE_    =   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)		->    Optional[Any]:



       """simple docstring"""







       return cls

def   lowerCamelCase__       (      a__			,      a__ = None			,      a__ = None			,      a__ = None			,      a__ = None			,      )		->    Dict:



    """simple docstring"""







    _snake_case : Optional[Any]												=		device
    _snake_case : Any												=		shape[0]

    _snake_case : str												=		layout or torch.strided
    _snake_case : str												=		device or torch.device('cpu')

    if generator is not None:
        _snake_case : Any												=		generator.device.type if not isinstance(a__			,      a__) else generator[0].device.type
        if gen_device_type != device.type and gen_device_type == "cpu":
            _snake_case : Optional[Any]												=		'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(a__			,      a__):
        _snake_case : Any												=		(1,) + shape[1:]
        _snake_case : int												=		[
            torch.randn(a__			,      generator=generator[i]			,      device=a__			,      dtype=a__			,      layout=a__)
            for i in range(a__)
        ]
        _snake_case : Optional[int]												=		torch.cat(a__			,      dim=0).to(a__)
    else:
        _snake_case : Optional[Any]												=		torch.randn(a__			,      generator=a__			,      device=a__			,      dtype=a__			,      layout=a__).to(a__)

    return latents




def   lowerCamelCase__       (      a__)		->    Optional[Any]:



    """simple docstring"""







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



