


'''simple docstring'''






from manim import *




class  a     (     _SCREAMING_SNAKE_CASE       ):
 def 							__UpperCAmelCase		( self						)					->							Tuple:
      _a			      =							Rectangle(height=0.5      ,				width=0.5						)
      _a			      =							Rectangle(height=0.2_5      ,				width=0.2_5						)
      _a			      =							Rectangle(height=0.4_6      ,				width=0.4_6						).set_stroke(width=0						)

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

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

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

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

      _a			      =							[]
      _a			      =							[]
      _a			      =							[]

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

           _a			      =							Rectangle(height=0.4_6 / 4      ,				width=0.4_6 / 3						).set_stroke(width=0.0						).set_fill(__magic_name__      ,				opacity=0.7						)

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

      self.add(*__magic_name__      ,				*__magic_name__      ,				*__magic_name__						)

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

      _a			      =							Text('Loaded Checkpoint'      ,				font_size=24						)
      _a			      =							Group(__magic_name__      ,				__magic_name__						).arrange(__magic_name__      ,				buff=0.5      ,				aligned_edge=__magic_name__						)
      checkpoint.move_to([3, 0.5, 0]						)

      self.add(__magic_name__						)

      _a			      =							[]
      _a			      =							[]

      for i, rect in enumerate(__magic_name__						):
           _a			      =							fill.copy().set_fill(__magic_name__      ,				opacity=0.7						)
           target.move_to(__magic_name__						)
           ckpt_arr.append(__magic_name__						)

           _a			      =							target.copy()
           if i < 5:
                cpu_target.move_to(cpu_left_col_base[i + 1]						)
           else:
                cpu_target.move_to(cpu_right_col_base[i - 5]						)
           ckpt_cpu_arr.append(__magic_name__						)
      self.add(*__magic_name__      ,				*__magic_name__						)

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

      _a			      =							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(__magic_name__      ,				__magic_name__						)

      _a			      =							MarkupText(
          f'<span fgcolor=\'{BLUE}\'>●</span> Checkpoint'      ,				font_size=18      ,				)

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

      _a			      =							MarkupText(
          f'Based on the passed in configuration, weights are stored in\na variety of np.memmaps on disk or to a particular device.'      ,				font_size=24      ,				)
      step_a.move_to([2, 2, 0]						)

      _a			      =							[meta_mem.copy() for i in range(6						)]
      _a			      =							[meta_mem.copy() for i in range(6						)]
      _a			      =							VGroup(*__magic_name__						).arrange(__magic_name__      ,				buff=0						)
      _a			      =							VGroup(*__magic_name__						).arrange(__magic_name__      ,				buff=0						)
      _a			      =							VGroup(__magic_name__      ,				__magic_name__						).arrange(__magic_name__      ,				buff=0						)
      _a			      =							Text('Disk'      ,				font_size=24						)
      _a			      =							Group(__magic_name__      ,				__magic_name__						).arrange(__magic_name__      ,				buff=0.5      ,				aligned_edge=__magic_name__						)
      disk.move_to([-4.0, -1.2_5, 0]						)
      self.play(Write(__magic_name__      ,				run_time=3						)      ,				Write(__magic_name__      ,				run_time=1						)      ,				Create(__magic_name__      ,				run_time=1						)						)

      _a			      =							[]
      for i, rect in enumerate(__magic_name__						):
           _a			      =							rect.copy()
           target.generate_target()
           target.target.move_to(disk_left_col_base[i]						).scale(0.5						)
           animations.append(MoveToTarget(__magic_name__      ,				run_time=1.5						)						)
      self.play(*__magic_name__						)

      self.play(FadeOut(__magic_name__						)						)

      _a			      =							MarkupText(f'Then, the checkpoint is removed from memory\nthrough garbage collection.'      ,				font_size=24						)
      step_a.move_to([2, 2, 0]						)

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

      self.play(
          FadeOut(__magic_name__      ,				__magic_name__      ,				*__magic_name__      ,				*__magic_name__						)      ,				)

      self.wait()





'''simple docstring'''






# Copyright 2023 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

import torch

from ..models.auto import AutoModelForVisualQuestionAnswering, AutoProcessor
from ..utils import requires_backends
from .base import PipelineTool


if TYPE_CHECKING:
 from PIL import Image




class  a     (     _SCREAMING_SNAKE_CASE       ):
 _lowerCAmelCase 					=	"""dandelin/vilt-b32-finetuned-vqa"""
 _lowerCAmelCase 					=	(
     """This is a tool that answers a question about an image. It takes an input named `image` which should be the """
     """image containing the information, as well as a `question` which should be the question in English. It """
     """returns a text that is the answer to the question."""
 )
 _lowerCAmelCase 					=	"""image_qa"""
 _lowerCAmelCase 					=	AutoProcessor
 _lowerCAmelCase 					=	AutoModelForVisualQuestionAnswering

 _lowerCAmelCase 					=	["""image""", """text"""]
 _lowerCAmelCase 					=	["""text"""]
 def __init__( self      ,				*__magic_name__      ,				**__magic_name__						)					->							Tuple:
      requires_backends(self      ,				['vision']						)
      super().__init__(*__magic_name__      ,				**__magic_name__						)
 def 							__UpperCAmelCase		( self      ,				__magic_name__      ,				__magic_name__						)					->							Tuple:
      return self.pre_processor(__magic_name__      ,				__magic_name__      ,				return_tensors='pt'						)
 def 							__UpperCAmelCase		( self      ,				__magic_name__						)					->							Any:
      with torch.no_grad():
           return self.model(**__magic_name__						).logits




 def 							__UpperCAmelCase		( self      ,				__magic_name__						)					->							Optional[int]:
      _a			      =							outputs.argmax(-1						).item()
      return self.model.config.idalabel[idx]

