code: 
  
  
  
  
  
  '''simple docstring'''
  
  import math
  from collections import OrderedDict
  
  import torch
  from packaging import version
  from torch import Tensor, nn
  
  from .utils import logging
  
  
  lowercase_			       =				logging.get_logger(__name__)
  
  
  class       a_  (       nn.Module ):
  
      '''simple docstring'''
  
  
      def __init__(	self )	->     Optional[int]:
          super().__init__()
          if version.parse(torch.__version__ ) < version.parse("""1.12.0""" ):
              raise ImportError(
                  f'You are using torch=={torch.__version__}, but torch>=1.12.0 is required to use '
                  """PytorchGELUTanh. Please upgrade torch.""" )
  
  
  
  
  
      def     snake_case_(	self				,	A )	->     Tensor:
          return nn.functional.gelu(A				,	approximate="""tanh""" )
  
  
  
  
  class       a_  (       nn.Module ):
  
      '''simple docstring'''
  
  
      def     snake_case_(	self				,	A )	->     Tensor:
          return 0.5 * input * (1.0 + torch.tanh(math.sqrt(2.0 / math.pi ) * (input + 0.04_4715 * torch.pow(A				,	3.0 )) ))
  
  
  
  
  class       a_  (       nn.Module ):
  
      '''simple docstring'''
  
  
      def __init__(	self				,	A = False )	->     List[Any]:
          super().__init__()
          if use_gelu_python:
              _SCREAMING_SNAKE_CASE             =    self._gelu_python
          else:
              _SCREAMING_SNAKE_CASE             =    nn.functional.gelu
  
  
      def     snake_case_(	self				,	A )	->     Tensor:
          return input * 0.5 * (1.0 + torch.erf(input / math.sqrt(2.0 ) ))
  
  
  
  
  
      def     snake_case_(	self				,	A )	->     Tensor:
          return self.act(A )
  
  
  
  
  class       a_  (       nn.Module ):
  
      '''simple docstring'''
  
  
      def     snake_case_(	self				,	A )	->     Tensor:
          return 0.5 * input * (1.0 + torch.tanh(input * 0.79_7884_5608 * (1.0 + 0.04_4715 * input * input) ))
  
  
  
  
  class       a_  (       nn.Module ):
  
      '''simple docstring'''
  
  
      def     snake_case_(	self				,	A )	->     Tensor:
          return input * torch.sigmoid(1.702 * input )
  
  
  
  
  class       a_  (       nn.Module ):
  
      '''simple docstring'''
  
  
      def __init__(	self				,	A				,	A )	->     Union[str, Any]:
          if min > max:
              raise ValueError(f'min should be < max (got min: {min}, max: {max})' )
  
          super().__init__()
          _SCREAMING_SNAKE_CASE             =    min
          _SCREAMING_SNAKE_CASE             =    max
  
  
  
  
  
      def     snake_case_(	self				,	A )	->     Tensor:
          return torch.clip(gelu(A )				,	self.min				,	self.max )
  
  
  
  
  class       a_  (       nn.Module ):
  
      '''simple docstring'''
  
  
      def __init__(	self )	->     Optional[Any]:
          super().__init__()
          _SCREAMING_SNAKE_CASE             =    math.sqrt(2 / math.pi )
  
  
  
  
  
      def     snake_case_(	self				,	A )	->     Tensor:
          return 0.5 * input * (1 + torch.tanh(self.precomputed_constant * (input + 0.04_4715 * torch.pow(A				,	3 )) ))
  
  
  
  
  class       a_  (       nn.Module ):
  
      '''simple docstring'''
  
  
      def     snake_case_(	self				,	A )	->     Tensor:
          return nn.functional.silu(A )
  
  
  
  
  class       a_  (       nn.Module ):
  
      '''simple docstring'''
  
  
      def __init__(	self )	->     Tuple:
          super().__init__()
          if version.parse(torch.__version__ ) < version.parse("""1.9.0""" ):
              _SCREAMING_SNAKE_CASE             =    self._mish_python
          else:
              _SCREAMING_SNAKE_CASE             =    nn.functional.mish
  
  
      def     snake_case_(	self				,	A )	->     Tensor:
          return input * torch.tanh(nn.functional.softplus(A ) )
  
  
  
  
  
      def     snake_case_(	self				,	A )	->     Tensor:
          return self.act(A )
  
  
  
  
  class       a_  (       nn.Module ):
  
      '''simple docstring'''
  
  
      def     snake_case_(	self				,	A )	->     Tensor:
          return input
  
  
  
  
  class       a_  (       nn.Module ):
  
      '''simple docstring'''
  
  
      def     snake_case_(	self				,	A				,	A=0.70_7107				,	A=0.28_2095 )	->     Optional[int]:
          _SCREAMING_SNAKE_CASE             =    (input - mu).div(sigma * math.sqrt(2.0 ) )
          return 0.5 * (1.0 + torch.erf(A ))
  
  
  
  
  class       a_  (       nn.Module ):
  
      '''simple docstring'''
  
  
      def     snake_case_(	self				,	A )	->     Tuple:
          _SCREAMING_SNAKE_CASE             =    nn.functional.relu(A )
          _SCREAMING_SNAKE_CASE             =    torch.square(A )
          return squared
  
  
  
  
  class       a_  (       snake_case_ ):
  
      '''simple docstring'''
  
  
      def __getitem__(	self				,	A )	->     Any:
          _SCREAMING_SNAKE_CASE             =    super().__getitem__(A )
          _SCREAMING_SNAKE_CASE       , _SCREAMING_SNAKE_CASE             =    content if isinstance(A				,	A ) else (content, {})
          return cls(**A )
  
  
  
  
  lowercase_			       =				{
      """gelu""": GELUActivation,
      """gelu_10""": (ClippedGELUActivation, {"""min""": -10, """max""": 10}),
      """gelu_fast""": FastGELUActivation,
      """gelu_new""": NewGELUActivation,
      """gelu_python""": (GELUActivation, {"""use_gelu_python""": True}),
      """gelu_pytorch_tanh""": PytorchGELUTanh,
      """gelu_accurate""": AccurateGELUActivation,
      """laplace""": LaplaceActivation,
      """linear""": LinearActivation,
      """mish""": MishActivation,
      """quick_gelu""": QuickGELUActivation,
      """relu""": nn.ReLU,
      """relu2""": ReLUSquaredActivation,
      """relu6""": nn.ReLUa,
      """sigmoid""": nn.Sigmoid,
      """silu""": SiLUActivation,
      """swish""": SiLUActivation,
      """tanh""": nn.Tanh,
  }
  lowercase_			       =				ClassInstantier(ACTaCLS)
  
  
  
  
  
  def lowerCamelCase		(  __lowerCamelCase				:					int					)		->Optional[int]:
      if activation_string in ACTaFN:
          return ACTaFN[activation_string]
      else:
          raise KeyError(F'function {activation_string} not found in ACT2FN mapping {list(ACTaFN.keys()					)}'					)
  
  
  # For backwards compatibility with: from activations import gelu_python
  lowercase_			       =				get_activation("""gelu_python""")
  lowercase_			       =				get_activation("""gelu_new""")
  lowercase_			       =				get_activation("""gelu""")
  lowercase_			       =				get_activation("""gelu_fast""")
  lowercase_			       =				get_activation("""quick_gelu""")
  lowercase_			       =				get_activation("""silu""")
  lowercase_			       =				get_activation("""mish""")
  
  
  
  
  
  
  lowercase_			       =				get_activation("""linear""")
  
  
  
  
