






"""simple docstring"""







import inspect
import os
import unittest

import torch

import accelerate
from accelerate import debug_launcher
from accelerate.test_utils import (
    execute_subprocess_async,
    require_cpu,
    require_multi_gpu,
    require_single_gpu,
    test_sync,
)
from accelerate.utils import patch_environment


class 			_lowercase		(   unittest.TestCase  ):

				def        A (     self       :    Optional[int]     ):


										'''simple docstring'''
										UpperCAmelCase__						=		inspect.getfile(accelerate.test_utils     )
										UpperCAmelCase__						=		os.path.sep.join(mod_file.split(os.path.sep     )[:-1] + ["""scripts""", """test_sync.py"""]     )

				@require_cpu
				def        A (     self       :    Dict     ):


										'''simple docstring'''
										debug_launcher(test_sync.main       ,    num_processes=1     )

				@require_cpu
				def        A (     self       :    Optional[int]     ):


										'''simple docstring'''
										debug_launcher(test_sync.main     )

				@require_single_gpu
				def        A (     self       :    Any     ):


										'''simple docstring'''
										test_sync.main()

				@require_multi_gpu
				def        A (     self       :    List[Any]     ):


										'''simple docstring'''
										print(f'Found {torch.cuda.device_count()} devices.'     )
										UpperCAmelCase__						=		["""torchrun""", f'--nproc_per_node={torch.cuda.device_count()}', self.test_file_path]
										with patch_environment(omp_num_threads=1     ):
																execute_subprocess_async(_lowercase       ,    env=os.environ.copy()     )


"""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 			_lowercase		(   unittest.TestCase  ):

				def        A (     self       :    Any     ):


										'''simple docstring'''
										UpperCAmelCase__						=		tf.constant([-1_0_0, -1.0, -0.1, 0, 0.1, 1.0, 100.0]     )
										UpperCAmelCase__						=		get_tf_activation("""gelu"""     )
										UpperCAmelCase__						=		get_tf_activation("""gelu_10"""     )

										UpperCAmelCase__						=		gelu(_lowercase     )
										UpperCAmelCase__						=		geluaa(_lowercase     )

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

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

				def        A (     self       :    Optional[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(_lowercase     ):
																get_tf_activation("""bogus"""     )
										with self.assertRaises(_lowercase     ):
																get_tf_activation(_lowercase     )

