




'''simple docstring'''





import copy
from collections import OrderedDict
from typing import Dict, Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging
from ..auto import CONFIG_MAPPING


UpperCamelCase_						:      Any       =						logging.get_logger(__name__)

UpperCamelCase_						:      List[str]       =						{
    '''facebook/detr-resnet-50''': '''https://huggingface.co/facebook/detr-resnet-50/resolve/main/config.json''',
    # See all DETR models at https://huggingface.co/models?filter=detr
}

class        _a    (						__lowerCAmelCase							):
     SCREAMING_SNAKE_CASE_							:   List[Any]       =						"""detr"""
     SCREAMING_SNAKE_CASE_							:   Union[str, Any]       =						["""past_key_values"""]
     SCREAMING_SNAKE_CASE_							:   int       =						{
         """hidden_size""": """d_model""",
         """num_attention_heads""": """encoder_attention_heads""",
     }






     def __init__(			self ,_SCREAMING_SNAKE_CASE=True ,_SCREAMING_SNAKE_CASE=None ,_SCREAMING_SNAKE_CASE=3 ,_SCREAMING_SNAKE_CASE=100 ,_SCREAMING_SNAKE_CASE=6 ,_SCREAMING_SNAKE_CASE=2_048 ,_SCREAMING_SNAKE_CASE=8 ,_SCREAMING_SNAKE_CASE=6 ,_SCREAMING_SNAKE_CASE=2_048 ,_SCREAMING_SNAKE_CASE=8 ,_SCREAMING_SNAKE_CASE=0.0 ,_SCREAMING_SNAKE_CASE=0.0 ,_SCREAMING_SNAKE_CASE=True ,_SCREAMING_SNAKE_CASE="relu" ,_SCREAMING_SNAKE_CASE=256 ,_SCREAMING_SNAKE_CASE=0.1 ,_SCREAMING_SNAKE_CASE=0.0 ,_SCREAMING_SNAKE_CASE=0.0 ,_SCREAMING_SNAKE_CASE=0.0_2 ,_SCREAMING_SNAKE_CASE=1.0 ,_SCREAMING_SNAKE_CASE=False ,_SCREAMING_SNAKE_CASE="sine" ,_SCREAMING_SNAKE_CASE="resnet50" ,_SCREAMING_SNAKE_CASE=True ,_SCREAMING_SNAKE_CASE=False ,_SCREAMING_SNAKE_CASE=1 ,_SCREAMING_SNAKE_CASE=5 ,_SCREAMING_SNAKE_CASE=2 ,_SCREAMING_SNAKE_CASE=1 ,_SCREAMING_SNAKE_CASE=1 ,_SCREAMING_SNAKE_CASE=5 ,_SCREAMING_SNAKE_CASE=2 ,_SCREAMING_SNAKE_CASE=0.1 ,**_SCREAMING_SNAKE_CASE ,)							->      Optional[Any]:
          if backbone_config is not None and use_timm_backbone:
               raise ValueError("You can't specify both `backbone_config` and `use_timm_backbone`."   )

          if not use_timm_backbone:
               if backbone_config is None:
                    logger.info("`backbone_config` is `None`. Initializing the config with the default `ResNet` backbone."   )
                    _snake_case							=				CONFIG_MAPPING["resnet"](out_features=["stage4"]   )
               elif isinstance(_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE   ):
                    _snake_case							=				backbone_config.get("model_type"   )
                    _snake_case							=				CONFIG_MAPPING[backbone_model_type]
                    _snake_case							=				config_class.from_dict(_SCREAMING_SNAKE_CASE   )
               # set timm attributes to None
               _snake_case							, _snake_case							, _snake_case							=				None, None, None

          _snake_case							=				use_timm_backbone
          _snake_case							=				backbone_config
          _snake_case							=				num_channels
          _snake_case							=				num_queries
          _snake_case							=				d_model
          _snake_case							=				encoder_ffn_dim
          _snake_case							=				encoder_layers
          _snake_case							=				encoder_attention_heads
          _snake_case							=				decoder_ffn_dim
          _snake_case							=				decoder_layers
          _snake_case							=				decoder_attention_heads
          _snake_case							=				dropout
          _snake_case							=				attention_dropout
          _snake_case							=				activation_dropout
          _snake_case							=				activation_function
          _snake_case							=				init_std
          _snake_case							=				init_xavier_std
          _snake_case							=				encoder_layerdrop
          _snake_case							=				decoder_layerdrop
          _snake_case							=				encoder_layers
          _snake_case							=				auxiliary_loss
          _snake_case							=				position_embedding_type
          _snake_case							=				backbone
          _snake_case							=				use_pretrained_backbone
          _snake_case							=				dilation
          # Hungarian matcher
          _snake_case							=				class_cost
          _snake_case							=				bbox_cost
          _snake_case							=				giou_cost
          # Loss coefficients
          _snake_case							=				mask_loss_coefficient
          _snake_case							=				dice_loss_coefficient
          _snake_case							=				bbox_loss_coefficient
          _snake_case							=				giou_loss_coefficient
          _snake_case							=				eos_coefficient
          super().__init__(is_encoder_decoder=_SCREAMING_SNAKE_CASE ,**_SCREAMING_SNAKE_CASE   )






     @property
     def     _lowercase     (			self   )							->      int:
          return self.encoder_attention_heads






     @property
     def     _lowercase     (			self   )							->      int:
          return self.d_model






     @classmethod
     def     _lowercase     (			cls ,_SCREAMING_SNAKE_CASE ,**_SCREAMING_SNAKE_CASE   )							->      int:
          return cls(backbone_config=_SCREAMING_SNAKE_CASE ,**_SCREAMING_SNAKE_CASE   )






     def     _lowercase     (			self   )							->      Dict[str, any]:
          _snake_case							=				copy.deepcopy(self.__dict__   )
          if output["backbone_config"] is not None:
               _snake_case							=				self.backbone_config.to_dict()
          _snake_case							=				self.__class__.model_type
          return output







