





'''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 ..models.auto import AutoModelForSeqaSeqLM, AutoTokenizer
from .base import PipelineTool
class 			_lowerCAmelCase		(			A__	):






     """simple docstring"""






     snake_case_						      =   "philschmid/bart-large-cnn-samsum"
     snake_case_						      =   (
         "This is a tool that summarizes an English text. It takes an input `text` containing the text to summarize, "
         "and returns a summary of the text."
     )
     snake_case_						      =   "summarizer"
     snake_case_						      =   AutoTokenizer
     snake_case_						      =   AutoModelForSeqaSeqLM

     snake_case_						      =   ["text"]
     snake_case_						      =   ["text"]



     def      lowerCAmelCase			(   self							:			Union[str, Any]   ,       __snake_case							:			List[Any]						)->	Union[str, Any]:
        return self.pre_processor(__snake_case   ,       return_tensors="""pt"""   ,       truncation=__snake_case						)



     def      lowerCAmelCase			(   self							:			int   ,       __snake_case							:			Tuple						)->	List[str]:
        return self.model.generate(**__snake_case						)[0]



     def      lowerCAmelCase			(   self							:			int   ,       __snake_case							:			List[Any]						)->	Dict:
        return self.pre_processor.decode(__snake_case   ,       skip_special_tokens=__snake_case   ,       clean_up_tokenization_spaces=__snake_case						)








'''simple docstring'''




from manim import *
class 			_lowerCAmelCase		(			A__	):






     """simple docstring"""






     def      lowerCAmelCase			(   self							:			Optional[Any]						)->	Union[str, Any]:
        snake_case 						=   Rectangle(height=0.5   ,       width=0.5						)
        snake_case 						=   Rectangle(height=0.25   ,       width=0.25						)
        snake_case 						=   Rectangle(height=0.46   ,       width=0.46						).set_stroke(width=0						)

        snake_case 						=   [mem.copy() for i in range(6						)]
        snake_case 						=   [mem.copy() for i in range(6						)]
        snake_case 						=   VGroup(*__snake_case						).arrange(__snake_case   ,       buff=0						)
        snake_case 						=   VGroup(*__snake_case						).arrange(__snake_case   ,       buff=0						)
        snake_case 						=   VGroup(__snake_case   ,       __snake_case						).arrange(__snake_case   ,       buff=0						)
        snake_case 						=   Text("""CPU"""   ,       font_size=24						)
        snake_case 						=   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						)

        snake_case 						=   [mem.copy() for i in range(4						)]
        snake_case 						=   VGroup(*__snake_case						).arrange(__snake_case   ,       buff=0						)
        snake_case 						=   Text("""GPU"""   ,       font_size=24						)
        snake_case 						=   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						)

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

        snake_case 						=   Text("""Model"""   ,       font_size=24						)
        snake_case 						=   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						)

        snake_case 						=   []
        snake_case 						=   []
        snake_case 						=   []

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

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

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

        self.add(*__snake_case   ,       *__snake_case   ,       *__snake_case						)

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

        snake_case 						=   Text("""Loaded Checkpoint"""   ,       font_size=24						)
        snake_case 						=   Group(__snake_case   ,       __snake_case						).arrange(__snake_case   ,       buff=0.5   ,       aligned_edge=__snake_case						)
        checkpoint.move_to([3, 0.5, 0]						)

        self.add(__snake_case						)

        snake_case 						=   []
        snake_case 						=   []

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

           snake_case 						=   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(__snake_case						)
        self.add(*__snake_case   ,       *__snake_case						)

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

        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(__snake_case   ,       __snake_case						)

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

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

        snake_case 						=   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]						)

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

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

        self.play(FadeOut(__snake_case						)						)

        snake_case 						=   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(__snake_case   ,       run_time=3						)						)

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

        self.wait()

