from manim import *


class 						lowercase    (     a     ):




							def 	__snake_case(						self   :					int      )					->				str:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE    			=       Rectangle(height=0.5	,							width=0.5      )
												SCREAMING_SNAKE_CASE    			=       Rectangle(height=0.4_6	,							width=0.4_6      ).set_stroke(width=0      )

												SCREAMING_SNAKE_CASE    			=       Rectangle(height=0.2_5	,							width=0.2_5      )

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

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

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

												SCREAMING_SNAKE_CASE    			=       Text("Model"	,							font_size=24      )
												SCREAMING_SNAKE_CASE    			=       Group(_UpperCamelCase	,							_UpperCamelCase      ).arrange(_UpperCamelCase	,							buff=0.5	,							aligned_edge=_UpperCamelCase      )
												model.move_to([3, -1.0, 0]      )
												self.add(_UpperCamelCase      )

												SCREAMING_SNAKE_CASE    			=       []
												SCREAMING_SNAKE_CASE    			=       []

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

																	SCREAMING_SNAKE_CASE    			=       Rectangle(height=0.4_6	,							width=0.4_6      ).set_stroke(width=0.0      ).set_fill(_UpperCamelCase	,							opacity=0.8      )
																	cpu_target.move_to(cpu_left_col_base[i]      )
																	model_cpu_arr.append(_UpperCamelCase      )

												self.add(*_UpperCamelCase	,							*_UpperCamelCase      )

												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(*_UpperCamelCase      ).arrange(_UpperCamelCase	,							buff=0      )
												SCREAMING_SNAKE_CASE    			=       VGroup(*_UpperCamelCase      ).arrange(_UpperCamelCase	,							buff=0      )
												SCREAMING_SNAKE_CASE    			=       VGroup(_UpperCamelCase	,							_UpperCamelCase      ).arrange(_UpperCamelCase	,							buff=0      )
												SCREAMING_SNAKE_CASE    			=       Text("Disk"	,							font_size=24      )
												SCREAMING_SNAKE_CASE    			=       Group(_UpperCamelCase	,							_UpperCamelCase      ).arrange(_UpperCamelCase	,							buff=0.5	,							aligned_edge=_UpperCamelCase      )
												disk.move_to([-4, -1.2_5, 0]      )
												self.add(_UpperCamelCase	,							_UpperCamelCase      )

												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=18	,							)

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

												self.add(_UpperCamelCase	,							_UpperCamelCase      )

												SCREAMING_SNAKE_CASE    			=       MarkupText(
												    F"<span fgcolor='{BLUE}'>●</span> Checkpoint"	,							font_size=18	,							)

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

												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=24	,							)
												step_a.move_to([2, 2, 0]      )

												self.play(Write(_UpperCamelCase      )      )

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

												self.play(Write(_UpperCamelCase      )      )

												input.generate_target()
												input.target.next_to(model_arr[0]	,							direction=_UpperCamelCase	,							buff=0.0_2      )
												self.play(MoveToTarget(_UpperCamelCase      )      )

												self.play(FadeOut(_UpperCamelCase      )      )

												SCREAMING_SNAKE_CASE    			=       Arrow(start=_UpperCamelCase	,							end=_UpperCamelCase	,							color=_UpperCamelCase	,							buff=0.5      )
												a.next_to(model_arr[0].get_left()	,							_UpperCamelCase	,							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=24	,							)
												step_a.move_to([2, 2, 0]      )

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

												SCREAMING_SNAKE_CASE    			=       {"run_time": 1, "fade_in": True, "fade_out": True, "buff": 0.0_2}

												self.play(
												    Write(_UpperCamelCase      )	,							Circumscribe(model_arr[0]	,							color=_UpperCamelCase	,							**_UpperCamelCase      )	,							Circumscribe(model_cpu_arr[0]	,							color=_UpperCamelCase	,							**_UpperCamelCase      )	,							Circumscribe(gpu_rect[0]	,							color=_UpperCamelCase	,							**_UpperCamelCase      )	,							)
												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.0_2	,							_UpperCamelCase	,							buff=0.2      )

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

																	SCREAMING_SNAKE_CASE    			=       AnimationGroup(
																	    FadeOut(_UpperCamelCase	,							run_time=0.5      )	,							MoveToTarget(_UpperCamelCase	,							run_time=0.5      )	,							FadeIn(_UpperCamelCase	,							run_time=0.5      )	,							lag_ratio=0.2      )

																	self.play(_UpperCamelCase      )

																	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]	,							**_UpperCamelCase      )	,							Circumscribe(cpu_left_col_base[i]	,							**_UpperCamelCase      )	,							Circumscribe(cpu_left_col_base[i + 1]	,							color=_UpperCamelCase	,							**_UpperCamelCase      )	,							Circumscribe(gpu_rect[0]	,							color=_UpperCamelCase	,							**_UpperCamelCase      )	,							Circumscribe(model_arr[i + 1]	,							color=_UpperCamelCase	,							**_UpperCamelCase      )	,							)
																						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.0_2	,							buff=0.2      )

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

																						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.0_2	,							buff=0.5      )
												self.play(
												    FadeOut(_UpperCamelCase      )	,							FadeOut(_UpperCamelCase	,							run_time=0.5      )	,							)

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

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

												self.wait()





