






'''simple docstring'''






from manim import *






class  __magic_name__							(		lowerCamelCase_    ):






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




          '''simple docstring'''
          _UpperCAmelCase       :       Optional[Any]							   =Rectangle(height=0.5  ,							width=0.5)
          _UpperCAmelCase       :       List[Any]							   =Rectangle(height=0.46  ,							width=0.46).set_stroke(width=0)

          _UpperCAmelCase       :       str							   =Rectangle(height=0.25  ,							width=0.25)

          _UpperCAmelCase       :       Optional[int]							   =[mem.copy() for i in range(6)]
          _UpperCAmelCase       :       Dict							   =[mem.copy() for i in range(6)]
          _UpperCAmelCase       :       Any							   =VGroup(*__snake_case).arrange(__snake_case  ,							buff=0)
          _UpperCAmelCase       :       List[str]							   =VGroup(*__snake_case).arrange(__snake_case  ,							buff=0)
          _UpperCAmelCase       :       str							   =VGroup(__snake_case  ,							__snake_case).arrange(__snake_case  ,							buff=0)
          _UpperCAmelCase       :       List[str]							   =Text('CPU'  ,							font_size=2_4)
          _UpperCAmelCase       :       Dict							   =Group(__snake_case  ,							__snake_case).arrange(__snake_case  ,							buff=0.5  ,							aligned_edge=__snake_case)
          cpu.move_to([-2.5, -0.5, 0])
          self.add(__snake_case)

          _UpperCAmelCase       :       List[Any]							   =[mem.copy() for i in range(4)]
          _UpperCAmelCase       :       Any							   =VGroup(*__snake_case).arrange(__snake_case  ,							buff=0)
          _UpperCAmelCase       :       str							   =Text('GPU'  ,							font_size=2_4)
          _UpperCAmelCase       :       Union[str, Any]							   =Group(__snake_case  ,							__snake_case).arrange(__snake_case  ,							buff=0.5  ,							aligned_edge=__snake_case)
          gpu.move_to([-1, -1, 0])
          self.add(__snake_case)

          _UpperCAmelCase       :       Union[str, Any]							   =[mem.copy() for i in range(6)]
          _UpperCAmelCase       :       Any							   =VGroup(*__snake_case).arrange(__snake_case  ,							buff=0)

          _UpperCAmelCase       :       Optional[int]							   =Text('Model'  ,							font_size=2_4)
          _UpperCAmelCase       :       int							   =Group(__snake_case  ,							__snake_case).arrange(__snake_case  ,							buff=0.5  ,							aligned_edge=__snake_case)
          model.move_to([3, -1.0, 0])
          self.add(__snake_case)

          _UpperCAmelCase       :       Any							   =[]
          _UpperCAmelCase       :       Any							   =[]

          for i, rect in enumerate(__snake_case):
             _UpperCAmelCase       :       List[str]							   =fill.copy().set_fill(__snake_case  ,							opacity=0.8)
             target.move_to(__snake_case)
             model_arr.append(__snake_case)

             _UpperCAmelCase       :       List[Any]							   =Rectangle(height=0.46  ,							width=0.46).set_stroke(width=0.0).set_fill(__snake_case  ,							opacity=0.8)
             cpu_target.move_to(cpu_left_col_base[i])
             model_cpu_arr.append(__snake_case)

          self.add(*__snake_case  ,							*__snake_case)

          _UpperCAmelCase       :       str							   =[meta_mem.copy() for i in range(6)]
          _UpperCAmelCase       :       Dict							   =[meta_mem.copy() for i in range(6)]
          _UpperCAmelCase       :       Optional[Any]							   =VGroup(*__snake_case).arrange(__snake_case  ,							buff=0)
          _UpperCAmelCase       :       Union[str, Any]							   =VGroup(*__snake_case).arrange(__snake_case  ,							buff=0)
          _UpperCAmelCase       :       Dict							   =VGroup(__snake_case  ,							__snake_case).arrange(__snake_case  ,							buff=0)
          _UpperCAmelCase       :       List[Any]							   =Text('Disk'  ,							font_size=2_4)
          _UpperCAmelCase       :       Optional[int]							   =Group(__snake_case  ,							__snake_case).arrange(__snake_case  ,							buff=0.5  ,							aligned_edge=__snake_case)
          disk.move_to([-4, -1.25, 0])
          self.add(__snake_case  ,							__snake_case)

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

          _UpperCAmelCase       :       Tuple							   =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(__snake_case  ,							__snake_case)

          _UpperCAmelCase       :       Optional[int]							   =MarkupText(
              f"<span fgcolor=\'{BLUE}\'>●</span> Checkpoint"  ,							font_size=1_8  ,							)

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

          _UpperCAmelCase       :       List[str]							   =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(__snake_case))

          _UpperCAmelCase       :       List[Any]							   =Square(0.3)
          input.set_fill(__snake_case  ,							opacity=1.0)
          input.set_stroke(width=0.0)
          input.next_to(model_base[0]  ,							__snake_case  ,							buff=0.5)

          self.play(Write(__snake_case))

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

          self.play(FadeOut(__snake_case))

          _UpperCAmelCase       :       int							   =Arrow(start=__snake_case  ,							end=__snake_case  ,							color=__snake_case  ,							buff=0.5)
          a.next_to(model_arr[0].get_left()  ,							__snake_case  ,							buff=0.2)

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

          _UpperCAmelCase       :       Any							   =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(__snake_case  ,							run_time=3))

          _UpperCAmelCase       :       str							   ={'run_time': 1, 'fade_in': True, 'fade_out': True, 'buff': 0.02}

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

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

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

             _UpperCAmelCase       :       int							   =AnimationGroup(
                 FadeOut(__snake_case  ,							run_time=0.5)  ,							MoveToTarget(__snake_case  ,							run_time=0.5)  ,							FadeIn(__snake_case  ,							run_time=0.5)  ,							lag_ratio=0.2)

             self.play(__snake_case)

             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:
                   _UpperCAmelCase       :       Tuple							   =0.7

                self.play(
                    Circumscribe(model_arr[i]  ,							**__snake_case)  ,							Circumscribe(cpu_left_col_base[i]  ,							**__snake_case)  ,							Circumscribe(cpu_left_col_base[i + 1]  ,							color=__snake_case  ,							**__snake_case)  ,							Circumscribe(gpu_rect[0]  ,							color=__snake_case  ,							**__snake_case)  ,							Circumscribe(model_arr[i + 1]  ,							color=__snake_case  ,							**__snake_case)  ,							)
                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=__snake_case  ,							**__snake_case)  ,							Circumscribe(cpu_left_col_base[-1]  ,							color=__snake_case  ,							**__snake_case)  ,							Circumscribe(gpu_rect[0]  ,							color=__snake_case  ,							**__snake_case)  ,							)

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

             _UpperCAmelCase       :       Optional[Any]							   =a_c
             _UpperCAmelCase       :       int							   =a_c.copy()

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

          _UpperCAmelCase       :       str							   =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(__snake_case  ,							run_time=3)  ,							MoveToTarget(__snake_case))

          self.wait()