style_context: 
  
  
  
  
  
  '''simple docstring'''
  
  import json
  import os
  import tempfile
  import unittest
  
  from transformers.modelcard import ModelCard
  
  
  class       a_  (       unittest.TestCase ):
  
      '''simple docstring'''
  
  
      def     snake_case_(	self )	->     int:
          _SCREAMING_SNAKE_CASE             =    {
              """model_details""": {
                  """Organization""": """testing""",
                  """Model date""": """today""",
                  """Model version""": """v2.1, Developed by Test Corp in 2019.""",
                  """Architecture""": """Convolutional Neural Network.""",
              },
              """metrics""": """BLEU and ROUGE-1""",
              """evaluation_data""": {
                  """Datasets""": {"""BLEU""": """My-great-dataset-v1""", """ROUGE-1""": """My-short-dataset-v2.1"""},
                  """Preprocessing""": """See details on https://arxiv.org/pdf/1810.03993.pdf""",
              },
              """training_data""": {
                  """Dataset""": """English Wikipedia dump dated 2018-12-01""",
                  """Preprocessing""": (
                      """Using SentencePiece vocabulary of size 52k tokens. See details on"""
                      """ https://arxiv.org/pdf/1810.03993.pdf"""
                  ),
              },
              """quantitative_analyses""": {"""BLEU""": 55.1, """ROUGE-1""": 76},
          }
  
  
      def     snake_case_(	self )	->     Tuple:
          _SCREAMING_SNAKE_CASE             =    ModelCard.from_dict(self.inputs_dict )
          self.assertTrue(hasattr(A				,	"""model_details""" ) )
          self.assertTrue(hasattr(A				,	"""intended_use""" ) )
          self.assertTrue(hasattr(A				,	"""factors""" ) )
          self.assertTrue(hasattr(A				,	"""metrics""" ) )
          self.assertTrue(hasattr(A				,	"""evaluation_data""" ) )
          self.assertTrue(hasattr(A				,	"""training_data""" ) )
          self.assertTrue(hasattr(A				,	"""quantitative_analyses""" ) )
          self.assertTrue(hasattr(A				,	"""ethical_considerations""" ) )
          self.assertTrue(hasattr(A				,	"""caveats_and_recommendations""" ) )
  
  
      def     snake_case_(	self )	->     List[str]:
          _SCREAMING_SNAKE_CASE             =    ModelCard.from_dict(self.inputs_dict )
          _SCREAMING_SNAKE_CASE             =    json.loads(modelcard.to_json_string() )
          for key, value in self.inputs_dict.items():
              self.assertEqual(obj[key]				,	A )
  
  
      def     snake_case_(	self )	->     Any:
          _SCREAMING_SNAKE_CASE             =    ModelCard.from_dict(self.inputs_dict )
  
          with tempfile.TemporaryDirectory() as tmpdirname:
              _SCREAMING_SNAKE_CASE             =    os.path.join(A				,	"""modelcard.json""" )
              model_card_first.to_json_file(A )
              _SCREAMING_SNAKE_CASE             =    ModelCard.from_json_file(A )
  
          self.assertEqual(model_card_second.to_dict()				,	model_card_first.to_dict() )
  
  
  
  
  
      def     snake_case_(	self )	->     List[Any]:
          _SCREAMING_SNAKE_CASE             =    ModelCard.from_dict(self.inputs_dict )
  
          with tempfile.TemporaryDirectory() as tmpdirname:
              model_card_first.save_pretrained(A )
              _SCREAMING_SNAKE_CASE             =    ModelCard.from_pretrained(A )
  
          self.assertEqual(model_card_second.to_dict()				,	model_card_first.to_dict() )
  
  
  
  