import unittest

import numpy as np

from transformers.file_utils import is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_vision

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
							import torch

if is_vision_available():
							from PIL import Image

							from transformers import DPTImageProcessor


class 						lowercase    (     unittest.TestCase     ):




							def __init__(						self   :					Union[str, Any]	,							_UpperCamelCase   :					Tuple	,							_UpperCamelCase   :					List[Any]=7	,							_UpperCamelCase   :					Any=3	,							_UpperCamelCase   :					str=18	,							_UpperCamelCase   :					Tuple=30	,							_UpperCamelCase   :					Optional[int]=400	,							_UpperCamelCase   :					Optional[int]=True	,							_UpperCamelCase   :					Optional[Any]=None	,							_UpperCamelCase   :					int=True	,							_UpperCamelCase   :					Optional[int]=[0.5, 0.5, 0.5]	,							_UpperCamelCase   :					List[str]=[0.5, 0.5, 0.5]	,							)					->				str:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE    			=       size if size is not None else {"height": 18, "width": 18}
												SCREAMING_SNAKE_CASE    			=       parent
												SCREAMING_SNAKE_CASE    			=       batch_size
												SCREAMING_SNAKE_CASE    			=       num_channels
												SCREAMING_SNAKE_CASE    			=       image_size
												SCREAMING_SNAKE_CASE    			=       min_resolution
												SCREAMING_SNAKE_CASE    			=       max_resolution
												SCREAMING_SNAKE_CASE    			=       do_resize
												SCREAMING_SNAKE_CASE    			=       size
												SCREAMING_SNAKE_CASE    			=       do_normalize
												SCREAMING_SNAKE_CASE    			=       image_mean
												SCREAMING_SNAKE_CASE    			=       image_std





							def 	__snake_case(						self   :					List[Any]      )					->				Any:



												'''simple docstring'''

												return {
												    "image_mean": self.image_mean,
												    "image_std": self.image_std,
												    "do_normalize": self.do_normalize,
												    "do_resize": self.do_resize,
												    "size": self.size,
												}



