





'''simple docstring'''




from typing import Optional

from torch import nn

from .transformer_ad import TransformeraDModel, TransformeraDModelOutput






class 				__snake_case     (					nn.Module							):





	def __init__(		self      ,       UpperCamelCase_ = 16      ,       UpperCamelCase_ = 88      ,       UpperCamelCase_ = None      ,       UpperCamelCase_ = 1      ,       UpperCamelCase_ = 0.0      ,       UpperCamelCase_ = 32      ,       UpperCamelCase_ = None      ,       UpperCamelCase_ = False      ,       UpperCamelCase_ = None      ,       UpperCamelCase_ = None      ,       UpperCamelCase_ = "geglu"      ,       UpperCamelCase_ = None      ,       )      ->		Tuple:
		super().__init__()
		snake_case__	       =   nn.ModuleList(
		    [
		        TransformeraDModel(
		            num_attention_heads=UpperCamelCase_      ,       attention_head_dim=UpperCamelCase_      ,       in_channels=UpperCamelCase_      ,       num_layers=UpperCamelCase_      ,       dropout=UpperCamelCase_      ,       norm_num_groups=UpperCamelCase_      ,       cross_attention_dim=UpperCamelCase_      ,       attention_bias=UpperCamelCase_      ,       sample_size=UpperCamelCase_      ,       num_vector_embeds=UpperCamelCase_      ,       activation_fn=UpperCamelCase_      ,       num_embeds_ada_norm=UpperCamelCase_      ,       )
		        for _ in range(2		)
		    ]		)

		# Variables that can be set by a pipeline:

		# The ratio of transformer1 to transformer2's output states to be combined during inference
		snake_case__	       =   0.5

		# The shape of `encoder_hidden_states` is expected to be
		# `(batch_size, condition_lengths[0]+condition_lengths[1], num_features)`
		snake_case__	       =   [77, 257]

		# Which transformer to use to encode which condition.
		# E.g. `(1, 0)` means that we'll use `transformers[1](conditions[0])` and `transformers[0](conditions[1])`
		snake_case__	       =   [1, 0]





	def   _snake_case   (		self      ,       UpperCamelCase_      ,       UpperCamelCase_      ,       UpperCamelCase_=None      ,       UpperCamelCase_=None      ,       UpperCamelCase_=None      ,       UpperCamelCase_ = True      ,       )      ->		int:
		snake_case__	       =   hidden_states

		snake_case__	       =   []
		snake_case__	       =   0
		# attention_mask is not used yet
		for i in range(2		):
			# for each of the two transformers, pass the corresponding condition tokens
			snake_case__	       =   encoder_hidden_states[:, tokens_start : tokens_start + self.condition_lengths[i]]
			snake_case__	       =   self.transformer_index_for_condition[i]
			snake_case__	       =   self.transformers[transformer_index](
			    UpperCamelCase_      ,       encoder_hidden_states=UpperCamelCase_      ,       timestep=UpperCamelCase_      ,       cross_attention_kwargs=UpperCamelCase_      ,       return_dict=UpperCamelCase_      ,       )[0]
			encoded_states.append(encoded_state - input_states		)
			tokens_start += self.condition_lengths[i]

		snake_case__	       =   encoded_states[0] * self.mix_ratio + encoded_states[1] * (1 - self.mix_ratio)
		snake_case__	       =   output_states + input_states

		if not return_dict:
			return (output_states,)

		return TransformeraDModelOutput(sample=UpperCamelCase_		)










'''simple docstring'''




from collections import Counter
from timeit import timeit




def 						__lowerCamelCase			(	UpperCAmelCase_ = ""					,				)   ->bool:
	return sum(c % 2 for c in Counter(input_str.replace(' '					,				''							).lower()							).values()							) < 2




def 						__lowerCamelCase			(	UpperCAmelCase_ = ""							)   ->bool:
	if len(UpperCAmelCase_							) == 0:
		return True
	snake_case__	       =   input_str.replace(' '					,				''							).lower()
	# character_freq_dict: Stores the frequency of every character in the input string
	snake_case__	       =   {}

	for character in lower_case_input_str:
		snake_case__	       =   character_freq_dict.get(UpperCAmelCase_					,				0							) + 1
	snake_case__	       =   0

	for character_count in character_freq_dict.values():
		if character_count % 2:
			odd_char += 1
	if odd_char > 1:
		return False
	return True




def 						__lowerCamelCase			(	UpperCAmelCase_ = ""							)   ->None:
	print('\nFor string = '					,				UpperCAmelCase_					,				':'							)
	print(
	    '> can_string_be_rearranged_as_palindrome_counter()'					,				'\tans ='					,				can_string_be_rearranged_as_palindrome_counter(UpperCAmelCase_							)					,				'\ttime ='					,				timeit(
	        'z.can_string_be_rearranged_as_palindrome_counter(z.check_str)'					,				setup='import __main__ as z'					,				)					,				'seconds'					,				)
	print(
	    '> can_string_be_rearranged_as_palindrome()'					,				'\tans ='					,				can_string_be_rearranged_as_palindrome(UpperCAmelCase_							)					,				'\ttime ='					,				timeit(
	        'z.can_string_be_rearranged_as_palindrome(z.check_str)'					,				setup='import __main__ as z'					,				)					,				'seconds'					,				)


if __name__ == "__main__":
			a__					:			str          =     input(
			    '''Enter string to determine if it can be rearranged as a palindrome or not: '''
			).strip()
			benchmark(check_str)
			a__					:			List[Any]          =     can_string_be_rearranged_as_palindrome_counter(check_str)
			print(f"""{check_str} can {'' if status else 'not '}be rearranged as a palindrome""")



