
"""simple docstring"""





from manim import *
class 						SCREAMING_SNAKE_CASE_ (						__a ):




		"""simple docstring"""





		def 	snake_case_     (     self):
				__SCREAMING_SNAKE_CASE            = Rectangle(height=0.5							,  width=0.5)
				__SCREAMING_SNAKE_CASE            = Rectangle(height=0.46							,  width=0.46).set_stroke(width=0)

				__SCREAMING_SNAKE_CASE            = Rectangle(height=0.25							,  width=0.25)

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

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

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

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

				__SCREAMING_SNAKE_CASE            = []
				__SCREAMING_SNAKE_CASE            = []

				for i, rect in enumerate(lowerCAmelCase__):
						__SCREAMING_SNAKE_CASE            = fill.copy().set_fill(lowerCAmelCase__							,  opacity=0.8)
						target.move_to(lowerCAmelCase__)
						model_arr.append(lowerCAmelCase__)

						__SCREAMING_SNAKE_CASE            = Rectangle(height=0.46							,  width=0.46).set_stroke(width=0.0).set_fill(lowerCAmelCase__							,  opacity=0.8)
						cpu_target.move_to(cpu_left_col_base[i])
						model_cpu_arr.append(lowerCAmelCase__)

				self.add(*lowerCAmelCase__							,  *lowerCAmelCase__)

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

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

				__SCREAMING_SNAKE_CASE            = 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(lowerCAmelCase__							,  lowerCAmelCase__)

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

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

				__SCREAMING_SNAKE_CASE            = MarkupText(
				    f"Now watch as an input is passed through the model\nand how the memory is utilized and handled."							,  font_size=2_4							,  )
				step_a.move_to([2, 2, 0])

				self.play(Write(lowerCAmelCase__))

				__SCREAMING_SNAKE_CASE            = Square(0.3)
				input.set_fill(lowerCAmelCase__							,  opacity=1.0)
				input.set_stroke(width=0.0)
				input.next_to(model_base[0]							,  lowerCAmelCase__							,  buff=0.5)

				self.play(Write(lowerCAmelCase__))

				input.generate_target()
				input.target.next_to(model_arr[0]							,  direction=lowerCAmelCase__							,  buff=0.02)
				self.play(MoveToTarget(lowerCAmelCase__))

				self.play(FadeOut(lowerCAmelCase__))

				__SCREAMING_SNAKE_CASE            = Arrow(start=lowerCAmelCase__							,  end=lowerCAmelCase__							,  color=lowerCAmelCase__							,  buff=0.5)
				a.next_to(model_arr[0].get_left()							,  lowerCAmelCase__							,  buff=0.2)

				model_cpu_arr[0].generate_target()
				model_cpu_arr[0].target.move_to(gpu_rect[0])

				__SCREAMING_SNAKE_CASE            = MarkupText(
				    f"As the input reaches a layer, the hook triggers\nand weights are moved from the CPU\nto the GPU and back."							,  font_size=2_4							,  )
				step_a.move_to([2, 2, 0])

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

				__SCREAMING_SNAKE_CASE            = {"""run_time""": 1, """fade_in""": True, """fade_out""": True, """buff""": 0.02}

				self.play(
				    Write(lowerCAmelCase__)							,  Circumscribe(model_arr[0]							,  color=lowerCAmelCase__							,  **lowerCAmelCase__)							,  Circumscribe(model_cpu_arr[0]							,  color=lowerCAmelCase__							,  **lowerCAmelCase__)							,  Circumscribe(gpu_rect[0]							,  color=lowerCAmelCase__							,  **lowerCAmelCase__)							,  )
				self.play(MoveToTarget(model_cpu_arr[0]))

				__SCREAMING_SNAKE_CASE            = a.copy()
				for i in range(6):
						a_c.next_to(model_arr[i].get_right() + 0.02							,  lowerCAmelCase__							,  buff=0.2)

						input.generate_target()
						input.target.move_to(model_arr[i].get_right() + 0.02)

						__SCREAMING_SNAKE_CASE            = AnimationGroup(
						    FadeOut(lowerCAmelCase__							,  run_time=0.5)							,  MoveToTarget(lowerCAmelCase__							,  run_time=0.5)							,  FadeIn(lowerCAmelCase__							,  run_time=0.5)							,  lag_ratio=0.2)

						self.play(lowerCAmelCase__)

						model_cpu_arr[i].generate_target()
						model_cpu_arr[i].target.move_to(cpu_left_col_base[i])

						if i < 5:
								model_cpu_arr[i + 1].generate_target()
								model_cpu_arr[i + 1].target.move_to(gpu_rect[0])
								if i >= 1:
										__SCREAMING_SNAKE_CASE            = 0.7

								self.play(
								    Circumscribe(model_arr[i]							,  **lowerCAmelCase__)							,  Circumscribe(cpu_left_col_base[i]							,  **lowerCAmelCase__)							,  Circumscribe(cpu_left_col_base[i + 1]							,  color=lowerCAmelCase__							,  **lowerCAmelCase__)							,  Circumscribe(gpu_rect[0]							,  color=lowerCAmelCase__							,  **lowerCAmelCase__)							,  Circumscribe(model_arr[i + 1]							,  color=lowerCAmelCase__							,  **lowerCAmelCase__)							,  )
								if i < 1:
										self.play(
										    MoveToTarget(model_cpu_arr[i])							,  MoveToTarget(model_cpu_arr[i + 1])							,  )
								else:
										self.play(
										    MoveToTarget(model_cpu_arr[i]							,  run_time=0.7)							,  MoveToTarget(model_cpu_arr[i + 1]							,  run_time=0.7)							,  )
						else:
								model_cpu_arr[i].generate_target()
								model_cpu_arr[i].target.move_to(cpu_left_col_base[-1])
								input.generate_target()
								input.target.next_to(model_arr[-1].get_right()							,  RIGHT + 0.02							,  buff=0.2)

								self.play(
								    Circumscribe(model_arr[-1]							,  color=lowerCAmelCase__							,  **lowerCAmelCase__)							,  Circumscribe(cpu_left_col_base[-1]							,  color=lowerCAmelCase__							,  **lowerCAmelCase__)							,  Circumscribe(gpu_rect[0]							,  color=lowerCAmelCase__							,  **lowerCAmelCase__)							,  )

								self.play(MoveToTarget(model_cpu_arr[i]))

						__SCREAMING_SNAKE_CASE            = a_c
						__SCREAMING_SNAKE_CASE            = a_c.copy()

				input.generate_target()
				input.target.next_to(model_base[-1]							,  RIGHT + 0.02							,  buff=0.5)
				self.play(
				    FadeOut(lowerCAmelCase__)							,  FadeOut(lowerCAmelCase__							,  run_time=0.5)							,  )

				__SCREAMING_SNAKE_CASE            = MarkupText(f"Inference on a model too large for GPU memory\nis successfully completed."							,  font_size=2_4)
				step_a.move_to([2, 2, 0])

				self.play(Write(lowerCAmelCase__							,  run_time=3)							,  MoveToTarget(lowerCAmelCase__))

				self.wait()






