


from collections import OrderedDict
from typing import Mapping

from packaging import version

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


a_ :Tuple  							=			logging.get_logger(__name__)

a_ :int  							=			{
    'hustvl/yolos-small': 'https://huggingface.co/hustvl/yolos-small/resolve/main/config.json',
    # See all YOLOS models at https://huggingface.co/models?filter=yolos
}

class 							lowercase  (						_UpperCAmelCase			):
     lowerCamelCase			:			List[Any]      = '''yolos'''







     def __init__(						self :						Union[str, Any]   ,   _lowercase :						List[Any]=7_68   ,   _lowercase :						Dict=12   ,   _lowercase :						Tuple=12   ,   _lowercase :						Tuple=30_72   ,   _lowercase :						Any="gelu"   ,   _lowercase :						Optional[int]=0.0   ,   _lowercase :						Tuple=0.0   ,   _lowercase :						str=0.02   ,   _lowercase :						Tuple=1E-12   ,   _lowercase :						str=[5_12, 8_64]   ,   _lowercase :						Tuple=16   ,   _lowercase :						Optional[Any]=3   ,   _lowercase :						List[str]=True   ,   _lowercase :						Optional[int]=1_00   ,   _lowercase :						Optional[int]=True   ,   _lowercase :						Union[str, Any]=False   ,   _lowercase :						Optional[int]=1   ,   _lowercase :						Any=5   ,   _lowercase :						Tuple=2   ,   _lowercase :						Optional[int]=5   ,   _lowercase :						List[str]=2   ,   _lowercase :						str=0.1   ,   **_lowercase :						List[str]   ,   ):
           super().__init__(**_lowercase      )

           SCREAMING_SNAKE_CASE__       :  Any						     =		hidden_size
           SCREAMING_SNAKE_CASE__       :  List[Any]						     =		num_hidden_layers
           SCREAMING_SNAKE_CASE__       :  List[str]						     =		num_attention_heads
           SCREAMING_SNAKE_CASE__       :  Optional[Any]						     =		intermediate_size
           SCREAMING_SNAKE_CASE__       :  List[str]						     =		hidden_act
           SCREAMING_SNAKE_CASE__       :  List[Any]						     =		hidden_dropout_prob
           SCREAMING_SNAKE_CASE__       :  int						     =		attention_probs_dropout_prob
           SCREAMING_SNAKE_CASE__       :  List[str]						     =		initializer_range
           SCREAMING_SNAKE_CASE__       :  List[str]						     =		layer_norm_eps
           SCREAMING_SNAKE_CASE__       :  Tuple						     =		image_size
           SCREAMING_SNAKE_CASE__       :  str						     =		patch_size
           SCREAMING_SNAKE_CASE__       :  str						     =		num_channels
           SCREAMING_SNAKE_CASE__       :  Dict						     =		qkv_bias
           SCREAMING_SNAKE_CASE__       :  Optional[Any]						     =		num_detection_tokens
           SCREAMING_SNAKE_CASE__       :  Tuple						     =		use_mid_position_embeddings
           SCREAMING_SNAKE_CASE__       :  Optional[int]						     =		auxiliary_loss
           # Hungarian matcher
           SCREAMING_SNAKE_CASE__       :  Optional[int]						     =		class_cost
           SCREAMING_SNAKE_CASE__       :  Optional[int]						     =		bbox_cost
           SCREAMING_SNAKE_CASE__       :  Union[str, Any]						     =		giou_cost
           # Loss coefficients
           SCREAMING_SNAKE_CASE__       :  str						     =		bbox_loss_coefficient
           SCREAMING_SNAKE_CASE__       :  Optional[Any]						     =		giou_loss_coefficient
           SCREAMING_SNAKE_CASE__       :  Dict						     =		eos_coefficient




class 							lowercase  (						_UpperCAmelCase			):
     lowerCamelCase			:			List[Any]      = version.parse('''1.11'''			)







     @property
     def 							lowercase__       (						self :						Union[str, Any]      ):
           return OrderedDict(
               [
                   ('''pixel_values''', {0: '''batch''', 1: '''num_channels''', 2: '''height''', 3: '''width'''}),
               ]      )







     @property
     def 							lowercase__       (						self :						Any      ):
           return 1E-4







     @property
     def 							lowercase__       (						self :						Tuple      ):
           return 12












'''simple docstring'''





import re

from flax.core.frozen_dict import freeze
from flax.traverse_util import flatten_dict, unflatten_dict
from jax.experimental import PartitionSpec as P


# Sentinels
UpperCamelCase_		:     Optional[int]          =		object()

# For specifying empty leaf dict `{}`
UpperCamelCase_		:     Optional[int]          =		object()





def       __a      (  _UpperCamelCase:       Union[str, Any]   ,		_UpperCamelCase:       Optional[Any]       )		->					Optional[Any]:

     """simple docstring"""




     _snake_case				= tuple((re.compile(x + "$"       ) for x in qs)       )
     for i in range(len(_UpperCamelCase       ) - len(_UpperCamelCase       ) + 1       ):
          _snake_case				= [x.match(_UpperCamelCase       ) for x, y in zip(_UpperCamelCase   ,		ks[i:]       )]
          if matches and all(_UpperCamelCase       ):
               return True
     return False





def       __a      (  _UpperCamelCase:       Optional[Any]       )		->					Union[str, Any]:

     """simple docstring"""




     def replace(_UpperCamelCase:       Tuple   ,		_UpperCamelCase:       List[str]       ):
          for rule, replacement in rules:
               if _match(_UpperCamelCase   ,		_UpperCamelCase       ):
                    return replacement
          return val

     return replace





def       __a      (  )		->					Any:

     """simple docstring"""




     return [
         # embeddings
         (("transformer", "wpe", "embedding"), P("mp"   ,		_UpperCamelCase       )),
         (("transformer", "wte", "embedding"), P("mp"   ,		_UpperCamelCase       )),
         # atention
         (("attention", "(q_proj|k_proj|v_proj)", "kernel"), P(_UpperCamelCase   ,		"mp"       )),
         (("attention", "out_proj", "kernel"), P("mp"   ,		_UpperCamelCase       )),
         (("attention", "out_proj", "bias"), None),
         # mlp
         (("mlp", "c_fc", "kernel"), P(_UpperCamelCase   ,		"mp"       )),
         (("mlp", "c_fc", "bias"), P("mp"       )),
         (("mlp", "c_proj", "kernel"), P("mp"   ,		_UpperCamelCase       )),
         (("mlp", "c_proj", "bias"), None),
         # layer norms
         ((r"ln_\d+", "bias"), None),
         ((r"\d+", r"ln_\d+", "scale"), None),
         (("ln_f", "bias"), None),
         (("ln_f", "scale"), None),
     ]





def       __a      (  _UpperCamelCase:       Union[str, Any]       )		->					Any:

     """simple docstring"""




     _snake_case				= _get_partition_rules()
     _snake_case				= _replacement_rules(_UpperCamelCase       )
     _snake_case				= {k: _unmatched for k in flatten_dict(_UpperCamelCase       )}
     _snake_case				= {k: replace(_UpperCamelCase   ,		_UpperCamelCase       ) for k, v in initd.items()}
     assert _unmatched not in result.values(), "Incomplete partition spec."
     return freeze(unflatten_dict(_UpperCamelCase       )       )