'''simple docstring'''






import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers import is_speech_available, is_vision_available
from transformers.testing_utils import require_torch


if is_vision_available():
 from transformers import TvltImageProcessor

if is_speech_available():
 from transformers import TvltFeatureExtractor

from transformers import TvltProcessor






@require_torch
class  __magic_name__							(		unittest.TestCase    ):






       def       lowerCAmelCase		(      self)						->  str:




          '''simple docstring'''
          _UpperCAmelCase       :       Dict							   ='ZinengTang/tvlt-base'
          _UpperCAmelCase       :       Dict							   =tempfile.mkdtemp()






       def       lowerCAmelCase		(      self  ,							**snake_case)						->  Union[str, Any]:




          '''simple docstring'''
          return TvltImageProcessor.from_pretrained(self.checkpoint  ,							**snake_case)






       def       lowerCAmelCase		(      self  ,							**snake_case)						->  Dict:




          '''simple docstring'''
          return TvltFeatureExtractor.from_pretrained(self.checkpoint  ,							**snake_case)






       def       lowerCAmelCase		(      self)						->  Any:




          '''simple docstring'''
          shutil.rmtree(self.tmpdirname)






       def       lowerCAmelCase		(      self)						->  Optional[int]:




          '''simple docstring'''
          _UpperCAmelCase       :       Any							   =self.get_image_processor()
          _UpperCAmelCase       :       Optional[Any]							   =self.get_feature_extractor()

          _UpperCAmelCase       :       str							   =TvltProcessor(image_processor=snake_case  ,							feature_extractor=snake_case)
          processor.save_pretrained(self.tmpdirname)
          _UpperCAmelCase       :       str							   =TvltProcessor.from_pretrained(self.tmpdirname)

          self.assertIsInstance(processor.feature_extractor  ,							snake_case)
          self.assertIsInstance(processor.image_processor  ,							snake_case)






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




          '''simple docstring'''
          _UpperCAmelCase       :       str							   =self.get_image_processor()
          _UpperCAmelCase       :       List[Any]							   =self.get_feature_extractor()

          _UpperCAmelCase       :       str							   =TvltProcessor(image_processor=snake_case  ,							feature_extractor=snake_case)

          _UpperCAmelCase       :       Optional[int]							   =np.ones([1_2_0_0_0])

          _UpperCAmelCase       :       str							   =feature_extractor(snake_case  ,							return_tensors='np')
          _UpperCAmelCase       :       Dict							   =processor(audio=snake_case  ,							return_tensors='np')

          for key in audio_dict.keys():
             self.assertAlmostEqual(audio_dict[key].sum()  ,							input_processor[key].sum()  ,							delta=1E-2)






       def       lowerCAmelCase		(      self)						->  int:




          '''simple docstring'''
          _UpperCAmelCase       :       Dict							   =self.get_image_processor()
          _UpperCAmelCase       :       int							   =self.get_feature_extractor()

          _UpperCAmelCase       :       int							   =TvltProcessor(image_processor=snake_case  ,							feature_extractor=snake_case)

          _UpperCAmelCase       :       Union[str, Any]							   =np.ones([3, 2_2_4, 2_2_4])

          _UpperCAmelCase       :       Optional[Any]							   =image_processor(snake_case  ,							return_tensors='np')
          _UpperCAmelCase       :       List[Any]							   =processor(images=snake_case  ,							return_tensors='np')

          for key in image_dict.keys():
             self.assertAlmostEqual(image_dict[key].sum()  ,							input_processor[key].sum()  ,							delta=1E-2)






       def       lowerCAmelCase		(      self)						->  List[str]:




          '''simple docstring'''
          _UpperCAmelCase       :       List[str]							   =self.get_image_processor()
          _UpperCAmelCase       :       Dict							   =self.get_feature_extractor()

          _UpperCAmelCase       :       Optional[int]							   =TvltProcessor(image_processor=snake_case  ,							feature_extractor=snake_case)

          _UpperCAmelCase       :       Optional[int]							   =np.ones([1_2_0_0_0])
          _UpperCAmelCase       :       str							   =np.ones([3, 2_2_4, 2_2_4])

          _UpperCAmelCase       :       Optional[int]							   =processor(audio=snake_case  ,							images=snake_case)

          self.assertListEqual(list(inputs.keys())  ,							['audio_values', 'audio_mask', 'pixel_values', 'pixel_mask'])

          # test if it raises when no input is passed
          with pytest.raises(snake_case):
             processor()






       def       lowerCAmelCase		(      self)						->  Optional[int]:




          '''simple docstring'''
          _UpperCAmelCase       :       Optional[int]							   =self.get_image_processor()
          _UpperCAmelCase       :       Tuple							   =self.get_feature_extractor()

          _UpperCAmelCase       :       Dict							   =TvltProcessor(image_processor=snake_case  ,							feature_extractor=snake_case)

          self.assertListEqual(
              processor.model_input_names  ,							image_processor.model_input_names + feature_extractor.model_input_names  ,							msg='`processor` and `image_processor`+`feature_extractor` model input names do not match'  ,							)