import unittest

from transformers import AlbertTokenizer, AlbertTokenizerFast
from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin


lowerCamelCase__          =		get_tests_dir("""fixtures/spiece.model""")







@require_sentencepiece
@require_tokenizers
class      A__							(     __magic_name__						,   unittest.TestCase	):
				lowercase			    =  AlbertTokenizer
				lowercase			    =  AlbertTokenizerFast
				lowercase			    =  True
				lowercase			    =  True
				lowercase			    =  True






				def 							_lowerCamelCase		(						self					:      int   ):






							'''simple docstring'''







							super().setUp()

							# We have a SentencePiece fixture for testing
							lowerCAmelCase__      :      int         =		AlbertTokenizer(a   )
							tokenizer.save_pretrained(self.tmpdirname   )






				def 							_lowerCamelCase		(						self					:      List[str]    ,     a					:      int   ):






							'''simple docstring'''







							lowerCAmelCase__      :      Any         =		'this is a test'
							lowerCAmelCase__      :      List[Any]         =		'this is a test'
							return input_text, output_text






				def 							_lowerCamelCase		(						self					:      Tuple   ):






							'''simple docstring'''







							lowerCAmelCase__      :      Tuple         =		'<pad>'
							lowerCAmelCase__      :      Optional[Any]         =		0

							self.assertEqual(self.get_tokenizer()._convert_token_to_id(a   )    ,     a   )
							self.assertEqual(self.get_tokenizer()._convert_id_to_token(a   )    ,     a   )






				def 							_lowerCamelCase		(						self					:      Union[str, Any]   ):






							'''simple docstring'''







							lowerCAmelCase__      :      Optional[Any]         =		list(self.get_tokenizer().get_vocab().keys()   )

							self.assertEqual(vocab_keys[0]    ,     '<pad>'   )
							self.assertEqual(vocab_keys[1]    ,     '<unk>'   )
							self.assertEqual(vocab_keys[-1]    ,     '▁eloquent'   )
							self.assertEqual(len(a   )    ,     30_000   )






				def 							_lowerCamelCase		(						self					:      Optional[Any]   ):






							'''simple docstring'''







							self.assertEqual(self.get_tokenizer().vocab_size    ,     30_000   )






				def 							_lowerCamelCase		(						self					:      List[str]   ):






							'''simple docstring'''







							if not self.test_rust_tokenizer:
										return

							lowerCAmelCase__      :      str         =		self.get_tokenizer()
							lowerCAmelCase__      :      str         =		self.get_rust_tokenizer()

							lowerCAmelCase__      :      List[Any]         =		'I was born in 92000, and this is falsé.'

							lowerCAmelCase__      :      str         =		tokenizer.tokenize(a   )
							lowerCAmelCase__      :      Optional[int]         =		rust_tokenizer.tokenize(a   )
							self.assertListEqual(a    ,     a   )

							lowerCAmelCase__      :      Tuple         =		tokenizer.encode(a    ,     add_special_tokens=a   )
							lowerCAmelCase__      :      Union[str, Any]         =		rust_tokenizer.encode(a    ,     add_special_tokens=a   )
							self.assertListEqual(a    ,     a   )

							lowerCAmelCase__      :      Optional[Any]         =		self.get_rust_tokenizer()
							lowerCAmelCase__      :      Dict         =		tokenizer.encode(a   )
							lowerCAmelCase__      :      List[Any]         =		rust_tokenizer.encode(a   )
							self.assertListEqual(a    ,     a   )






				def 							_lowerCamelCase		(						self					:      int   ):






							'''simple docstring'''







							lowerCAmelCase__      :      Tuple         =		AlbertTokenizer(a    ,     keep_accents=a   )

							lowerCAmelCase__      :      Union[str, Any]         =		tokenizer.tokenize('This is a test'   )
							self.assertListEqual(a    ,     ['▁this', '▁is', '▁a', '▁test']   )

							self.assertListEqual(tokenizer.convert_tokens_to_ids(a   )    ,     [48, 25, 21, 1_289]   )

							lowerCAmelCase__      :      Tuple         =		tokenizer.tokenize('I was born in 92000, and this is falsé.'   )
							self.assertListEqual(
							    a    ,     ['▁i', '▁was', '▁born', '▁in', '▁9', '2000', ',', '▁and', '▁this', '▁is', '▁fal', 's', 'é', '.']   )
							lowerCAmelCase__      :      Any         =		tokenizer.convert_tokens_to_ids(a   )
							self.assertListEqual(a    ,     [31, 23, 386, 19, 561, 3_050, 15, 17, 48, 25, 8_256, 18, 1, 9]   )

							lowerCAmelCase__      :      Any         =		tokenizer.convert_ids_to_tokens(a   )
							self.assertListEqual(
							    a    ,     ['▁i', '▁was', '▁born', '▁in', '▁9', '2000', ',', '▁and', '▁this', '▁is', '▁fal', 's', '<unk>', '.']    ,     )






				def 							_lowerCamelCase		(						self					:      List[str]   ):






							'''simple docstring'''







							lowerCAmelCase__      :      List[str]         =		AlbertTokenizer(a   )

							lowerCAmelCase__      :      Tuple         =		tokenizer.encode('sequence builders'   )
							lowerCAmelCase__      :      Any         =		tokenizer.encode('multi-sequence build'   )

							lowerCAmelCase__      :      Dict         =		tokenizer.build_inputs_with_special_tokens(a   )
							lowerCAmelCase__      :      Tuple         =		tokenizer.build_inputs_with_special_tokens(a    ,     a   )

							assert encoded_sentence == [tokenizer.cls_token_id] + text + [tokenizer.sep_token_id]
							assert encoded_pair == [tokenizer.cls_token_id] + text + [tokenizer.sep_token_id] + text_a + [
							    tokenizer.sep_token_id
							]






				@slow
				def 							_lowerCamelCase		(						self					:      Union[str, Any]   ):






							'''simple docstring'''







							lowerCAmelCase__      :      Dict         =		{'attention_mask': [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], 'input_ids': [[2, 21_970, 13, 5, 6_092, 167, 28, 7_103, 2_153, 673, 8, 7_028, 12_051, 18, 17, 7_103, 2_153, 673, 8, 3_515, 18_684, 8, 4_461, 6, 1_927, 297, 8, 12_060, 2_607, 18, 13, 5, 4_461, 15, 10_538, 38, 8, 135, 15, 822, 58, 15, 993, 10_363, 15, 1_460, 8_005, 4_461, 15, 993, 255, 2_328, 9, 9, 9, 6, 26, 1_112, 816, 3_260, 13, 5, 103, 2_377, 6, 17, 1_112, 816, 2_782, 13, 5, 103, 10_641, 6, 29, 84, 2_512, 2_430, 782, 18_684, 2_761, 19, 808, 2_430, 2_556, 17, 855, 1_480, 9_477, 4_091, 128, 11_712, 15, 7_103, 2_153, 673, 17, 24_883, 9_990, 9, 3], [2, 11_502, 25, 1_006, 20, 782, 8, 11_809, 855, 1_732, 19_393, 18_667, 37, 367, 21_018, 69, 1_854, 34, 11_860, 19_124, 27, 156, 225, 17, 193, 4_141, 19, 65, 9_124, 9, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [2, 14, 2_231, 886, 2_385, 17_659, 84, 14, 16_792, 1_952, 9, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], 'token_type_ids': [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]}  # noqa: E501
							# fmt: on

							self.tokenizer_integration_test_util(
							    expected_encoding=a    ,     model_name='albert-base-v2'    ,     revision='6b6560eaf5ff2e250b00c50f380c5389a9c2d82e'    ,     )