





import copy
import os
from typing import Union

from ...configuration_utils import PretrainedConfig
from ...utils import logging


__A     =    logging.get_logger(__name__)

__A     =    {
    "BridgeTower/bridgetower-base": "https://huggingface.co/BridgeTower/bridgetower-base/blob/main/config.json",
    "BridgeTower/bridgetower-base-itm-mlm": (
        "https://huggingface.co/BridgeTower/bridgetower-base-itm-mlm/blob/main/config.json"
    ),
}



class        _SCREAMING_SNAKE_CASE						(     __SCREAMING_SNAKE_CASE   ):







 '''simple docstring'''
 lowercase_		=      "bridgetower_vision_model"

 def __init__(self    :       int	,			UpperCAmelCase_    :       Union[str, Any]=768	,			UpperCAmelCase_    :       Union[str, Any]=12	,			UpperCAmelCase_    :       List[str]=3	,			UpperCAmelCase_    :       int=16	,			UpperCAmelCase_    :       str=288	,			UpperCAmelCase_    :       List[str]=1	,			UpperCAmelCase_    :       Any=1E-0_5	,			UpperCAmelCase_    :       Union[str, Any]=False	,			UpperCAmelCase_    :       Union[str, Any]=True	,			UpperCAmelCase_    :       Optional[Any]=False	,			**UpperCAmelCase_    :       int	,			)	->Optional[int]:



   '''simple docstring'''



   super().__init__(**UpperCAmelCase_)
   lowerCamelCase__:				Tuple        =hidden_size
   lowerCamelCase__:				str        =num_hidden_layers
   lowerCamelCase__:				List[Any]        =num_channels
   lowerCamelCase__:				Optional[int]        =patch_size
   lowerCamelCase__:				List[str]        =image_size
   lowerCamelCase__:				Dict        =initializer_factor
   lowerCamelCase__:				Tuple        =layer_norm_eps
   lowerCamelCase__:				Any        =stop_gradient
   lowerCamelCase__:				Any        =share_layernorm
   lowerCamelCase__:				Dict        =remove_last_layer







 @classmethod
 def 							SCREAMING_SNAKE_CASE_ (cls    :       Optional[Any]	,			UpperCAmelCase_    :       Union[str, os.PathLike]	,			**UpperCAmelCase_    :       Tuple)	->"PretrainedConfig":



   '''simple docstring'''



   lowerCamelCase__  , lowerCamelCase__:				List[Any]        =cls.get_config_dict(UpperCAmelCase_	,			**UpperCAmelCase_)

   if config_dict.get("model_type") == "bridgetower":
     lowerCamelCase__:				Tuple        =config_dict["text_config"]

   if "model_type" in config_dict and hasattr(cls	,			"model_type") and config_dict["model_type"] != cls.model_type:
     logger.warning(
         F"""You are using a model of type {config_dict["model_type"]} to instantiate a model of type """
         F"""{cls.model_type}. This is not supported for all configurations of models and can yield errors.""")

   return cls.from_dict(UpperCAmelCase_	,			**UpperCAmelCase_)



