


'''simple docstring'''
import copy
import os
from typing import Union

from ...configuration_utils import PretrainedConfig
from ...models.auto.modeling_auto import MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
from ...utils import logging
from ..auto import CONFIG_MAPPING


__snake_case							      =     logging.get_logger(__name__)

__snake_case							      =     {
    '''Salesforce/instruct-blip-flan-t5''': '''https://huggingface.co/Salesforce/instruct-blip-flan-t5/resolve/main/config.json''',
}
class    lowercase	(							A__					):

		"""simple docstring"""

		_a     =				'instructblip_vision_model'




		def __init__(		self    ,   UpperCamelCase_=1408    ,   UpperCamelCase_=6144    ,   UpperCamelCase_=39    ,   UpperCamelCase_=16    ,   UpperCamelCase_=224    ,   UpperCamelCase_=14    ,   UpperCamelCase_="gelu"    ,   UpperCamelCase_=1e-6    ,   UpperCamelCase_=0.0    ,   UpperCamelCase_=1e-10    ,   UpperCamelCase_=True    ,   **UpperCamelCase_    ,   ):

							'''simple docstring'''


							super().__init__(**UpperCamelCase_							)

							UpperCamelCase__   :Optional[Any]												= hidden_size
							UpperCamelCase__   :List[Any]												= intermediate_size
							UpperCamelCase__   :Optional[Any]												= num_hidden_layers
							UpperCamelCase__   :List[str]												= num_attention_heads
							UpperCamelCase__   :List[Any]												= patch_size
							UpperCamelCase__   :Tuple												= image_size
							UpperCamelCase__   :List[Any]												= initializer_range
							UpperCamelCase__   :int												= attention_dropout
							UpperCamelCase__   :Union[str, Any]												= layer_norm_eps
							UpperCamelCase__   :List[Any]												= hidden_act
							UpperCamelCase__   :str												= qkv_bias




		@classmethod
		def     lowerCAmelCase__				(		cls    ,   UpperCamelCase_    ,   **UpperCamelCase_							):

							'''simple docstring'''


							cls._set_token_in_kwargs(UpperCamelCase_							)

							UpperCamelCase__					,				UpperCamelCase__   :Tuple												= cls.get_config_dict(UpperCamelCase_    ,   **UpperCamelCase_							)

							# get the vision config dict if we are loading from InstructBlipConfig
							if config_dict.get('''model_type'''							) == "instructblip":
												UpperCamelCase__   :List[Any]												= config_dict['''vision_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    lowercase	(							A__					):

		"""simple docstring"""

		_a     =				'instructblip_qformer'




		def __init__(		self    ,   UpperCamelCase_=30522    ,   UpperCamelCase_=768    ,   UpperCamelCase_=12    ,   UpperCamelCase_=12    ,   UpperCamelCase_=3072    ,   UpperCamelCase_="gelu"    ,   UpperCamelCase_=0.1    ,   UpperCamelCase_=0.1    ,   UpperCamelCase_=512    ,   UpperCamelCase_=0.02    ,   UpperCamelCase_=1e-12    ,   UpperCamelCase_=0    ,   UpperCamelCase_="absolute"    ,   UpperCamelCase_=2    ,   UpperCamelCase_=1408    ,   **UpperCamelCase_    ,   ):

							'''simple docstring'''


							super().__init__(pad_token_id=UpperCamelCase_    ,   **UpperCamelCase_							)

							UpperCamelCase__   :List[Any]												= vocab_size
							UpperCamelCase__   :List[str]												= hidden_size
							UpperCamelCase__   :List[str]												= num_hidden_layers
							UpperCamelCase__   :Any												= num_attention_heads
							UpperCamelCase__   :List[str]												= hidden_act
							UpperCamelCase__   :List[str]												= intermediate_size
							UpperCamelCase__   :str												= hidden_dropout_prob
							UpperCamelCase__   :Union[str, Any]												= attention_probs_dropout_prob
							UpperCamelCase__   :List[str]												= max_position_embeddings
							UpperCamelCase__   :List[Any]												= initializer_range
							UpperCamelCase__   :List[str]												= layer_norm_eps
							UpperCamelCase__   :Dict												= position_embedding_type
							UpperCamelCase__   :int												= cross_attention_frequency
							UpperCamelCase__   :str												= encoder_hidden_size




		@classmethod
		def     lowerCAmelCase__				(		cls    ,   UpperCamelCase_    ,   **UpperCamelCase_							):

							'''simple docstring'''


							cls._set_token_in_kwargs(UpperCamelCase_							)

							UpperCamelCase__					,				UpperCamelCase__   :Dict												= cls.get_config_dict(UpperCamelCase_    ,   **UpperCamelCase_							)

							# get the qformer config dict if we are loading from InstructBlipConfig
							if config_dict.get('''model_type'''							) == "instructblip":
												UpperCamelCase__   :str												= config_dict['''qformer_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    lowercase	(							A__					):

		"""simple docstring"""

		_a     =				'instructblip'
		_a     =				True




		def __init__(		self    ,   UpperCamelCase_=None    ,   UpperCamelCase_=None    ,   UpperCamelCase_=None    ,   UpperCamelCase_=32    ,   **UpperCamelCase_							):

							'''simple docstring'''


							super().__init__(**UpperCamelCase_							)

							if vision_config is None:
												UpperCamelCase__   :int												= {}
												logger.info('''vision_config is None. initializing the InstructBlipVisionConfig with default values.'''							)

							if qformer_config is None:
												UpperCamelCase__   :Union[str, Any]												= {}
												logger.info('''qformer_config is None. Initializing the InstructBlipQFormerConfig with default values.'''							)

							if text_config is None:
												UpperCamelCase__   :str												= {}
												logger.info('''text_config is None. Initializing the text config with default values (`OPTConfig`).'''							)

							UpperCamelCase__   :Union[str, Any]												= InstructBlipVisionConfig(**UpperCamelCase_							)
							UpperCamelCase__   :str												= InstructBlipQFormerConfig(**UpperCamelCase_							)
							UpperCamelCase__   :List[str]												= text_config['''model_type'''] if '''model_type''' in text_config else '''opt'''
							UpperCamelCase__   :Union[str, Any]												= CONFIG_MAPPING[text_model_type](**UpperCamelCase_							)

							UpperCamelCase__   :Optional[int]												= self.text_config.tie_word_embeddings
							UpperCamelCase__   :int												= self.text_config.is_encoder_decoder

							UpperCamelCase__   :Union[str, Any]												= num_query_tokens
							UpperCamelCase__   :Optional[Any]												= self.vision_config.hidden_size
							UpperCamelCase__   :Any												= self.text_config.model_type in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
							UpperCamelCase__   :str												= 1.0
							UpperCamelCase__   :List[str]												= 0.02




		@classmethod
		def     lowerCAmelCase__				(		cls    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   **UpperCamelCase_    ,   ):

							'''simple docstring'''


							return cls(
							    vision_config=vision_config.to_dict()    ,   qformer_config=qformer_config.to_dict()    ,   text_config=text_config.to_dict()    ,   **UpperCamelCase_    ,   )




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :List[str]												= copy.deepcopy(self.__dict__							)
							UpperCamelCase__   :List[str]												= self.vision_config.to_dict()
							UpperCamelCase__   :Tuple												= self.qformer_config.to_dict()
							UpperCamelCase__   :List[Any]												= self.text_config.to_dict()
							UpperCamelCase__   :Dict												= self.__class__.model_type
							return output



'''simple docstring'''
from collections import defaultdict
class    lowercase	:

		"""simple docstring"""

		def __init__(		self    ,   UpperCamelCase_    ,   UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__   :List[Any]												= total  # total no of tasks (N)

							# DP table will have a dimension of (2^M)*N
							# initially all values are set to -1
							UpperCamelCase__   :Union[str, Any]												= [
							    [-1 for i in range(total + 1							)] for j in range(2 ** len(UpperCamelCase_							)							)
							]

							UpperCamelCase__   :str												= defaultdict(UpperCamelCase_							)  # stores the list of persons for each task

							# final_mask is used to check if all persons are included by setting all bits
							# to 1
							UpperCamelCase__   :Optional[int]												= (1 << len(UpperCamelCase_							)) - 1




		def     lowerCAmelCase__				(		self    ,   UpperCamelCase_    ,   UpperCamelCase_							):

							'''simple docstring'''


							if mask == self.final_mask:
												return 1

							# if not everyone gets the task and no more tasks are available, return 0
							if task_no > self.total_tasks:
												return 0

							# if case already considered
							if self.dp[mask][task_no] != -1:
												return self.dp[mask][task_no]

							# Number of ways when we don't this task in the arrangement
							UpperCamelCase__   :str												= self.count_ways_until(UpperCamelCase_    ,   task_no + 1							)

							# now assign the tasks one by one to all possible persons and recursively
							# assign for the remaining tasks.
							if task_no in self.task:
												for p in self.task[task_no]:
																	# if p is already given a task
																	if mask & (1 << p):
																						continue

																	# assign this task to p and change the mask value. And recursively
																	# assign tasks with the new mask value.
																	total_ways_util += self.count_ways_until(mask | (1 << p)    ,   task_no + 1							)

        # save the value.
							UpperCamelCase__   :Optional[int]												= total_ways_util

							return self.dp[mask][task_no]




		def     lowerCAmelCase__				(		self    ,   UpperCamelCase_							):

							'''simple docstring'''


							for i in range(len(UpperCamelCase_							)							):
												for j in task_performed[i]:
																	self.task[j].append(UpperCamelCase_							)

        # call the function to fill the DP table, final answer is stored in dp[0][1]
							return self.count_ways_until(0    ,   1							)


if __name__ == "__main__":
		__snake_case							      =     5  # total no of tasks (the value of N)

		# the list of tasks that can be done by M persons.
		__snake_case							      =     [[1, 3, 4], [1, 2, 5], [3, 4]]
		print(
		    AssignmentUsingBitmask(task_performed, total_tasks).count_no_of_ways(
		        task_performed
		    )
		)