


import copy
import os
from typing import Union

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


lowercase_	   =     logging.get_logger(__name__)

lowercase_	   =     {
    '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 	A_ (	__UpperCamelCase   ):




      '''simple docstring'''


      __snake_case 	=       """bridgetower_vision_model"""




      def __init__(    self:	Union[str, Any]						,				a:	int=768						,				a:	List[Any]=12						,				a:	Tuple=3						,				a:	str=16						,				a:	Optional[Any]=288						,				a:	int=1						,				a:	List[str]=1e-05						,				a:	Dict=False						,				a:	Any=True						,				a:	Union[str, Any]=False						,				**a:	Any						,				):
       super().__init__(**a    )
       __lowerCamelCase		:							int		 =						hidden_size
       __lowerCamelCase		:							Dict		 =						num_hidden_layers
       __lowerCamelCase		:							Any		 =						num_channels
       __lowerCamelCase		:							Tuple		 =						patch_size
       __lowerCamelCase		:							Tuple		 =						image_size
       __lowerCamelCase		:							Tuple		 =						initializer_factor
       __lowerCamelCase		:							Optional[Any]		 =						layer_norm_eps
       __lowerCamelCase		:							Optional[Any]		 =						stop_gradient
       __lowerCamelCase		:							Dict		 =						share_layernorm
       __lowerCamelCase		:							List[str]		 =						remove_last_layer




      @classmethod
      def 					_snake_case     (    cls:	List[Any]						,				a:	Union[str, os.PathLike]						,				**a:	Dict    ):
       __lowerCamelCase ,					__lowerCamelCase		:							str		 =						cls.get_config_dict(a						,				**a    )

       if config_dict.get('model_type'    ) == "bridgetower":
        __lowerCamelCase		:							int		 =						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(a						,				**a    )



class 	A_ (	__UpperCamelCase   ):




      '''simple docstring'''


      __snake_case 	=       """bridgetower_text_model"""




      def __init__(    self:	Optional[Any]						,				a:	Tuple=5_0265						,				a:	Union[str, Any]=768						,				a:	Dict=12						,				a:	Any=12						,				a:	int=1						,				a:	Tuple=3072						,				a:	Any="gelu"						,				a:	str=0.1						,				a:	Tuple=0.1						,				a:	Dict=514						,				a:	List[str]=1						,				a:	str=1e-05						,				a:	List[str]=1						,				a:	int=0						,				a:	Dict=2						,				a:	Optional[int]="absolute"						,				a:	Tuple=True						,				**a:	Union[str, Any]						,				):
       super().__init__(**a    )

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




      @classmethod
      def 					_snake_case     (    cls:	str						,				a:	Union[str, os.PathLike]						,				**a:	Any    ):
       __lowerCamelCase ,					__lowerCamelCase		:							Any		 =						cls.get_config_dict(a						,				**a    )

       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(a						,				**a    )



class 	A_ (	__UpperCamelCase   ):




      '''simple docstring'''


      __snake_case 	=       """bridgetower"""




      def __init__(    self:	str						,				a:	Optional[int]=True						,				a:	str="gelu"						,				a:	Optional[int]=768						,				a:	List[Any]=1						,				a:	List[Any]=1e-05						,				a:	Dict=False						,				a:	Any="add"						,				a:	Any=12						,				a:	str=6						,				a:	List[Any]=False						,				a:	Any=False						,				a:	int=None						,				a:	int=None						,				**a:	Tuple						,				):
       # TODO: remove this once the Hub files are updated.
       __lowerCamelCase		:							Tuple		 =						kwargs.pop('text_config_dict'						,				a    )
       __lowerCamelCase		:							Union[str, Any]		 =						kwargs.pop('vision_config_dict'						,				a    )

       super().__init__(**a    )
       __lowerCamelCase		:							int		 =						share_cross_modal_transformer_layers
       __lowerCamelCase		:							Tuple		 =						hidden_act
       __lowerCamelCase		:							Tuple		 =						hidden_size
       __lowerCamelCase		:							Optional[Any]		 =						initializer_factor
       __lowerCamelCase		:							str		 =						layer_norm_eps
       __lowerCamelCase		:							List[Any]		 =						share_link_tower_layers
       __lowerCamelCase		:							Dict		 =						link_tower_type
       __lowerCamelCase		:							str		 =						num_attention_heads
       __lowerCamelCase		:							int		 =						num_hidden_layers
       __lowerCamelCase		:							Optional[Any]		 =						tie_word_embeddings
       __lowerCamelCase		:							Dict		 =						init_layernorm_from_vision_encoder

       if text_config is None:
        __lowerCamelCase		:							str		 =						{}
        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		:							Dict		 =						BridgeTowerTextConfig(**a    )
       __lowerCamelCase		:							Tuple		 =						BridgeTowerVisionConfig(**a    )




      @classmethod
      def 					_snake_case     (    cls:	Optional[Any]						,				a:	BridgeTowerTextConfig						,				a:	BridgeTowerVisionConfig						,				**a:	str    ):
       return cls(text_config=text_config.to_dict()						,				vision_config=vision_config.to_dict()						,				**a    )




      def 					_snake_case     (    self:	Union[str, Any]    ):
       __lowerCamelCase		:							Dict		 =						copy.deepcopy(self.__dict__    )
       __lowerCamelCase		:							str		 =						self.text_config.to_dict()
       __lowerCamelCase		:							Optional[Any]		 =						self.vision_config.to_dict()
       __lowerCamelCase		:							Tuple		 =						self.__class__.model_type
       return output





from math import pow
def 				UpperCamelCase__					(  SCREAMING_SNAKE_CASE__      ,	SCREAMING_SNAKE_CASE__      ,	SCREAMING_SNAKE_CASE__      ,	SCREAMING_SNAKE_CASE__      ,	SCREAMING_SNAKE_CASE__      ,	):
 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(SCREAMING_SNAKE_CASE__      ,	SCREAMING_SNAKE_CASE__						)						)
 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		:							Optional[Any]		 =						backtrack(
      SCREAMING_SNAKE_CASE__      ,	SCREAMING_SNAKE_CASE__      ,	current_number + 1      ,	SCREAMING_SNAKE_CASE__      ,	SCREAMING_SNAKE_CASE__						)
  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(
      SCREAMING_SNAKE_CASE__      ,	SCREAMING_SNAKE_CASE__      ,	current_number + 1      ,	SCREAMING_SNAKE_CASE__      ,	SCREAMING_SNAKE_CASE__						)
 return current_sum, solutions_count
def 				UpperCamelCase__					(  SCREAMING_SNAKE_CASE__      ,	SCREAMING_SNAKE_CASE__						):
 if not (1 <= needed_sum <= 1_000 and 2 <= power <= 10):
  raise ValueError(
      'Invalid input\n'
      'needed_sum must be between 1 and 1000, power between 2 and 10.'						)

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


if __name__ == "__main__":
       import doctest

       doctest.testmod()