class        _SCREAMING_SNAKE_CASE						(     __SCREAMING_SNAKE_CASE   ):







 '''simple docstring'''
 lowercase_		=      "bridgetower_text_model"

 def __init__(self    :       List[Any]	,			UpperCAmelCase_    :       List[str]=50_265	,			UpperCAmelCase_    :       List[str]=768	,			UpperCAmelCase_    :       List[Any]=12	,			UpperCAmelCase_    :       int=12	,			UpperCAmelCase_    :       Any=1	,			UpperCAmelCase_    :       int=3_072	,			UpperCAmelCase_    :       int="gelu"	,			UpperCAmelCase_    :       Any=0.1	,			UpperCAmelCase_    :       int=0.1	,			UpperCAmelCase_    :       Optional[Any]=514	,			UpperCAmelCase_    :       int=1	,			UpperCAmelCase_    :       str=1E-0_5	,			UpperCAmelCase_    :       List[str]=1	,			UpperCAmelCase_    :       Dict=0	,			UpperCAmelCase_    :       Union[str, Any]=2	,			UpperCAmelCase_    :       Any="absolute"	,			UpperCAmelCase_    :       Any=True	,			**UpperCAmelCase_    :       Union[str, Any]	,			)	->List[str]:



   '''simple docstring'''



   super().__init__(**UpperCAmelCase_)

   lowerCamelCase__:				List[Any]        =vocab_size
   lowerCamelCase__:				Optional[Any]        =hidden_size
   lowerCamelCase__:				Optional[int]        =num_hidden_layers
   lowerCamelCase__:				Optional[int]        =num_attention_heads
   lowerCamelCase__:				List[str]        =hidden_act
   lowerCamelCase__:				Dict        =initializer_factor
   lowerCamelCase__:				Union[str, Any]        =intermediate_size
   lowerCamelCase__:				Any        =hidden_dropout_prob
   lowerCamelCase__:				Union[str, Any]        =attention_probs_dropout_prob
   lowerCamelCase__:				str        =max_position_embeddings
   lowerCamelCase__:				Union[str, Any]        =type_vocab_size
   lowerCamelCase__:				Optional[int]        =layer_norm_eps
   lowerCamelCase__:				int        =position_embedding_type
   lowerCamelCase__:				Union[str, Any]        =use_cache
   lowerCamelCase__:				Tuple        =pad_token_id
   lowerCamelCase__:				Union[str, Any]        =bos_token_id
   lowerCamelCase__:				List[Any]        =eos_token_id







 @classmethod
 def 							SCREAMING_SNAKE_CASE_ (cls    :       Tuple	,			UpperCAmelCase_    :       Union[str, os.PathLike]	,			**UpperCAmelCase_    :       Optional[int])	->"PretrainedConfig":



   '''simple docstring'''



   lowerCamelCase__  , lowerCamelCase__:				Optional[Any]        =cls.get_config_dict(UpperCAmelCase_	,			**UpperCAmelCase_)

   if config_dict.get("model_type") == "bridgetower":
     lowerCamelCase__:				Dict        =config_dict["text_config"]

   if "model_type" in config_dict and hasattr(cls	,			"model_type") and config_dict["model_type"] != cls.model_type:
     logger.warning(
         F"""You are using a model of type {config_dict["model_type"]} to instantiate a model of type """
         F"""{cls.model_type}. This is not supported for all configurations of models and can yield errors.""")

   return cls.from_dict(UpperCAmelCase_	,			**UpperCAmelCase_)