@require_torch
@require_vision
class 						lowercase    (     a				,       unittest.TestCase     ):
							lowercase__						:       Any								=							DPTImageProcessor if is_vision_available() else None




							def 	__snake_case(						self   :					List[str]      )					->				Any:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE    			=       DPTImageProcessingTester(self      )




							@property
							def 	__snake_case(						self   :					List[Any]      )					->				List[str]:



												'''simple docstring'''

												return self.image_processor_tester.prepare_image_processor_dict()




							def 	__snake_case(						self   :					str      )					->				Optional[int]:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE    			=       self.image_processing_class(**self.image_processor_dict      )
												self.assertTrue(hasattr(_UpperCamelCase	,							"image_mean"      )      )
												self.assertTrue(hasattr(_UpperCamelCase	,							"image_std"      )      )
												self.assertTrue(hasattr(_UpperCamelCase	,							"do_normalize"      )      )
												self.assertTrue(hasattr(_UpperCamelCase	,							"do_resize"      )      )
												self.assertTrue(hasattr(_UpperCamelCase	,							"size"      )      )




							def 	__snake_case(						self   :					Dict      )					->				Dict:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE    			=       self.image_processing_class.from_dict(self.image_processor_dict      )
												self.assertEqual(image_processor.size	,							{"height": 18, "width": 18}      )

												SCREAMING_SNAKE_CASE    			=       self.image_processing_class.from_dict(self.image_processor_dict	,							size=42      )
												self.assertEqual(image_processor.size	,							{"height": 42, "width": 42}      )




							def 	__snake_case(						self   :					Union[str, Any]      )					->				Tuple:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE    			=       self.image_processing_class(**self.image_processor_dict      )
												# create random PIL images
												SCREAMING_SNAKE_CASE    			=       prepare_image_inputs(self.image_processor_tester	,							equal_resolution=_UpperCamelCase      )
												for image in image_inputs:
																	self.assertIsInstance(_UpperCamelCase	,							Image.Image      )

												# Test not batched input
												SCREAMING_SNAKE_CASE    			=       image_processing(image_inputs[0]	,							return_tensors="pt"      ).pixel_values
												self.assertEqual(
												    encoded_images.shape	,							(
												        1,
												        self.image_processor_tester.num_channels,
												        self.image_processor_tester.size["height"],
												        self.image_processor_tester.size["width"],
												    )	,							)

												# Test batched
												SCREAMING_SNAKE_CASE    			=       image_processing(_UpperCamelCase	,							return_tensors="pt"      ).pixel_values
												self.assertEqual(
												    encoded_images.shape	,							(
												        self.image_processor_tester.batch_size,
												        self.image_processor_tester.num_channels,
												        self.image_processor_tester.size["height"],
												        self.image_processor_tester.size["width"],
												    )	,							)




							def 	__snake_case(						self   :					Optional[Any]      )					->				Optional[Any]:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE    			=       self.image_processing_class(**self.image_processor_dict      )
												# create random numpy tensors
												SCREAMING_SNAKE_CASE    			=       prepare_image_inputs(self.image_processor_tester	,							equal_resolution=_UpperCamelCase	,							numpify=_UpperCamelCase      )
												for image in image_inputs:
																	self.assertIsInstance(_UpperCamelCase	,							np.ndarray      )

												# Test not batched input
												SCREAMING_SNAKE_CASE    			=       image_processing(image_inputs[0]	,							return_tensors="pt"      ).pixel_values
												self.assertEqual(
												    encoded_images.shape	,							(
												        1,
												        self.image_processor_tester.num_channels,
												        self.image_processor_tester.size["height"],
												        self.image_processor_tester.size["width"],
												    )	,							)

												# Test batched
												SCREAMING_SNAKE_CASE    			=       image_processing(_UpperCamelCase	,							return_tensors="pt"      ).pixel_values
												self.assertEqual(
												    encoded_images.shape	,							(
												        self.image_processor_tester.batch_size,
												        self.image_processor_tester.num_channels,
												        self.image_processor_tester.size["height"],
												        self.image_processor_tester.size["width"],
												    )	,							)





							def 	__snake_case(						self   :					Optional[Any]      )					->				str:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE    			=       self.image_processing_class(**self.image_processor_dict      )
												# create random PyTorch tensors
												SCREAMING_SNAKE_CASE    			=       prepare_image_inputs(self.image_processor_tester	,							equal_resolution=_UpperCamelCase	,							torchify=_UpperCamelCase      )
												for image in image_inputs:
																	self.assertIsInstance(_UpperCamelCase	,							torch.Tensor      )

												# Test not batched input
												SCREAMING_SNAKE_CASE    			=       image_processing(image_inputs[0]	,							return_tensors="pt"      ).pixel_values
												self.assertEqual(
												    encoded_images.shape	,							(
												        1,
												        self.image_processor_tester.num_channels,
												        self.image_processor_tester.size["height"],
												        self.image_processor_tester.size["width"],
												    )	,							)

												# Test batched
												SCREAMING_SNAKE_CASE    			=       image_processing(_UpperCamelCase	,							return_tensors="pt"      ).pixel_values
												self.assertEqual(
												    encoded_images.shape	,							(
												        self.image_processor_tester.batch_size,
												        self.image_processor_tester.num_channels,
												        self.image_processor_tester.size["height"],
												        self.image_processor_tester.size["width"],
												    )	,							)