class        _a    (						__lowerCAmelCase							):
     SCREAMING_SNAKE_CASE_							:   List[str]       =						version.parse("""1.11"""							)






     @property
     def     _lowercase     (			self   )							->      Mapping[str, Mapping[int, str]]:
          return OrderedDict(
              [
                  ("pixel_values", {0: "batch", 1: "num_channels", 2: "height", 3: "width"}),
                  ("pixel_mask", {0: "batch"}),
              ]   )






     @property
     def     _lowercase     (			self   )							->      float:
          return 1e-5






     @property
     def     _lowercase     (			self   )							->      int:
          return 12








'''simple docstring'''





from manim import *

class        _a    (						__lowerCAmelCase							):






     def     _lowercase     (			self   )							->      Optional[int]:
          _snake_case							=				Rectangle(height=0.5 ,width=0.5   )
          _snake_case							=				Rectangle(height=0.4_6 ,width=0.4_6   ).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(*_SCREAMING_SNAKE_CASE   ).arrange(_SCREAMING_SNAKE_CASE ,buff=0   )
          _snake_case							=				VGroup(*_SCREAMING_SNAKE_CASE   ).arrange(_SCREAMING_SNAKE_CASE ,buff=0   )
          _snake_case							=				VGroup(_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE   ).arrange(_SCREAMING_SNAKE_CASE ,buff=0   )
          _snake_case							=				Text("CPU" ,font_size=24   )
          _snake_case							=				Group(_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE   ).arrange(_SCREAMING_SNAKE_CASE ,buff=0.5 ,aligned_edge=_SCREAMING_SNAKE_CASE   )
          cpu.move_to([-2.5, -0.5, 0]   )
          self.add(_SCREAMING_SNAKE_CASE   )

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

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

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

          _snake_case							=				[]
          for i, rect in enumerate(_SCREAMING_SNAKE_CASE   ):
               rect.set_stroke(_SCREAMING_SNAKE_CASE   )
               # target = fill.copy().set_fill(YELLOW, opacity=0.7)
               # target.move_to(rect)
               # self.add(target)

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

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

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

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

          _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(_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE   )

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

          blue_text.next_to(_SCREAMING_SNAKE_CASE ,DOWN * 2.4 ,aligned_edge=key_text.get_left()   )

          _snake_case							=				MarkupText(
              f"""Next, a <i><span fgcolor=\"{BLUE}\">second</span></i> model is loaded into memory,\nwith the weights of a <span fgcolor=\"{BLUE}\">single shard</span>.""" ,font_size=24 ,)
          step_a.move_to([2, 2, 0]   )
          self.play(Write(_SCREAMING_SNAKE_CASE   ) ,Write(_SCREAMING_SNAKE_CASE   )   )

          self.play(Write(_SCREAMING_SNAKE_CASE ,run_time=1   ) ,Create(_SCREAMING_SNAKE_CASE ,run_time=1   )   )

          _snake_case							=				[]
          _snake_case							=				[]
          for i, rect in enumerate(_SCREAMING_SNAKE_CASE   ):
               _snake_case							=				fill.copy().set_fill(_SCREAMING_SNAKE_CASE ,opacity=0.7   )
               target.move_to(_SCREAMING_SNAKE_CASE   )
               first_animations.append(GrowFromCenter(_SCREAMING_SNAKE_CASE ,run_time=1   )   )

               _snake_case							=				target.copy()
               cpu_target.generate_target()
               if i < 5:
                    cpu_target.target.move_to(cpu_left_col_base[i + 1]   )
               else:
                    cpu_target.target.move_to(cpu_right_col_base[i - 5]   )
               second_animations.append(MoveToTarget(_SCREAMING_SNAKE_CASE ,run_time=1.5   )   )

          self.play(*_SCREAMING_SNAKE_CASE   )
          self.play(*_SCREAMING_SNAKE_CASE   )
          self.wait()