class        _SCREAMING_SNAKE_CASE						(     __SCREAMING_SNAKE_CASE   ):







 '''simple docstring'''
 lowercase_		=      "bridgetower"

 def __init__(self    :       str	,			UpperCAmelCase_    :       List[str]=True	,			UpperCAmelCase_    :       Union[str, Any]="gelu"	,			UpperCAmelCase_    :       str=768	,			UpperCAmelCase_    :       Any=1	,			UpperCAmelCase_    :       Optional[Any]=1E-0_5	,			UpperCAmelCase_    :       Any=False	,			UpperCAmelCase_    :       Optional[Any]="add"	,			UpperCAmelCase_    :       Optional[Any]=12	,			UpperCAmelCase_    :       Union[str, Any]=6	,			UpperCAmelCase_    :       Tuple=False	,			UpperCAmelCase_    :       Dict=False	,			UpperCAmelCase_    :       Any=None	,			UpperCAmelCase_    :       Optional[Any]=None	,			**UpperCAmelCase_    :       Any	,			)	->Optional[int]:



   '''simple docstring'''



   lowerCamelCase__:				List[str]        =kwargs.pop("text_config_dict"	,			UpperCAmelCase_)
   lowerCamelCase__:				Tuple        =kwargs.pop("vision_config_dict"	,			UpperCAmelCase_)

   super().__init__(**UpperCAmelCase_)
   lowerCamelCase__:				Optional[Any]        =share_cross_modal_transformer_layers
   lowerCamelCase__:				Any        =hidden_act
   lowerCamelCase__:				int        =hidden_size
   lowerCamelCase__:				Optional[Any]        =initializer_factor
   lowerCamelCase__:				Optional[int]        =layer_norm_eps
   lowerCamelCase__:				Any        =share_link_tower_layers
   lowerCamelCase__:				Optional[int]        =link_tower_type
   lowerCamelCase__:				Tuple        =num_attention_heads
   lowerCamelCase__:				int        =num_hidden_layers
   lowerCamelCase__:				Optional[int]        =tie_word_embeddings
   lowerCamelCase__:				Optional[Any]        =init_layernorm_from_vision_encoder

   if text_config is None:
     lowerCamelCase__:				Optional[int]        ={}
     logger.info("`text_config` is `None`. Initializing the `BridgeTowerTextConfig` with default values.")

   if vision_config is None:
     lowerCamelCase__:				List[Any]        ={}
     logger.info("`vision_config` is `None`. Initializing the `BridgeTowerVisionConfig` with default values.")

   lowerCamelCase__:				List[Any]        =BridgeTowerTextConfig(**UpperCAmelCase_)
   lowerCamelCase__:				List[Any]        =BridgeTowerVisionConfig(**UpperCAmelCase_)

 @classmethod
 def 							SCREAMING_SNAKE_CASE_ (cls    :       Optional[int]	,			UpperCAmelCase_    :       BridgeTowerTextConfig	,			UpperCAmelCase_    :       BridgeTowerVisionConfig	,			**UpperCAmelCase_    :       Optional[Any])	->Dict:



   '''simple docstring'''



   return cls(text_config=text_config.to_dict()	,			vision_config=vision_config.to_dict()	,			**UpperCAmelCase_)







 def 							SCREAMING_SNAKE_CASE_ (self    :       List[Any])	->int:



   '''simple docstring'''



   lowerCamelCase__:				str        =copy.deepcopy(self.__dict__)
   lowerCamelCase__:				Optional[int]        =self.text_config.to_dict()
   lowerCamelCase__:				int        =self.vision_config.to_dict()
   lowerCamelCase__:				Any        =self.__class__.model_type
   return output








from math import pow





def 					lowerCAmelCase_			(	__a     ,   __a     ,   __a     ,   __a     ,   __a     ,   )					->		tuple[int, int]:







  """simple docstring"""





  if current_sum == needed_sum:
    # If the sum of the powers is equal to needed_sum, then we have a solution.
    solutions_count += 1
    return current_sum, solutions_count

  lowerCamelCase__:				Optional[Any]        =int(pow(__a     ,   __a		)		)
  if current_sum + i_to_n <= needed_sum:
    # If the sum of the powers is less than needed_sum, then continue adding powers.
    current_sum += i_to_n
    lowerCamelCase__  , lowerCamelCase__:				int        =backtrack(
        __a     ,   __a     ,   current_number + 1     ,   __a     ,   __a		)
    current_sum -= i_to_n
  if i_to_n < needed_sum:
    # If the power of i is less than needed_sum, then try with the next power.
    lowerCamelCase__  , lowerCamelCase__:				Dict        =backtrack(
        __a     ,   __a     ,   current_number + 1     ,   __a     ,   __a		)
  return current_sum, solutions_count





def 					lowerCAmelCase_			(	__a     ,   __a		)					->		int:







  """simple docstring"""





  if not (1 <= needed_sum <= 1000 and 2 <= power <= 10):
    raise ValueError(
        "Invalid input\n"
        "needed_sum must be between 1 and 1000, power between 2 and 10."		)

  return backtrack(__a     ,   __a     ,   1     ,   0     ,   0		)[1]  # Return the solutions_count


if __name__ == "__main__":
     import doctest

     doctest.testmod()

