






"""simple docstring"""







from manim import *


class 			_lowercase		(   snake_case_  ):

				def        A (     self       :    str     ):


										'''simple docstring'''
										UpperCAmelCase__						=		Rectangle(height=0.5       ,    width=0.5     )
										UpperCAmelCase__						=		Rectangle(height=0.46       ,    width=0.46     ).set_stroke(width=0     )
										UpperCAmelCase__						=		Rectangle(height=0.25       ,    width=0.25     )

										UpperCAmelCase__						=		[mem.copy() for i in range(6     )]
										UpperCAmelCase__						=		[mem.copy() for i in range(6     )]
										UpperCAmelCase__						=		VGroup(*_lowercase     ).arrange(_lowercase       ,    buff=0     )
										UpperCAmelCase__						=		VGroup(*_lowercase     ).arrange(_lowercase       ,    buff=0     )
										UpperCAmelCase__						=		VGroup(_lowercase       ,    _lowercase     ).arrange(_lowercase       ,    buff=0     )
										UpperCAmelCase__						=		Text("""CPU"""       ,    font_size=2_4     )
										UpperCAmelCase__						=		Group(_lowercase       ,    _lowercase     ).arrange(_lowercase       ,    buff=0.5       ,    aligned_edge=_lowercase     )
										cpu.move_to([-2.5, -0.5, 0]     )
										self.add(_lowercase     )

										UpperCAmelCase__						=		[mem.copy() for i in range(4     )]
										UpperCAmelCase__						=		VGroup(*_lowercase     ).arrange(_lowercase       ,    buff=0     )
										UpperCAmelCase__						=		Text("""GPU"""       ,    font_size=2_4     )
										UpperCAmelCase__						=		Group(_lowercase       ,    _lowercase     ).arrange(_lowercase       ,    buff=0.5       ,    aligned_edge=_lowercase     )
										gpu.move_to([-1, -1, 0]     )
										self.add(_lowercase     )

										UpperCAmelCase__						=		[mem.copy() for i in range(6     )]
										UpperCAmelCase__						=		VGroup(*_lowercase     ).arrange(_lowercase       ,    buff=0     )

										UpperCAmelCase__						=		Text("""Model"""       ,    font_size=2_4     )
										UpperCAmelCase__						=		Group(_lowercase       ,    _lowercase     ).arrange(_lowercase       ,    buff=0.5       ,    aligned_edge=_lowercase     )
										model.move_to([3, -1.0, 0]     )
										self.add(_lowercase     )

										UpperCAmelCase__						=		[]
										UpperCAmelCase__						=		[]

										for i, rect in enumerate(_lowercase     ):
																rect.set_stroke(_lowercase     )

																UpperCAmelCase__						=		Rectangle(height=0.46 / 4       ,    width=0.46 / 3     ).set_stroke(width=0.0     ).set_fill(_lowercase       ,    opacity=0.7     )

																if i == 0:
																						cpu_target.next_to(cpu_left_col_base[0].get_corner(DOWN + LEFT     )       ,    buff=0.02       ,    direction=_lowercase     )
																						cpu_target.set_x(cpu_target.get_x() + 0.1     )
																elif i == 3:
																						cpu_target.next_to(model_cpu_arr[0]       ,    direction=_lowercase       ,    buff=0.0     )
																else:
																						cpu_target.next_to(model_cpu_arr[i - 1]       ,    direction=_lowercase       ,    buff=0.0     )
																self.add(_lowercase     )
																model_cpu_arr.append(_lowercase     )

										self.add(*_lowercase       ,    *_lowercase     )

										UpperCAmelCase__						=		[meta_mem.copy() for i in range(6     )]
										UpperCAmelCase__						=		[meta_mem.copy() for i in range(6     )]
										UpperCAmelCase__						=		VGroup(*_lowercase     ).arrange(_lowercase       ,    buff=0     )
										UpperCAmelCase__						=		VGroup(*_lowercase     ).arrange(_lowercase       ,    buff=0     )
										UpperCAmelCase__						=		VGroup(_lowercase       ,    _lowercase     ).arrange(_lowercase       ,    buff=0     )
										UpperCAmelCase__						=		Text("""Disk"""       ,    font_size=2_4     )
										UpperCAmelCase__						=		Group(_lowercase       ,    _lowercase     ).arrange(_lowercase       ,    buff=0.5       ,    aligned_edge=_lowercase     )
										disk.move_to([-4.0, -1.25, 0]     )
										self.add(_lowercase       ,    _lowercase     )

										UpperCAmelCase__						=		[]

										for i in range(6     ):
																UpperCAmelCase__						=		fill.copy().set_fill(_lowercase       ,    opacity=0.8     )
																target.move_to(disk_left_col_base[i]     ).scale(0.5     )
																cpu_disk_arr.append(_lowercase     )

										self.add(*_lowercase     )

										UpperCAmelCase__						=		Square(side_length=2.2     )
										key.move_to([-5, 2, 0]     )

										UpperCAmelCase__						=		MarkupText(
										    f'<b>Key:</b>\n\n<span fgcolor=\'{YELLOW}\'>●</span> Empty Model'       ,    font_size=1_8       ,    )

										key_text.move_to([-5, 2.4, 0]     )

										self.add(_lowercase       ,    _lowercase     )

										UpperCAmelCase__						=		MarkupText(
										    f'<span fgcolor=\'{BLUE}\'>●</span> Checkpoint'       ,    font_size=1_8       ,    )

										blue_text.next_to(_lowercase       ,    DOWN * 2.4       ,    aligned_edge=key_text.get_left()     )
										self.add(_lowercase     )

										UpperCAmelCase__						=		MarkupText(f'The offloaded weights are all sent to the CPU.'       ,    font_size=2_4     )
										step_a.move_to([2, 2, 0]     )

										self.play(Write(_lowercase       ,    run_time=3     )     )

										for i in range(6     ):
																UpperCAmelCase__						=		cpu_disk_arr[i]
																UpperCAmelCase__						=		rect.copy().set_fill(_lowercase       ,    opacity=0.8     ).scale(2.0     )
																cpa.generate_target()
																cpa.target.move_to(model_base[i]     )

																if i == 0:
																						rect.set_fill(_lowercase       ,    opacity=0.8     )
																						rect.generate_target()
																						rect.target.move_to(cpu_left_col_base[0]     ).scale(2.0     )

																						self.remove(
																						    *_lowercase       ,    *_lowercase       ,    )

																else:
																						rect.generate_target()
																						rect.target.move_to(cpu_left_col_base[i]     ).scale(2.0     )
																self.play(MoveToTarget(_lowercase     )       ,    MoveToTarget(_lowercase     )       ,    model_base[i].animate.set_stroke(_lowercase     )     )
										self.play(FadeOut(_lowercase     )     )

										UpperCAmelCase__						=		MarkupText(
										    f'Finally, hooks are added to each weight in the model\nto transfer the weights from CPU to GPU\n\t\tand back when needed.'       ,    font_size=2_4       ,    )
										step_a.move_to([2, 2, 0]     )

										self.play(Write(_lowercase       ,    run_time=3     )     )

										UpperCAmelCase__						=		[]
										UpperCAmelCase__						=		[]
										for i in range(6     ):
																UpperCAmelCase__						=		Arrow(start=_lowercase       ,    end=_lowercase       ,    color=_lowercase       ,    buff=0.5     )
																a.next_to(model_base[i].get_left()       ,    _lowercase       ,    buff=0.2     )
																arrows.append(_lowercase     )
																animations.append(Write(_lowercase     )     )
										self.play(*_lowercase     )
										self.wait()


"""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     )

