

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    				=     logging.get_logger(__name__)

__UpperCAmelCase    				=     {
    '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__    ( A ):



 """simple docstring"""







 _lowercase     :					List[Any]      =						'''detr'''
 _lowercase     :					str      =						['''past_key_values''']
 _lowercase     :					str      =						{
     '''hidden_size''': '''d_model''',
     '''num_attention_heads''': '''encoder_attention_heads''',
 }

 def __init__(		self :	int     ,						A_ :	int=True     ,						A_ :	Tuple=None     ,						A_ :	Dict=3     ,						A_ :	List[Any]=1_0_0     ,						A_ :	Optional[int]=6     ,						A_ :	int=2_0_4_8     ,						A_ :	Dict=8     ,						A_ :	Optional[Any]=6     ,						A_ :	Dict=2_0_4_8     ,						A_ :	List[str]=8     ,						A_ :	Any=0.0     ,						A_ :	List[Any]=0.0     ,						A_ :	List[str]=True     ,						A_ :	Union[str, Any]="relu"     ,						A_ :	Union[str, Any]=2_5_6     ,						A_ :	List[Any]=0.1     ,						A_ :	List[str]=0.0     ,						A_ :	List[Any]=0.0     ,						A_ :	List[str]=0.02     ,						A_ :	str=1.0     ,						A_ :	List[Any]=False     ,						A_ :	Dict="sine"     ,						A_ :	Any="resnet50"     ,						A_ :	int=True     ,						A_ :	Tuple=False     ,						A_ :	Union[str, Any]=1     ,						A_ :	Tuple=5     ,						A_ :	List[str]=2     ,						A_ :	List[Any]=1     ,						A_ :	Optional[Any]=1     ,						A_ :	Dict=5     ,						A_ :	str=2     ,						A_ :	Optional[int]=0.1     ,						**A_ :	Optional[int]     ,						):






      '''simple docstring'''




      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."       )
                _lowerCAmelCase   :					Optional[Any]        =    CONFIG_MAPPING["resnet"](out_features=["stage4"]       )
           elif isinstance(A_     ,						A_       ):
                _lowerCAmelCase   :					Any        =    backbone_config.get("model_type"       )
                _lowerCAmelCase   :					Optional[int]        =    CONFIG_MAPPING[backbone_model_type]
                _lowerCAmelCase   :					str        =    config_class.from_dict(A_       )
           # set timm attributes to None
           _lowerCAmelCase      ,			_lowerCAmelCase      ,			_lowerCAmelCase   :					Tuple        =    None, None, None

      _lowerCAmelCase   :					str        =    use_timm_backbone
      _lowerCAmelCase   :					Tuple        =    backbone_config
      _lowerCAmelCase   :					Optional[Any]        =    num_channels
      _lowerCAmelCase   :					Union[str, Any]        =    num_queries
      _lowerCAmelCase   :					List[str]        =    d_model
      _lowerCAmelCase   :					str        =    encoder_ffn_dim
      _lowerCAmelCase   :					Dict        =    encoder_layers
      _lowerCAmelCase   :					Optional[Any]        =    encoder_attention_heads
      _lowerCAmelCase   :					Optional[int]        =    decoder_ffn_dim
      _lowerCAmelCase   :					str        =    decoder_layers
      _lowerCAmelCase   :					Union[str, Any]        =    decoder_attention_heads
      _lowerCAmelCase   :					str        =    dropout
      _lowerCAmelCase   :					Optional[int]        =    attention_dropout
      _lowerCAmelCase   :					Any        =    activation_dropout
      _lowerCAmelCase   :					Optional[Any]        =    activation_function
      _lowerCAmelCase   :					List[str]        =    init_std
      _lowerCAmelCase   :					List[str]        =    init_xavier_std
      _lowerCAmelCase   :					Tuple        =    encoder_layerdrop
      _lowerCAmelCase   :					Dict        =    decoder_layerdrop
      _lowerCAmelCase   :					str        =    encoder_layers
      _lowerCAmelCase   :					Dict        =    auxiliary_loss
      _lowerCAmelCase   :					int        =    position_embedding_type
      _lowerCAmelCase   :					Optional[int]        =    backbone
      _lowerCAmelCase   :					Union[str, Any]        =    use_pretrained_backbone
      _lowerCAmelCase   :					Optional[Any]        =    dilation
      # Hungarian matcher
      _lowerCAmelCase   :					Union[str, Any]        =    class_cost
      _lowerCAmelCase   :					Union[str, Any]        =    bbox_cost
      _lowerCAmelCase   :					Optional[Any]        =    giou_cost
      # Loss coefficients
      _lowerCAmelCase   :					Tuple        =    mask_loss_coefficient
      _lowerCAmelCase   :					Any        =    dice_loss_coefficient
      _lowerCAmelCase   :					Any        =    bbox_loss_coefficient
      _lowerCAmelCase   :					List[Any]        =    giou_loss_coefficient
      _lowerCAmelCase   :					Tuple        =    eos_coefficient
      super().__init__(is_encoder_decoder=A_     ,						**A_       )

 @property
 def    __magic_name__       (		self :	Optional[Any]       ):






      '''simple docstring'''




      return self.encoder_attention_heads

 @property
 def    __magic_name__       (		self :	List[Any]       ):






      '''simple docstring'''




      return self.d_model

 @classmethod
 def    __magic_name__       (		cls :	Any     ,						A_ :	PretrainedConfig     ,						**A_ :	List[Any]       ):






      '''simple docstring'''




      return cls(backbone_config=A_     ,						**A_       )


 def    __magic_name__       (		self :	Union[str, Any]       ):






      '''simple docstring'''




      _lowerCAmelCase   :					str        =    copy.deepcopy(self.__dict__       )
      if output["backbone_config"] is not None:
           _lowerCAmelCase   :					Tuple        =    self.backbone_config.to_dict()
      _lowerCAmelCase   :					Any        =    self.__class__.model_type
      return output





class A__    ( A ):



 """simple docstring"""







 _lowercase     :					Tuple      =						version.parse('''1.11''' )

 @property
 def    __magic_name__       (		self :	Dict       ):






      '''simple docstring'''




      return OrderedDict(
          [
              ("pixel_values", {0: "batch", 1: "num_channels", 2: "height", 3: "width"}),
              ("pixel_mask", {0: "batch"}),
          ]       )

 @property
 def    __magic_name__       (		self :	List[Any]       ):






      '''simple docstring'''




      return 1E-5


 @property
 def    __magic_name__       (		self :	Union[str, Any]       ):






      '''simple docstring'''




      return 1_2









import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin


__UpperCAmelCase    				=     '\nHugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf originally as a company that developed a chatbot app targeted at teenagers.[2] After open-sourcing the model behind the chatbot, the company pivoted to focus on being a platform for machine learning.\n\nIn March 2021, Hugging Face raised $40 million in a Series B funding round.[3]\n\nOn April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model.[4] In 2022, the workshop concluded with the announcement of BLOOM, a multilingual large language model with 176 billion parameters.[5]\n'





class A__    ( unittest.TestCase  ,		A ):



 """simple docstring"""







 def    __magic_name__       (		self :	Tuple       ):






      '''simple docstring'''




      _lowerCAmelCase   :					Dict        =    load_tool("text-question-answering"       )
      self.tool.setup()
      _lowerCAmelCase   :					int        =    load_tool("text-question-answering"     ,						remote=A_       )

 def    __magic_name__       (		self :	List[str]       ):






      '''simple docstring'''




      _lowerCAmelCase   :					Dict        =    self.tool(A_     ,						"What did Hugging Face do in April 2021?"       )
      self.assertEqual(A_     ,						"launched the BigScience Research Workshop"       )

 def    __magic_name__       (		self :	Tuple       ):






      '''simple docstring'''




      _lowerCAmelCase   :					int        =    self.remote_tool(A_     ,						"What did Hugging Face do in April 2021?"       )
      self.assertEqual(A_     ,						"launched the BigScience Research Workshop"       )

 def    __magic_name__       (		self :	Dict       ):






      '''simple docstring'''




      _lowerCAmelCase   :					Union[str, Any]        =    self.tool(text=A_     ,						question="What did Hugging Face do in April 2021?"       )
      self.assertEqual(A_     ,						"launched the BigScience Research Workshop"       )


 def    __magic_name__       (		self :	Optional[Any]       ):






      '''simple docstring'''




      _lowerCAmelCase   :					Optional[int]        =    self.remote_tool(text=A_     ,						question="What did Hugging Face do in April 2021?"       )
      self.assertEqual(A_     ,						"launched the BigScience Research Workshop"       )






