

'''simple docstring'''

import os
import shutil
import unittest
from unittest.mock import patch

from transformers.testing_utils import CaptureStd, is_pt_tf_cross_test, require_torch





class 					snake_case   (   unittest.TestCase      ):





  """simple docstring"""




  @patch("sys.argv"      ,  ["fakeprogrampath", "env"]					)
  def   snake_case		(   self					):







   """simple docstring"""
   import transformers.commands.transformers_cli

   with CaptureStd() as cs:
    transformers.commands.transformers_cli.main()
   self.assertIn("Python version"      ,  cs.out					)
   self.assertIn("Platform"      ,  cs.out					)
   self.assertIn("Using distributed or parallel set-up in script?"      ,  cs.out					)






  @is_pt_tf_cross_test
  @patch(
      "sys.argv"      ,  ["fakeprogrampath", "pt-to-tf", "--model-name", "hf-internal-testing/tiny-random-gptj", "--no-pr"]					)
  def   snake_case		(   self					):







   """simple docstring"""
   import transformers.commands.transformers_cli

   shutil.rmtree("/tmp/hf-internal-testing/tiny-random-gptj"      ,  ignore_errors=UpperCamelCase					)  # cleans potential past runs
   transformers.commands.transformers_cli.main()

   # The original repo has no TF weights -- if they exist, they were created by the CLI
   self.assertTrue(os.path.exists("/tmp/hf-internal-testing/tiny-random-gptj/tf_model.h5"					)					)






  @require_torch
  @patch("sys.argv"      ,  ["fakeprogrampath", "download", "hf-internal-testing/tiny-random-gptj", "--cache-dir", "/tmp"]					)
  def   snake_case		(   self					):







   """simple docstring"""
   import transformers.commands.transformers_cli

   # # remove any previously downloaded model to start clean
   shutil.rmtree("/tmp/models--hf-internal-testing--tiny-random-gptj"      ,  ignore_errors=UpperCamelCase					)

   # run the command
   transformers.commands.transformers_cli.main()

   # check if the model files are downloaded correctly on /tmp/models--hf-internal-testing--tiny-random-gptj
   self.assertTrue(os.path.exists("/tmp/models--hf-internal-testing--tiny-random-gptj/blobs"					)					)
   self.assertTrue(os.path.exists("/tmp/models--hf-internal-testing--tiny-random-gptj/refs"					)					)
   self.assertTrue(os.path.exists("/tmp/models--hf-internal-testing--tiny-random-gptj/snapshots"					)					)







  @require_torch
  @patch(
      "sys.argv"      ,  [
          "fakeprogrampath",
          "download",
          "hf-internal-testing/test_dynamic_model_with_tokenizer",
          "--trust-remote-code",
          "--cache-dir",
          "/tmp",
      ]      ,  )
  def   snake_case		(   self					):







   """simple docstring"""
   import transformers.commands.transformers_cli

   # # remove any previously downloaded model to start clean
   shutil.rmtree("/tmp/models--hf-internal-testing--test_dynamic_model_with_tokenizer"      ,  ignore_errors=UpperCamelCase					)

   # run the command
   transformers.commands.transformers_cli.main()

   # check if the model files are downloaded correctly on /tmp/models--hf-internal-testing--test_dynamic_model_with_tokenizer
   self.assertTrue(os.path.exists("/tmp/models--hf-internal-testing--test_dynamic_model_with_tokenizer/blobs"					)					)
   self.assertTrue(os.path.exists("/tmp/models--hf-internal-testing--test_dynamic_model_with_tokenizer/refs"					)					)
   self.assertTrue(
       os.path.exists("/tmp/models--hf-internal-testing--test_dynamic_model_with_tokenizer/snapshots"					)					)







'''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 					snake_case   (   unittest.TestCase      ):





  """simple docstring"""




  def   snake_case		(   self					):







   """simple docstring"""
   lowerCamelCase_								=  tf.constant([-100, -1.0, -0.1, 0, 0.1, 1.0, 100.0]					)
   lowerCamelCase_								=  get_tf_activation("gelu"					)
   lowerCamelCase_								=  get_tf_activation("gelu_10"					)

   lowerCamelCase_								=  gelu(UpperCamelCase					)
   lowerCamelCase_								=  geluaa(UpperCamelCase					)

   lowerCamelCase_								=  tf.where(y_gelu_aa < 10.0      ,  1.0      ,  0.0					)

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







  def   snake_case		(   self					):







   """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(UpperCamelCase					):
    get_tf_activation("bogus"					)
   with self.assertRaises(UpperCamelCase					):
    get_tf_activation(UpperCamelCase					)



